Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ResNet-50 Fine-Tuned Model for Vehicle Type Classification
|
| 2 |
+
|
| 3 |
+
This repository hosts a **fine-tuned ResNet-50 model** for **Vehicle Type Classification**, trained on a subset of the **MIO-TCD Traffic Dataset**. This model is designed for **traffic management applications**, enabling real-time and accurate recognition of different vehicle types, such as cars, trucks, buses, and motorcycles.
|
| 4 |
+
|
| 5 |
+
## Model Details
|
| 6 |
+
|
| 7 |
+
- **Model Architecture:** ResNet-50
|
| 8 |
+
- **Task:** Vehicle Type Classification
|
| 9 |
+
- **Dataset:** MIO-TCD (Subset from Kaggle: `miotcd-dataset-50000-imagesclassification`)
|
| 10 |
+
- **Number of Classes:** 11 vehicle categories
|
| 11 |
+
- **Fine-tuning Framework:** PyTorch (`torchvision.models.resnet50`)
|
| 12 |
+
- **Optimization:** Trained with Adam optimizer and data augmentation for robust performance
|
| 13 |
+
|
| 14 |
+
## Downloading the Model
|
| 15 |
+
|
| 16 |
+
You can download the fine-tuned model from the provided link:
|
| 17 |
+
|
| 18 |
+
```sh
|
| 19 |
+
wget <download_link>/fine_tuned_model.zip
|
| 20 |
+
unzip fine_tuned_model.zip
|
| 21 |
+
```
|
| 22 |
+
|
| 23 |
+
## Usage
|
| 24 |
+
|
| 25 |
+
### Installation
|
| 26 |
+
|
| 27 |
+
Ensure you have the required dependencies installed:
|
| 28 |
+
|
| 29 |
+
```sh
|
| 30 |
+
pip install torch torchvision pillow
|
| 31 |
+
```
|
| 32 |
+
|
| 33 |
+
### Loading the Model
|
| 34 |
+
|
| 35 |
+
```python
|
| 36 |
+
import torch
|
| 37 |
+
import torchvision.models as models
|
| 38 |
+
import torchvision.transforms as transforms
|
| 39 |
+
from PIL import Image
|
| 40 |
+
|
| 41 |
+
# Load the model architecture
|
| 42 |
+
model = models.resnet50(pretrained=False)
|
| 43 |
+
num_ftrs = model.fc.in_features
|
| 44 |
+
model.fc = torch.nn.Linear(num_ftrs, 11) # 11 vehicle classes
|
| 45 |
+
|
| 46 |
+
# Load fine-tuned weights
|
| 47 |
+
model.load_state_dict(torch.load("fine_tuned_model/pytorch_model.bin", map_location=torch.device('cpu')))
|
| 48 |
+
model.eval() # Set to evaluation mode
|
| 49 |
+
|
| 50 |
+
# Load class labels
|
| 51 |
+
with open("fine_tuned_model/classes.txt", "r") as f:
|
| 52 |
+
class_names = f.read().splitlines()
|
| 53 |
+
|
| 54 |
+
# Define preprocessing transformations
|
| 55 |
+
transform = transforms.Compose([
|
| 56 |
+
transforms.Resize((224, 224)),
|
| 57 |
+
transforms.ToTensor(),
|
| 58 |
+
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
|
| 59 |
+
])
|
| 60 |
+
|
| 61 |
+
# Load and preprocess a test image
|
| 62 |
+
image_path = "path_to_your_image.jpg" # Change this to your test image path
|
| 63 |
+
image = Image.open(image_path).convert("RGB")
|
| 64 |
+
input_tensor = transform(image).unsqueeze(0)
|
| 65 |
+
|
| 66 |
+
# Make prediction
|
| 67 |
+
with torch.no_grad():
|
| 68 |
+
outputs = model(input_tensor)
|
| 69 |
+
_, predicted_class = torch.max(outputs, 1)
|
| 70 |
+
|
| 71 |
+
print(f"Predicted Vehicle Type: {class_names[predicted_class.item()]}")
|
| 72 |
+
```
|
| 73 |
+
|
| 74 |
+
## Performance Metrics
|
| 75 |
+
|
| 76 |
+
- **Validation Accuracy:** High accuracy achieved on the test dataset
|
| 77 |
+
- **Inference Speed:** Optimized for real-time classification
|
| 78 |
+
- **Robustness:** Trained with data augmentation to handle variations in lighting and angles
|
| 79 |
+
|
| 80 |
+
## Dataset Details
|
| 81 |
+
|
| 82 |
+
The dataset consists of **50,000 images** across **11 vehicle types**, structured in the following folders:
|
| 83 |
+
- **articulated_truck**
|
| 84 |
+
- **bicycle**
|
| 85 |
+
- **bus**
|
| 86 |
+
- **car**
|
| 87 |
+
- **motorcycle**
|
| 88 |
+
- **non-motorized_vehicle**
|
| 89 |
+
- **pedestrian**
|
| 90 |
+
- **pickup_truck**
|
| 91 |
+
- **single_unit_truck**
|
| 92 |
+
- **work_van**
|
| 93 |
+
- **unknown**
|
| 94 |
+
|
| 95 |
+
### Training Details
|
| 96 |
+
|
| 97 |
+
- **Number of Epochs:** 10
|
| 98 |
+
- **Batch Size:** 32
|
| 99 |
+
- **Optimizer:** Adam
|
| 100 |
+
- **Learning Rate:** 1e-4
|
| 101 |
+
- **Loss Function:** Cross-Entropy Loss
|
| 102 |
+
- **Data Augmentation:** Horizontal flipping, random cropping, normalization
|
| 103 |
+
|
| 104 |
+
## Repository Structure
|
| 105 |
+
|
| 106 |
+
```
|
| 107 |
+
.
|
| 108 |
+
βββ fine_tuned_model/ # Contains the fine-tuned model files
|
| 109 |
+
β βββ pytorch_model.bin # Model weights
|
| 110 |
+
β βββ classes.txt # Class labels
|
| 111 |
+
βββ dataset/ # Training dataset (MIO-TCD subset)
|
| 112 |
+
βββ scripts/ # Training and evaluation scripts
|
| 113 |
+
βββ README.md # Model documentation
|
| 114 |
+
```
|
| 115 |
+
|
| 116 |
+
## Limitations
|
| 117 |
+
|
| 118 |
+
- The model is trained specifically on the **MIO-TCD dataset** and may not generalize well to images from different sources.
|
| 119 |
+
- Accuracy may vary based on real-world conditions such as lighting, occlusion, and camera angles.
|
| 120 |
+
- Requires GPU for faster inference.
|
| 121 |
+
|
| 122 |
+
## Contributing
|
| 123 |
+
|
| 124 |
+
Contributions are welcome! If you have suggestions for improvement, feel free to submit a pull request or open an issue.
|
| 125 |
+
|
| 126 |
+
|