ai detect
1.1K
This project provides a Docker-based pipeline for training a YOLO model using labeled image datasets and deploying an API for inference.
š GitHub Repository: truongginjs/atri-apiā
This pipeline automates:
š GitHub Repository: truongginjs/atri-apiā
Ensure you have the following installed:
Create an input/images/ folder with the following structure:
input/images/
āāā image1.jpg
āāā image1.txt
āāā image2.jpg
āāā image2.txt
āāā ...
Labels follow the YOLO format:
<label_id> <x_center> <y_center> <width> <height>
Where:
label_id: Integer class identifierx_center, y_center: Center coordinates (normalized 0-1)width, height: Bounding box dimensions (normalized 0-1)Example:
0 0.656228 0.789873 0.163667 0.154430
1 0.440047 0.443038 0.610033 0.481013
Define class labels in input/labels.yml:
labels:
0: weight
1: barcode
ā
Ensure image and label files share the same name (e.g., image1.jpg ā image1.txt).
ā
Check that label values are normalized between 0 and 1.
ā
Each label file must contain at least one bounding box.
ā
Class IDs must match defined labels.
# full-pipeline.sh
#! /bin/bash
set -e
CURRENT_DIR=$(pwd)
TRAIN_IMAGE_NAME=truongginjs/atri-train
TRAIN_IMAGE_TAG=2.0-win
API_IMAGE_NAME=truongginjs/atri-api
API_IMAGE_TAG=2.0-win
# Add GPU flag parsing
USE_GPU=false
while getopts "g" opt; do
case $opt in
g) USE_GPU=true ;;
*) echo "Usage: $0 [-g] (use -g for GPU support)" && exit 1 ;;
esac
done
# Fix if statement syntax
if [ -d "${CURRENT_DIR}/output/yolo_train/train" ]; then
echo "folder train found, remove that folder..."
rm -rf ${CURRENT_DIR}/output/yolo_train/train
fi
echo "Starting training and exporting..."
# Define docker run command based on GPU flag
# -e IGNORE_AUG=TRUE \
# -e IGNORE_TRAIN=TRUE \
# -e IGNORE_EXPORT=TRUE \
if [ "$USE_GPU" = true ]; then
echo "Running with GPU support..."
docker run --rm -it --gpus all --shm-size=16g \
-v "${CURRENT_DIR}/input:/app/input" \
-v "${CURRENT_DIR}/output:/app/output:rw" \
-e EXPORT_PRE_TRAIN=/app/output/yolo_train/train/weights/best.pt \
-e NUM_OF_AUGMENT=100 \
-e EPOCHS=150 \
-e IMGSZ=640 \
${TRAIN_IMAGE_NAME}:${TRAIN_IMAGE_TAG}
else
echo "Running without GPU support..."
docker run --rm -it \
-v "${CURRENT_DIR}/input:/app/input" \
-v "${CURRENT_DIR}/output:/app/output:rw" \
-e EXPORT_PRE_TRAIN=/app/output/yolo_train/train/weights/best.pt \
-e NUM_OF_AUGMENT=100 \
-e EPOCHS=150 \
-e IMGSZ=640 \
${TRAIN_IMAGE_NAME}:${TRAIN_IMAGE_TAG}
fi
mv ${CURRENT_DIR}/output/yolo_train/train/weights/best.onnx ${CURRENT_DIR}/output/best.onnx
echo "start api..."
# Check if container exists and remove it
CONTAINER_NAME="atri-api"
if [ "$(docker ps -q -f name=${CONTAINER_NAME})" ]; then
echo "Stopping existing container..."
docker stop ${CONTAINER_NAME}
fi
if [ "$(docker ps -aq -f name=${CONTAINER_NAME})" ]; then
echo "Removing existing container..."
docker rm ${CONTAINER_NAME}
fi
# Start new container
docker run -d -p 80:3000 \
--name ${CONTAINER_NAME} \
-v "${CURRENT_DIR}/output:/usr/src/app/models/yolo" \
${API_IMAGE_NAME}:${API_IMAGE_TAG}
To run the pipeline with CPU:
./full-pipeline.sh
If you have a compatible NVIDIA GPU:
./full-pipeline.sh -g
This enables CUDA acceleration inside the container.
You can skip specific steps using environment variables:
./full-pipeline.sh -e IGNORE_AUG=TRUE
./full-pipeline.sh -e IGNORE_TRAIN=TRUE
./full-pipeline.sh -e IGNORE_AUG=TRUE -e IGNORE_TRAIN=TRUE
./full-pipeline.sh -g -e IGNORE_AUG=TRUE
Apple Silicon (M1/M2) does not support GPU acceleration for YOLO training inside Docker. Use:
./full-pipeline.arm64.sh
Modify these settings in the script:
| Variable | Description | Default |
|---|---|---|
NUM_OF_AUGMENT | Number of augmented images | 100 |
EPOCHS | Training epochs | 150 |
IMGSZ | Image size for training | 640 |
| Flag | Effect |
|---|---|
IGNORE_AUG=TRUE | Skip augmentation |
IGNORE_TRAIN=TRUE | Skip training |
IGNORE_EXPORT=TRUE | Skip model export |
Example:
docker run ... -e IGNORE_AUG=TRUE -e IGNORE_TRAIN=TRUE
80.The script automatically handles:
ā
Stopping and removing existing API containers.
ā
Starting a fresh container instance.
Manually stop the container:
docker stop atri-api
Check running containers:
docker ps
If you see:
requirements: Ultralytics requirement ['onnxruntime-gpu'] not found, attempting AutoUpdate...
Manually install:
pip install onnxruntime-gpu
Run:
nvidia-smi
If CUDA is missing, ensure NVIDIA drivers are installed.
Ensure that output/yolo_train/train/weights/best.pt exists before running the pipeline.
ā
Train the model with new datasets
ā
Deploy the API for real-time inference
ā
Optimize training parameters for better accuracy
Developed by: TruongGinJS š
Maintained by: TruongGinJS
š GitHub Repository: truongginjs/atri-apiā
Content type
Image
Digest
sha256:147094342ā¦
Size
1.2 GB
Last updated
over 1 year ago
docker pull truongginjs/atri-api