This repository contains the setup and inference scripts for the Colony Detection. It uses a trained model to detect colonies in images, generating visual annotations and statistical metadata.
setup.sh: Bash script to install all required dependencies.inference.py: Main Python script to run model predictions.best.pt: The trained YOLOv8 model weights (must be present in the root directory).test_images/: Default directory for placing input images.Results/: Output directory (auto-generated) where annotated images and prediction JSONs are saved.
Before running the inference script, you need to install the required Python packages (ultralytics for YOLO, and opencv-python).
Open your terminal, navigate to this directory, and run the setup script:
# Make the script executable (macOS/Linux)
chmod +x setup.sh
# Run the setup script
./setup.shThe inference.py script allows you to process either a full directory of images or a single image. It will output annotated images with bounding boxes and a predictions.json file containing all the statistical data (bounding box coordinates, confidence scores, etc.).
If you want to run the inference on sample images in ./test_images directory, simply run:
python3 inference.pyTo run batch inference on a specific folder of images:
python3 inference.py -i /path/to/your/custom_directory/To run inference on just one specific image:
python3 inference.py -i /path/to/image.jpgBy default, the script only considers detections with a confidence score of 0.25 or higher. You can adjust this using the -c or --conf flag. For example, to require a 50% confidence:
python3 inference.py -i /path/to/image.jpg -c 0.5After inference is complete, check the ./Results folder.
Results/images/: Contains copies of your images drawn with bounding boxes and confidence scores.Results/predictions/predictions.json: Contains detailed JSON output of every detection (class, confidence, and normalized/pixel bounding box coordinates).
| Class | Bacteria Species |
|---|---|
| class0 | Actinobacillus equuli |
| class1 | Actinobacillus pleuropneumoniae |
| class2 | Aeromonas hydrophila |
| class3 | Bacillus cereus |
| class4 | Bibersteinia trehalosi |
| class5 | Bordetella bronchiseptica |
| class6 | Brucella ovis |
| class7 | Clostridium perfringens |
| class8 | Corynebacterium pseudotuberculosis |
| class9 | Erysipelothrix rhusiopathiae |
| class10 | Escherichia coli |
| class11 | Glaesserella parasuis |
| class12 | Klebsiella pneumoniae |
| class13 | Listeria monocytogenes |
| class14 | Paenibacillus larvae |
| class15 | Pasteurella multocida |
| class16 | Proteus mirabilis |
| class17 | Pseudomonas aeruginosa |
| class18 | Rhodococcus equi |
| class19 | Salmonella enterica |
| class20 | Staphylococcus aureus |
| class21 | Staphylococcus hyicus |
| class22 | Streptococcus agalactiae |
| class23 | Trueperella pyogenes |