Upload initial DeepLabV3 ResNet50 segmentation model with corrected README.md
Browse files- README.md +83 -0
- deeplabv3_resnet50_offroad.pth +3 -0
README.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
---
|
| 3 |
+
base_model: deeplabv3_resnet50
|
| 4 |
+
model_name: offroad_segmentation
|
| 5 |
+
tags:
|
| 6 |
+
- image-segmentation
|
| 7 |
+
- pytorch
|
| 8 |
+
- computer-vision
|
| 9 |
+
- deeplabv3
|
| 10 |
+
widget:
|
| 11 |
+
- src: https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/widget-images/image-segmentation.png
|
| 12 |
+
example_title: Image segmentation example
|
| 13 |
+
---
|
| 14 |
+
# Offroad Terrain Segmentation Model
|
| 15 |
+
|
| 16 |
+
This is a semantic segmentation model trained to identify offroad terrains from images.
|
| 17 |
+
|
| 18 |
+
## Model Details
|
| 19 |
+
- **Model Architecture**: DeepLabV3 with ResNet50 backbone
|
| 20 |
+
- **Pre-training**: Initialized with weights pre-trained on COCO dataset
|
| 21 |
+
- **Dataset**: 'Offroad_Segmentation_Training_Dataset'
|
| 22 |
+
- **Input**: RGB images (540x960 pixels)
|
| 23 |
+
- **Output**: Segmentation mask with 2 classes (e.g., background, offroad terrain)
|
| 24 |
+
- **Training Epochs**: 10
|
| 25 |
+
- **Batch Size**: 16
|
| 26 |
+
- **Learning Rate**: 0.001
|
| 27 |
+
|
| 28 |
+
## Training Metrics
|
| 29 |
+
- **Final Training Loss**: 0.0682
|
| 30 |
+
- **Final Validation Loss**: 0.0785
|
| 31 |
+
- **Final Training Mean IoU**: 0.2789
|
| 32 |
+
- **Final Validation Mean IoU**: 0.2690
|
| 33 |
+
|
| 34 |
+
## How to use
|
| 35 |
+
|
| 36 |
+
```python
|
| 37 |
+
import torch
|
| 38 |
+
import torchvision.models.segmentation as models
|
| 39 |
+
from torchvision import transforms
|
| 40 |
+
from PIL import Image
|
| 41 |
+
import cv2
|
| 42 |
+
import numpy as np
|
| 43 |
+
|
| 44 |
+
# Load the model architecture
|
| 45 |
+
model = models.deeplabv3_resnet50(pretrained=False) # Set pretrained=False as we load custom weights
|
| 46 |
+
model.classifier[4] = torch.nn.Conv2d(256, 2, kernel_size=1) # Adjust output channels for 2 classes
|
| 47 |
+
|
| 48 |
+
# Load the state dictionary
|
| 49 |
+
model_path = "deeplabv3_resnet50_offroad.pth" # Path to your saved model
|
| 50 |
+
model.load_state_dict(torch.load(model_path, map_location=torch.device('cpu')))
|
| 51 |
+
model.eval()
|
| 52 |
+
|
| 53 |
+
# Preprocessing transformations
|
| 54 |
+
transform = transforms.Compose([
|
| 55 |
+
transforms.ToTensor(),
|
| 56 |
+
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
|
| 57 |
+
])
|
| 58 |
+
|
| 59 |
+
def predict_mask(image_path, model, transform):
|
| 60 |
+
image = Image.open(image_path).convert("RGB")
|
| 61 |
+
original_size = image.size
|
| 62 |
+
|
| 63 |
+
# Resize to model's expected input size (960x540 for this model, or handle dynamic resizing)
|
| 64 |
+
# For simplicity, assuming model input was trained on fixed size, let's resize
|
| 65 |
+
image_tensor = transform(image).unsqueeze(0) # Add batch dimension
|
| 66 |
+
|
| 67 |
+
with torch.no_grad():
|
| 68 |
+
output = model(image_tensor)['out']
|
| 69 |
+
|
| 70 |
+
# Get the predicted class for each pixel
|
| 71 |
+
predicted_mask = torch.argmax(output.squeeze(), dim=0).cpu().numpy()
|
| 72 |
+
|
| 73 |
+
# Resize mask back to original image size if necessary
|
| 74 |
+
predicted_mask_resized = cv2.resize(predicted_mask.astype(np.uint8), original_size, interpolation=cv2.INTER_NEAREST)
|
| 75 |
+
|
| 76 |
+
return predicted_mask_resized
|
| 77 |
+
|
| 78 |
+
# Example usage:
|
| 79 |
+
# Assuming you have an image 'test_image.jpg'
|
| 80 |
+
# mask = predict_mask('test_image.jpg', model, transform)
|
| 81 |
+
# plt.imshow(mask)
|
| 82 |
+
# plt.show()
|
| 83 |
+
```
|
deeplabv3_resnet50_offroad.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:331c810f137bb83c6e9100edf59fbaae27709f04f711ccce93ce784ce82fedf5
|
| 3 |
+
size 168355011
|