Skip to content

creation of object detection datasets, training of object-detection-models and inference in production

License

Notifications You must be signed in to change notification settings

SDFIdk/ML_object_detection

Repository files navigation

ML_object_detection

Maintained by the Danish Climate Data Agency for Bounding Box Detection on Oblique Images.

image

Installation

  • clone repo

    git clone https://github.com/SDFIdk/ML_object_detection
  • create conda environment

    cd ML_object_detection
    mamba env create -f environment.yml
    mamba activate  ML_object_detection

Example use

  • Use the included model for inference on one small and one large image from the included set of example images
    python src/ML_object_detection/infer_with_sahi.py --weights models/example_model.pt --folder_with_images data/example_images/ --result_folder output

Create dataset for training

  • split the images to sizes suitable for yolo

    python split_with_gdal.py --image /path/to/large/images --output dataset/folder --x 640 --y 640 --overlap 40
  • Create a dataset with labelme

    Open folder containing the splitted images

    For each image you want to train on, draw rectangles from the upper left corner to the lower right corner.

    OBS. All objects of the categoriez you want to detect needs to be marked up. Partly labeled images will ruin the training.

  • (optional) set all "unkown"/"ignore" areas to black

    If you labeled areas with the text "ignore" (e.g areas for wich you are unsure about the correct classification) we have the option to mask all these areas and make them black. Calling mask_unknown_regions.py with -h flag will give more instructions on usage

    python  mask_unknown_regions.py -h
  • make sure that all .json files use the same format (original .tif image)

python standardize_json.py --json_dir /mnt/T/mnt/trainingdata/object_detection/from_Fdrev_ampol/all/
  • convert the labelme dataset to yolo format with

    labelme2yolo --json_dir /path/to/labelme_json_dir/ --val_size 0.15 --test_size 0.15
    e.g labelme2yolo --json_dir /mnt/T/mnt/trainingdata/object_detection/from_Fdrev_ampol/split/
  • Train a object detection model on the dataset

    python train.py --data /path/to/labelme_json_dir/config.yml
    e.g  python src/ML_object_detection/train.py --data /mnt/T/mnt/trainingdata/object_detection/object_detection_dataset/2025-06-16/labelme_images/YOLODataset/dataset.yaml
  • Use the model for inference on large (unsplitted images) (e.g for creating sugestions for new labels)

    python src/ML_object_detection/infer_with_sahi.py --weights models/example_model.pt --folder_with_images data/example_images/ --result_folder output
    

About

creation of object detection datasets, training of object-detection-models and inference in production

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages