Command-line Interface
AIgarMIC contains a collection of command-line scripts to help construct workflows without requiring custom python
scripts. Generally, these scripts are intended for users that are working with 96-position square agar plates. These
scripts provide the following high-level functionality:
Rename images can be used to rename a sequence of agar plate images with the correct antibiotic concentration in the filename, to prepare for analysis.
The main command line interface for
AIgarMICcan be used to make MIC predictions using pre-trained models: AIgarMIC – main command-line interface.Manual annotator can be used to generate a labelled dataset of bacterial colony image to train and test machine learning models.
In the creation of a labelled dataset, sometimes duplicate images end up in the annotation folders. Clean up annotations is useful to clean up duplicate images to avoid incorrect model training.
The annotated datasets can be used to train a binary or softmax model using Modular model training script. This creates a model that can be used as an input to AIgarMIC – main command-line interface.
Finally, Model performance is useful to test the model’s performance on an unseen dataset that is held for testing purposes.
Rename images
Script to batch rename images with halving value of drug concentration.
usage: rename_images [-h] directory starting_concentration
Positional Arguments
- directory
Directory containing images. Filenames should reflect the concentration order when sorted, e.g.:
image1 (no drug)
image2 (low concentration)
image3 (medium concentration)
image4 (high concentration)
etc..
- starting_concentration
Starting (max) concentration that will be iteratively halved
AIgarMIC – main command-line interface
Main script to interpret agar dilution MICs
usage: main [-h] [-m [MODEL ...]] [-t TYPE_MODEL] [-o OUTPUT_FILE]
[-v VALIDATION_THRESHOLD] [-c] [-n NEGATIVE_CODES]
[-s SOFTMAX_CLASSES] [-r RESOLUTION RESOLUTION]
[-d DIMENSIONS DIMENSIONS]
directory
Positional Arguments
- directory
Directory containing images to process, arranged in sub-folders by antibiotic name, e.g.,:
directory/
antibiotic1_name/
0.jpg
0.125.jpg
0.25.jpg
Named Arguments
- -m, --model
Specify one or more directories containing tensorflow model/s for image classification
- -t, --type_model
Type of keras model, e.g., binary, softmax [default] = binary
Default: “binary”
- -o, --output_file
Specify output file for csv report (will be overwritten)
- -v, --validation_threshold
Image annotation accuracies below this value will be validated for manual confirmation.0.0 checks no images [default]; 1.0 checks all images.
Default: 0.0
- -c, --check_contours
Check contours visually
Default: False
- -n, --negative_codes
Comma-separated list of no growth class codes for model, e.g., 0,1 (default=0)
- -s, --softmax_classes
Number of softmax classes for softmax classes that model predicts.Required if -t = softmax
- -r, --resolution
X and Y resolution of images for model training [default = 160 160]
Default: [160, 160]
- -d, --dimensions
Number of rows and columns in agar plate image grid [default = 8 12]
Default: [8, 12]
Manual annotator
Manually label random colony images from plates to generate annotated image database. Supports labels from 0 to 9.
usage: manual_annotator [-h] [-o OUTPUT_DIRECTORY] input_directory
Positional Arguments
- input_directory
Directory containing plate images
Named Arguments
- -o, --output_directory
Path to store annotation output files
Default: “annotations/”
Clean up annotations
Clean up duplicate images in annotation folders
usage: clean_up_annotations [-h] [-q] input_dir
Positional Arguments
- input_dir
Input directory - can contain subdirectories of images which will be processed separately
Named Arguments
- -q, --quiet
Suppress file deletion warnings (CAUTION)
Default: False
Modular model training script
This script loads images from annotations directory and trains ML to classify colony growth.
usage: train_modular [-h] [-v] [-s SAVE] [-l] [-t TEST_DATASET]
[-m {binary,softmax}] [-c {0,1}] [-b BATCH_SIZE]
[-d DIMENSIONS DIMENSIONS]
annotations
Positional Arguments
- annotations
Directory containing annotated images
Named Arguments
- -v, --visualise
Generate visualisations for model diagnostics
Default: False
- -s, --save
If specified, tensorflow model will be saved to this folder
- -l, --log
Store performance log in output folder
Default: False
- -t, --test_dataset
Testing dataset for final model evaluation. Ideally unseen data.If not provided then input directory is used (whole dataset).
- -m, --model_type
Possible choices: binary, softmax
Model type to train [default] = binary
Default: “binary”
- -c, --complexity
Possible choices: 0, 1
Model complexity level [default] = 0. Supports 0 or 1. 0 = first-step model from Gerada et al Spectrum 2024;1 = second-step model from Gerada et al Spectrum 2024.
Default: 0
- -b, --batch_size
Batch size for training [default] = 64
Default: 64
- -d, --dimensions
X and Y dimensions of images for model training [default = 160 160]
Default: [160, 160]
Model performance
Evaluate saved model performance
usage: model_performance [-h] [-x TRAINED_X] [-y TRAINED_Y] [-t THRESHOLD]
model_path annotations_path
Positional Arguments
- model_path
Path to the model
- annotations_path
Path to the annotations to test
Named Arguments
- -x, --trained_x
Width of the images that the model was trained on [default=160]
Default: 160
- -y, --trained_y
Height of the images that the model was trained on [default=160]
Default: 160
- -t, --threshold
Accuracy threshold, to highlight low accuracy predictions [default=0.95]
Default: 0.95