Skip to content

Automated segmentation of SAR images to find Ships. Implemented with Meta's SAM3 model + UNET trained on SAR imagery converted to 3 channel false RGB.

License

Notifications You must be signed in to change notification settings

edwardarchaeology/SAR_Segmentation_with_SAM3_UNET

Repository files navigation

SAM3SAR: Ship Segmentation in SAR with SAM3‑UNet (Personal Project)

Screenshot 2026-01-24 134656

This is my personal project to train a SAM3‑UNet model to segment ships in SAR imagery. I started from the upstream SAM3‑UNet implementation and adapted it to a SAR ship segmentation workflow (dataset prep, evaluation, and inference on never‑seen Sentinel‑1 scenes).

Upstream references:

Notes:

  • data/ and weights/ are intentionally ignored by git (see .gitignore).
  • SAM3 weights may require approval to download (I had to request access).

Repo layout

  • train.py, train.sh: training entrypoints
  • test.py, test.sh: dataset-style inference (expects images + masks)
  • infer.py: inference on a single image or folder (supports tiled inference for huge scenes)
  • eval_segmentation.py: threshold sweep + relaxed IoU + object metrics + overlay outputs
  • tools/find_singapore_scenes.py: download Sentinel‑1 over Singapore (and Sentinel‑2 preview) and optionally convert to PNG
  • project_writeup.md: blog-style writeup of the full project
  • tutorial_for_dummies.md: friendly “from zero” tutorial

Quickstart (existing SSDD-style dataset)

  1. Put your data in:
data/ships/train/images
data/ships/train/masks
data/ships/val/images
data/ships/val/masks
  1. Train:
bash train.sh
  1. Predict on validation:
python test.py \
  --checkpoint runs/sam3_ssdd_wsl/SAM3-UNet-10.pth \
  --test_image_path data/ships/val/images \
  --test_gt_path data/ships/val/masks \
  --save_path runs/sam3_ssdd_wsl/preds_ep10
  1. Evaluate:
python eval_segmentation.py \
  --val_images data/ships/val/images \
  --val_masks data/ships/val/masks \
  --pred_dir runs/sam3_ssdd_wsl/preds_ep10 \
  --out_dir runs/sam3_ssdd_wsl/eval_ep10

Inference on a new SAR image (no masks required)

Single image:

python infer.py \
  --checkpoint runs/sam3_ssdd_wsl/SAM3-UNet-10.pth \
  --input /path/to/image.png \
  --out-dir runs/sam3_ssdd_wsl/preds_new

Tiled inference (recommended for huge Sentinel‑1 scenes):

python infer.py \
  --checkpoint runs/sam3_ssdd_wsl/SAM3-UNet-10.pth \
  --input /path/to/big_scene.png \
  --out-dir runs/sam3_ssdd_wsl/preds_new \
  --tile \
  --tile-size 336 \
  --stride 256 \
  --minmax

Download a never-seen Sentinel‑1 scene (Singapore port)

Set CDSE credentials in your shell (don’t commit them):

export CDSE_USERNAME="your_cdse_email"
export CDSE_PASSWORD='your_password'

Download SAFE via OData, extract VV band, convert to PNG:

python tools/find_singapore_scenes.py \
  --download-full-s1 \
  --full-out-dir runs/cdse_full \
  --s1-band vv \
  --convert-png

Then run infer.py on the produced PNG.

License and attribution

  • This repo builds on upstream SAM3‑UNet and SAM3; please follow their licenses and citation guidance if you publish results.

About

Automated segmentation of SAR images to find Ships. Implemented with Meta's SAM3 model + UNET trained on SAR imagery converted to 3 channel false RGB.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages