This project implements a modular pipeline for classifying tree species from images using transfer learning with MobileNet architectures (V2, V3Large, V3Small) in TensorFlow/Keras.
├── classify.py # Main script to run the pipeline
├── requirements.txt # Python dependencies
├── src/
│ ├── config.py # Configuration (hyperparameters, paths, etc.)
│ ├── data_processor.py # Data loading and preprocessing
│ ├── mobilenet_transfer_learning.py # Model building, training, fine-tuning
│ ├── model_evaluator.py # Evaluation and metrics
│ └── tflite_converter.py # TFLite conversion utilities
└── data/
├── train/ # Training images (one subfolder per class)
├── val/ # Validation images
└── test/ # Test images
-
Configuration
- All settings (image size, batch size, learning rates, epochs, etc.) are defined in
src/config.py
.
- All settings (image size, batch size, learning rates, epochs, etc.) are defined in
-
Data Processing
DataProcessor
(indata_processor.py
) loads images from thedata/
directory usingtf.keras.utils.image_dataset_from_directory
.- Datasets are normalized, batched, and prefetched for efficient training.
-
Model Building & Training
MobileNetTransferLearning
(inmobilenet_transfer_learning.py
) builds a model using a pre-trained MobileNet backbone (V2, V3Large, or V3Small).- The base model is frozen and new classification layers are added.
- The model is compiled and trained on the training set (feature extraction phase).
- Callbacks (early stopping, learning rate reduction, model checkpointing) are used for robust training.
-
Fine-Tuning
- After initial training, the base model is partially unfrozen (typically the last half of layers) and the model is re-trained with a lower learning rate.
- This allows the model to adapt more specifically to the tree species dataset.
-
Evaluation
ModelEvaluator
(inmodel_evaluator.py
) provides tools for evaluating model performance on validation and test sets, including accuracy, confusion matrix, and classification reports.
-
TFLite Conversion
TFLiteConverter
(intflite_converter.py
) enables conversion of trained models to TensorFlow Lite format for deployment on mobile or edge devices.
-
Main Pipeline
classify.py
orchestrates the entire workflow: loading config, preparing data, training and fine-tuning the model, evaluating results, and exporting the model.
- Transfer learning leverages a MobileNet model pre-trained on ImageNet. The base model's weights are reused, and only the new classification layers are trained initially.
- Feature extraction phase: The base model is frozen, and only the new layers learn to classify tree species.
- Fine-tuning phase: Some layers of the base model are unfrozen, allowing the model to adapt more closely to the new dataset.
- This approach enables high accuracy even with limited data and reduces training time.
- Install dependencies:
python3.10 -m venv venv source venv/bin/activate pip install -r requirements.txt
- Prepare your data:
- Place images in
data/train/
,data/val/
, anddata/test/
with one subfolder per class/species.
- Place images in
- Run the pipeline:
python classify.py
- The script will train, fine-tune, evaluate, and (optionally) export the model.
- Adjust hyperparameters and paths in
src/config.py
. - Switch between MobileNet variants by changing the model name in the config or main script.
- Use a Python 3.10 virtual environment for compatibility with TensorFlow.
- Keep
requirements.txt
updated for reproducibility. - Modular code structure makes it easy to extend or swap components.
For questions or improvements, please open an issue or pull request.