GASNet is a lightweight single-class segmentation model built on MobileNetV3-Small. It predicts foreground masks using geometric priors (signed distance transform) and soft boundary maps. The network uses an attention-based fusion module to combine semantic features with spatial and boundary cues.
- Backbone: MobileNetV3-Small (ImageNet-pretrained)
- Heads: Dual-task heads produce spatial priors and boundary predictions
- Fusion: Attention module gates features using prior magnitude and boundary information
- Decoder: Upsamples fused features with skip connections to produce the final mask
- Mask loss: Dice loss + boundary-weighted BCE
- Spatial loss: Smooth L1 between predicted prior and signed distance transform
- Boundary loss: BCE on soft boundary targets
- Consistency loss: Geometry consistency between mask and spatial prior
- torch
- torchvision
- Pillow
- numpy
- opencv-python
- scipy
- albumentations
Organize your data as follows:
data/
├── train/
│ ├── images/
│ │ ├── img_001.png
│ │ ├── img_002.png
│ │ └── ...
│ └── masks/
│ ├── img_001.png
│ ├── img_002.png
│ └── ...
├── val/
│ ├── images/
│ │ └── ...
│ └── masks/
│ └── ...
└── test/
├── images/
│ └── ...
└── masks/
└── ...
Rules:
- Split (
train,val,test) must contain bothimagesandmasksdirectories - Masks must have the exact same filename as their corresponding image.
- Filenames are matched by name.
Results after training on the Person class of COCO training dataset.
python train.pyKey hyperparameters:
- Target size: 320px (adaptive max-dimension scaling with reflection padding)
- Optimizer: AdamW (lr=3e-4)
- LR schedule: Cosine annealing with warmup
from model import GASNet
from util import run_gasnet
import torch
from PIL import Image
model = GASNet()
model.load_state_dict(torch.load("gasnet.pt", map_location="cpu"))
model.eval()
image = Image.open("image.jpg").convert("RGB")
mask, num_det = run_gasnet(model, image, conf_threshold=0.55)run_gasnet returns a binary mask (0/1 uint8) resized to the original image dimensions.

