File size: 4,740 Bytes
cb55219
38bade1
 
 
 
 
a5b2d86
38bade1
 
a5b2d86
b4f4a03
 
f572eac
b4f4a03
 
 
 
 
 
 
 
 
14424f5
b4f4a03
14424f5
b4f4a03
 
 
 
 
14424f5
 
 
 
 
 
 
 
b4f4a03
 
 
f572eac
b4f4a03
14424f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f572eac
 
 
14424f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b4f4a03
 
 
14424f5
b4f4a03
14424f5
f572eac
14424f5
 
 
 
b4f4a03
 
 
14424f5
 
b4f4a03
 
 
 
 
 
 
 
14424f5
b4f4a03
 
 
f572eac
b4f4a03
14424f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
---
title: HRSID Ship Detection Demo
emoji: 🚒
colorFrom: blue
colorTo: indigo
sdk: gradio
sdk_version: 4.44.0
app_file: app.py
pinned: false
license: apache-2.0
tags:
  - object-detection
  - synthetic-aperture-radar
  - detectron2
  - faster-rcnn
  - ship-detection
datasets:
  - HRSID
metrics:
  - mAP
---

# 🚒 Ship Detection in SAR Imagery β€” Faster R-CNN (HRSID)

A **Faster R-CNN** model trained on the [HRSID](https://github.com/chaozhong2010/HRSID) dataset for robust ship detection in high-resolution Synthetic Aperture Radar (SAR) imagery. Upload a SAR image to detect ships in real time.

---

## 🧠 Model Architecture

| Component  | Detail                           |
|------------|----------------------------------|
| Framework  | Detectron2                       |
| Detector   | Faster R-CNN                     |
| Backbone   | ResNet-50 + FPN                  |
| Classes    | 1 (Ship)                         |
| Input Size | 1400 Γ— 1400                      |
| Inference  | CPU-compatible (HF Spaces free)  |

---

## πŸ“Š Training Configuration

| Parameter          | Value                        |
|--------------------|------------------------------|
| Dataset            | HRSID (train / val / test)   |
| Train Images       | 2,914                        |
| Val Images         | 728                          |
| Test Images        | 5,604                        |
| Total Instances    | 16,951 ships                 |
| Max Iterations     | 5,000                        |
| Batch Size         | 2                            |
| Base Learning Rate | 0.00025                      |
| Optimizer          | SGD                          |
| Eval Period        | Every 500 iterations         |
| Checkpoint Period  | Every 500 iterations         |
| Score Threshold    | 0.5                          |
| GPU                | Tesla T4 (15.6 GB VRAM)      |

**Augmentations:** Resize to 1400 Γ— 1400, random horizontal flip.

---

## πŸ“ˆ Evaluation Results

Evaluated on the HRSID **test split** (5,604 images) using COCO-style metrics.

| Metric                        | Value  |
|-------------------------------|--------|
| **AP (IoU=0.50:0.95)**        | **47.39** |
| **AP50 (IoU=0.50)**           | **71.88** |
| **AP75 (IoU=0.75)**           | **56.53** |
| APs (small objects)           | 48.54  |
| APm (medium objects)          | 48.55  |
| APl (large objects)           | 23.17  |
| AR @ maxDets=1                | 24.30  |
| AR @ maxDets=10               | 49.20  |
| AR @ maxDets=100              | 52.40  |
| AR small @ maxDets=100        | 50.60  |
| AR medium @ maxDets=100       | 66.70  |
| AR large @ maxDets=100        | 44.60  |

---

## πŸ›° Dataset

[HRSID (High-Resolution SAR Images Dataset)](https://github.com/chaozhong2010/HRSID) is a benchmark for ship detection and instance segmentation in SAR imagery.

- **5,604** SAR image crops
- **16,951** annotated ship instances (bounding boxes + segmentation masks)
- Multi-scale vessel distribution across coastal and open-sea scenarios
- Derived from Sentinel-1, TerraSAR-X, and TanDEM-X satellite imagery

---

## βš™οΈ Inference
````python
from detectron2.config import get_cfg
from detectron2.engine import DefaultPredictor
import cv2

cfg = get_cfg()
cfg.merge_from_file("config.yaml")
cfg.MODEL.WEIGHTS = "model_final.pth"
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.5
cfg.MODEL.DEVICE = "cpu"  # or "cuda"

predictor = DefaultPredictor(cfg)

image = cv2.imread("test_sar.jpg")
outputs = predictor(image)

instances = outputs["instances"]
print(f"Detected {len(instances)} ships")
print(f"Boxes:  {instances.pred_boxes}")
print(f"Scores: {instances.scores}")
````

---

## πŸ“¦ Repository Files

| File              | Description                          |
|-------------------|--------------------------------------|
| `model_final.pth` | Trained Faster R-CNN weights         |
| `config.yaml`     | Detectron2 model configuration       |
| `labels.json`     | Class label mapping `{0: "ship"}`    |
| `app.py`          | Gradio inference app                 |
| `requirements.txt`| Python dependencies                  |

---

## πŸš€ Run Locally
````bash
git clone https://huggingface.co/PUSHPENDAR/hrsid-ship-detection
cd hrsid-ship-detection
pip install -r requirements.txt
python app.py
````

---

## πŸ“ Citation
````bibtex
@article{wei2020hrsid,
  title={HRSID: A High-Resolution SAR Images Dataset for Ship Detection and Instance Segmentation},
  author={Wei, Shunjun and Zeng, Xiangfeng and Qu, Qizhe and Wang, Mou and Su, Hao and Shi, Jun},
  journal={IEEE Access},
  volume={8},
  pages={96962--96980},
  year={2020},
  publisher={IEEE}
}
````

---

## πŸ“„ License

Apache 2.0 β€” see [LICENSE](LICENSE) for details.