All stages run through a single unified CLI on a standard PC: python -m agrisort <command>.
Downloads images for all 15 classes using the search queries in configs/classes.yaml:
python -m agrisort collect --out data/raw --engine bing --min-side 120
Target specific classes or switch to Google:
python -m agrisort collect --engine google --classes durian_ripe disease_anthracnose
Removes corrupt files and images smaller than 80px, converts all valid images to 3-channel RGB JPEG, and removes perceptual-hash duplicates:
python -m agrisort clean --raw-dir data/raw --min-side 80
Splits each class before augmentation (80/20 by default) to prevent data leakage, estimates bounding boxes using Otsu thresholding, resizes to 192x192, and applies 4x augmentation:
python -m agrisort label --raw-dir data/raw --out-dir data/processed --train-ratio 0.8
Note: Otsu contour auto-labeling works best on clean single-object backgrounds. For cluttered conveyor environments, refine labels with LabelImg or Roboflow before training.
Generate class distribution plots and sample grids:
python -m agrisort visualize --dataset data/processed --out-dir outputs/visualizations
Uses defaults from configs/train.yaml (--device auto uses GPU if available, otherwise CPU):
python -m agrisort train --data data/processed/dataset.yaml --epochs 80 --device auto
Quick smoke test on the included sample dataset:
python -m agrisort train --data data/sample_yolo/dataset.yaml --epochs 5 --device auto
Exports PyTorch .pt (or --saved-model) to full-integer INT8 .tflite and regenerates firmware/include/model_data.h:
python -m agrisort export \
--weights runs/yolov8n_agri_192/weights/best.pt \
--data data/processed/dataset.yaml \
--out-tflite models/yolov8n_agri_192_int8.tflite \
--out-header firmware/include/model_data.h
Regenerate model_data.h alone from an existing .tflite file:
python -m agrisort header \
--tflite models/yolov8n_agri_192_int8.tflite \
--out firmware/include/model_data.h
cd firmware
pio run --target upload
pio device monitor