Console/terminal pipeline for training and running a YOLO26 instance-segmentation model (PyTorch), supporting Windows 11 and Ubuntu Linux 24.04. Instance segmentation does not just locate each object but outlines its exact shape, so two objects of the same class stay separate. The workflow covers the whole cycle: annotate in the bundled web tool, convert the labels to YOLO format, train, and then run inference on a single image, a folder or a live webcam. Two example datasets ship with the project: CT (liver) and nucleus (cell nuclei). The ultralytics source is bundled under src/ultralytics/ and imported directly, so no PyPI install is needed.

 

[Folder Structure]

  • CLAUDE.md / AGENT.md: program specification (identical content).
  • CHANGELOG.md: change log.
  • copyright.txt: copyright notice.
  • data/{dataset}/: the datasets, holding train/ and val/ (each with images, labels and annotations), test/images, label.names and voc.yaml.
  • model/{dataset}/: the starting weights (yolo26x-seg.pt) and the training output (best.pt, last.pt and the run artifacts).
  • tool/tools.py: shared helpers (delete_ipynb_checkpoints, project_root, resolve_device).
  • src/annotation/: the bundled aiohttp annotation web server (main.py, routes.py, views.py, API.py, config/ and the image-annotation/ browser UI). It is launched by src/annotation.py and runs cross-platform with the venv Python.
  • src/: the source code and the launcher scripts.
  • src/requirements.txt: the Python dependencies installed by step 1.
  • src/ultralytics/: the bundled ultralytics source, imported directly.
  • venv/: the virtual environment created by step 1 and removed by 99_venv_clear.

[Prerequisites]

  • Operating system: Windows 11 (the .bat launchers) or Ubuntu Linux 24.04 (the .sh launchers).
  • Python 3.10 or newer on PATH.
  • Optional: an NVIDIA GPU with a matching CUDA build of PyTorch.
  • Annotation (step 3) uses the bundled web server, which runs on both Windows and Linux with the venv Python; no external binary is needed.
  • Webcam inference (step 8) needs a display and a camera.

[Instructions]

Step 1: create the virtual environment

Recreate the venv and install src/requirements.txt.

 

Windows 11: src\01_venv_create.bat

Ubuntu 24.04: bash src/01_venv_create.sh

 

Step 2: activate the virtual environment (optional)

Activate the venv in the current shell so you can run python directly. On Linux you must source it. Scripts 3 to 8 activate the venv themselves, so this step is optional.

 

Windows 11: src\02_venv_activate.bat

Ubuntu 24.04: source src/02_venv_activate.sh

 

Step 3: annotate your images (only for your own data)

Start the LabelMe JSON annotation server and draw the object outlines in the browser. The default port is 8817.

 

Windows 11: src\03_annotation.bat

Ubuntu 24.04: bash src/03_annotation.sh

 

Step 4: convert the labels to YOLO format

Convert the LabelMe JSON files into YOLO segmentation labels and write voc.yaml.

 

Windows 11: src\04_convert_yolo_format.bat --dataset CT

Ubuntu 24.04: bash src/04_convert_yolo_format.sh --dataset CT

 

Step 5: train the model

Train the segmentation model. If voc.yaml is missing, the converter runs automatically first. Use --device 0 to train on the first GPU.

 

Windows 11: src\05_train.bat --dataset CT --epochs 300 --device 0

Ubuntu 24.04: bash src/05_train.sh --dataset CT --epochs 300 --device 0

 

Step 6: run inference on a single image

Segment one image. --show opens a window, --save writes the result to disk.

 

Windows 11: src\06_inference.bat --dataset CT --source data\CT\test\images\liver-1.png --show

Ubuntu 24.04: bash src/06_inference.sh --dataset CT --source data/CT/test/images/liver-1.png --save

 

Step 7: run inference on a folder

Segment every image in a folder in one go.

 

Windows 11: src\07_inference_folder.bat --dataset CT --source data\CT\test\images --save

Ubuntu 24.04: bash src/07_inference_folder.sh --dataset CT --source data/CT/test/images --save

 

Step 8: run inference on a webcam (optional)

Segment a live webcam stream. A display and a camera are required.

 

Windows 11: src\08_inference_webcam.bat

Ubuntu 24.04: bash src/08_inference_webcam.sh

 

Step 9: clear the virtual environment (optional)

Delete the venv/ folder to free disk space when you no longer need it.

 

Windows 11: src\99_venv_clear.bat

Ubuntu 24.04: bash src/99_venv_clear.sh

 

[Python Entry Points]

  • src/annotation.py: launches the bundled annotation web server. Arguments: --dataset --port --split, with --port 8817 by default.
  • src/convert_yolo_format.py: converts LabelMe JSON to YOLO segmentation labels and writes voc.yaml. Arguments: --dataset.
  • src/train.py: trains YOLO26 segmentation. Arguments: --dataset --batch-size --image-size --epochs --workers --device --weights.
  • src/inference.py: single-image or folder inference. Arguments: --dataset --source --image-size --device --threshold --weights --show --save.
  • src/inference_webcam.py: webcam inference. Arguments: --dataset --webcam-id --image-size --device --threshold --weights --save.

[Dataset Format]

  • label.names: one class name per line. It drives the class ids and voc.yaml. The CT dataset has the single class liver, and nucleus has the single class nucleus.
  • Images go into train/images/ and val/images/, with the LabelMe JSON files in the matching annotations/ folders.
  • The converter writes YOLO segmentation txt files into train/labels/ and val/labels/, one line per object in the form: class_id x1 y1 x2 y2 ... xn yn, where the polygon coordinates are normalized to the range 0 to 1.
  • test/images/ holds the unlabeled images used for inference.

[References]

 

This SDK is built in AppForAI - AI Dev Tools.

 

Purchase license separately:  USD 600, permanent authorization, single APP authorization, single machine authorization, one-year activation, one-year download, one-year update, one-year email technical support.