--- 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.