This project is set up to train a YOLO11 model for object detection.
-
Create and activate a virtual environment:
python3 -m venv .venv source .venv/bin/activate -
Install dependencies:
pip install -r requirements.txt
-
Add your data:
- Place your training images in
data/images/train - Place your validation images in
data/images/val - Place your training labels in
data/labels/train - Place your validation labels in
data/labels/val
The label files should be in YOLO format (txt files with one line per bounding box:
class_id center_x center_y width height). - Place your training images in
-
Update
data/dataset.yaml:- Change the
nameslist to match the classes in your dataset.
- Change the
To start training the model, make sure your virtual environment is activated and run the following command:
python train.pyThe training results, including saved model weights, will be stored in the runs/ directory.
You can also run this project using Docker.
-
Build the Docker image:
docker build -t cartes-yolo . -
Run the Docker container:
To train the model inside the container, you need to mount your local
data/andruns/directories so that the container can access your dataset and save the training results.docker run -it --rm \ -v "$(pwd)/data:/app/data" \ -v "$(pwd)/runs:/app/runs" \ cartes-yolo \ --data data/dataset.yaml --epochs 100 --imgsz 640 --project runs/train --name train
You can customize the arguments passed to
train.py(e.g.,--epochs,--imgsz,--name) as needed.To direct the training results to a local
tmpfolder instead ofruns, you can use the following command. This command mounts your localdatadirectory to/datainside the container and your localtmpdirectory to/app/runsinside the container, which is where the training script will write its output.docker run -it --rm \ -v "$(pwd)/data:/data" \ -v "$(pwd)/tmp:/app/runs" \ cartes-yolo \ --epochs=1 --data=/data/dataset.yaml