NOTE : SOIL-CLASSIFICATION-MODEL.IPYNB CONTAINS THE CODE FOR BOTH TRAINING AND INFERENCE
A high-performance deep learning model for classifying soil types from images with 95%+ F1 score.
VIDEO-2025-05-25-12-12-47.mov
This project uses computer vision to classify soil samples into four categories:
- Alluvial soil
- Black Soil
- Clay soil
- Red soil
Perfect for agricultural tech, environmental monitoring, and soil science applications!
The dataset contains:
- Training images of soil samples
- Test images for prediction
- Labels CSV with image IDs and soil types
# Clone this repository
git clone https://github.com/punkkkkkkk/soil-classification-model_annam.git
# Install dependencies
pip install torch torchvision albumentations pandas scikit-learn pillow tqdm ranger-adabelief
- Base Model: ResNet50 pretrained on ImageNet
- Custom Head: Added dropout layers and an intermediate layer for better feature learning
- Training Strategy: Freeze early layers, train later layers for soil-specific features
Our approach uses:
- 5-fold Cross-Validation: Ensures robust performance across different data splits
- Data Augmentation: Flips, rotations, brightness adjustments to prevent overfitting
- Advanced Optimizer: RangerAdaBelief for faster convergence
- Cyclic Learning Rate: Helps escape local minima and find better solutions
- Early Stopping: Saves the best model based on minimum F1 score across classes
For maximum accuracy:
- Model Ensemble: Combines all 5 fold models for prediction
- Test-Time Augmentation: Uses multiple views of each image for robust predictions
- Temperature Scaling: Calibrates confidence scores
The model achieves:
- 95%+ F1 Score on the validation set
- High Accuracy across all soil types
- Robust Generalization to unseen images
- Cell 1: Libraries and dependencies
- Cell 2: Data loading and fold preparation
- Cell 3: Model, optimizer, scheduler, and loss function setup
- Cell 4: Transforms, dataset class, and dataloaders
- Cell 5: Training and validation functions
- Cell 6: Full training loop with cross-validation
- Cell 7: Ensemble inference with TTA and performance evaluation
- Cross-validation strategy for robust results
- Advanced augmentation techniques
- Optimizer tuning for better convergence
- Ensemble prediction with test-time augmentation
- Detailed performance metrics for each soil class
Soil Type | F1 Score |
---|---|
Alluvial soil | 0.97 |
Black Soil | 0.95 |
Clay soil | 0.96 |
Red soil | 0.97 |
Overall | 0.96 |
- Python 3.7+ installed
- CUDA-compatible GPU recommended (for faster training)
- Access to the soil classification dataset
-
Clone the repository:
git clone https://github.com/punkkkkkkk/soil-classification-model_annam.git cd soil-classification
-
Install dependencies:
pip install -r requirements.txt
-
Prepare your environment:
- For Jupyter:
jupyter notebook
- For Python script: Make sure your working directory contains the code files
- For Jupyter:
Ensure your dataset is organized as follows:
/dataset
/train # Training images
/test # Test images
train_labels.csv # CSV with image_id and soil_type columns
- Open
soil-classification-model_annam.ipynb
in Jupyter - Execute cells sequentially
- Modify parameters in cell 6 to adjust training (epochs, batch size, etc.)
- The final cell will generate
submission.csv
with predictions
- Trained models saved to
/models
directory as.pth
files - Training metrics printed to console
- F1 scores for each soil class displayed after training
- Final predictions saved to
submission.csv
- Memory errors: Reduce batch size in cell 4 and cell 6
- CUDA errors: Try
torch.cuda.empty_cache()
or restart kernel - Import errors: Ensure all dependencies are installed correctly
- Dataset errors: Verify your image paths and CSV structure match the expected format