This repository provides a configurable image classification training pipeline using TensorFlow and Keras. It supports training from scratch or fine-tuning a pre-trained model, with customizable data augmentation, callbacks, and training parameters defined in a YAML configuration file.
---train.py— Main script to train the model.config.yaml— Centralized configuration file for training parameters.model/— Contains model architecture definitions.utils/— Utility functions, configuration loader, data augmentation previews, and custom callbacks.confusion_matrix.py— Script for model evaluation with custom F1-score metric and threshold optimization.
- Open a terminal or command prompt.
- Create a virtual environment using Anaconda:
conda create -n name_env python=3.9
- Activate the environment:
conda activate name_env
- Ensure
pipis installed:conda install pip
- Install project dependencies:
pip install -r requirements.txt
After setting up the environment and configuring config.yaml, run the training script:
python train.pyThe model will be trained on the dataset specified in the configuration file, and the best model will be saved according to the selected evaluation metric.
The confusion_matrix.py script evaluates a trained binary classification model using a test set. It calculates a custom F1-score and can determine the optimal classification threshold. Optionally, it saves test images into structured folders for easier inspection.
- Custom F1-score metric (TensorFlow/Keras-compatible)
- Automatic threshold optimization
- Two image-saving modes:
standard: saves images by true classfolder_split: saves images intoout/0andout/1based on predictions
- Compatible with models trained using
train.py
python confusion_matrix.py -m <path_to_model> [-s <threshold>] [--mode standard|folder_split]-m,--model: Path to the saved model (required)-s,--threshold: Classification threshold (default: 0.5)--mode: Output mode:standardorfolder_split
