A PyTorch based CLI toolkit for image classification, augmentation, inference, and more. It lets you easily train and retrain models on custom datasets, evaluate model performance, and perform inference or classification on single images or folders.
ImageRec is a simple Python CLI toolkit for image classification, augmentation, inference, and more. One can quickly test models, experiment with datasets, and handle image data without writing any custom code. It contains these commands:
- Train and retrain models on custom datasets
- Run inference to predict image classes
- Classify images into their respective folders
- Evaluate model performance on validation data
- Plot training logs and visualize image augmentations
- Use various tools for dataset or model manipulation
Clone the repository :
git clone https://github.com/PoorYoungEagle/ImageRec-Toolkit.git
cd ImageRec-Toolkit
pip install -r requirements.txtBy default, PyTorch will install the CPU version. If you have an NVIDIA GPU and want faster training and inference, you should install the CUDA version of PyTorch instead:
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu121You can check other CUDA versions and installation options at the PyTorch Website
It requires the -m module syntax to run. Use the following command to see all available options and commands:
python -m imagerec --helpFor a full list of available options for each command, use the following example:
python -m imagerec train --helpCheck the examples/ directory for sample scripts and usage examples.
Train a new model on a custom dataset and save it.
python -m imagerec train \
--data-dir "examples/example_data" \
--output-dir "examples/outputs" \
--model-name "example_model" \
--epochs 5 \
--batch-size 16Retrain an existing model with same or new data.
python -m imagerec retrain \
--data-dir "examples/example_data" \
--model-path "examples/example_data/model.pt" \
--output-dir "examples/outputs" \
--model-name "example_model" \
--new-classes "Sphinx, Petra"
--epochs 5 \
--batch-size 16Infer on a single image or an entire folder of images to predict their classes.
python -m imagerec infer \
--model-path "examples/example_data/model.pt" \
--input-path "examples/example_data/Colosseum/colo.png"Classify a folder of images into their respective classes and organize them into folders based on the predicted labels.
python -m imagerec classify \
--model-path "examples/example_data/model.pt" \
--input-dir "examples/example_data/Colosseum" \
--output-dir "examples/outputs"Evaluate the model's accuracy and other metrics using the provided dataset and displays the results in the terminal.
python -m imagerec evaluate \
--data-dir "examples/example_data/test" \
--model-path "examples/example_data/model.pt"Plot training logs or visualize image augmentations to better understand model performance and data transformations.
python -m imagerec plot csv \
--csv-path "examples/example_data/example_log.csv"python -m imagerec plot augments \
--image-path "examples/example_data/Colosseum/colo.png" \
--num-samples 20ImageRec includes a set of utility commands to manipulate datasets and models.
Split a dataset into training and validation sets.
python -m imagerec tools split \
--input-dir "examples/example_data/classes" \
--output-dir "examples/outputs" \
--split 0.25Limit the number of images per class in the dataset.
python -m imagerec tools limit \
--input-dir "examples/example_data/class" \
--output-dir "examples/outputs" \
--max-images 50Compress a trained model to reduce its size.
python -m imagerec tools compress \
--model-path "examples/example_data/model.pt" \
--output-path "examples/outputs"Export a trained model into different formats (ONNX and TorchScript).
python -m imagerec tools export \
--format "onnx" or "torchscript" \
--model-path "examples/example_data/model.pt" \
--output-path "examples/outputs"Find suitable learning rate on a dataset.
python -m imagerec tools find-lr \
--data-dir "examples/example_data/classes" \
--architecture "resnet34"ImageRec includes tests to make sure that all commands work correctly. You can run the tests using pytest.
pip install pytest
pytest tests/Running them is optional but recommended if you make changes or want to verify your setup.
Takes around 5 minutes with CUDA.
- Image datasets used for examples: https://www.pexels.com
- Learning rate methodology: 'Cyclical Learning Rates for Training Neural Networks'
Any feedback is welcome!








