FlashSeg
Ultra-lightweight real-time semantic segmentation with LoRA fine-tuning & knowledge distillation
Install • Usage • Models • Solutions • Training • Examples
What is FlashSeg?
FlashSeg is an ultra-lightweight semantic segmentation framework built for speed and edge deployment. Using a ShuffleNetV2 backbone with FPN neck, it delivers real-time pixel-level predictions with models as small as 0.3M parameters.
pip install -e .
flashseg train --model-size m --num-classes 21 --train-images data/images --train-masks data/masks --val-images data/val_img --val-masks data/val_mask
flashseg predict --model best.pth --source images/
Installation
# From source
git clone https://github.com/FlashVision/FlashSeg.git
cd FlashSeg
pip install -e ".[all]"
Optional extras
pip install -e ".[export]" # ONNX export
pip install -e ".[analytics]" # Benchmarking, plots
pip install -e ".[solutions]" # Background removal, lane detection
pip install -e ".[all]" # Everything
Verify
flashseg check
flashseg settings
flashseg version
Usage
Python API
from flashseg import Trainer, Predictor, Exporter
# Train
trainer = Trainer(
model_size="m",
train_images="data/images",
train_masks="data/masks",
val_images="data/val_images",
val_masks="data/val_masks",
num_classes=21,
epochs=100,
device="cuda",
)
trainer.train()
# Predict
predictor = Predictor(model_path="workspace/best.pth", num_classes=21, device="cuda")
mask = predictor.predict("photo.jpg")
# Export
exporter = Exporter(model_path="workspace/best.pth", num_classes=21)
exporter.export(output="model.onnx", simplify=True)
CLI
flashseg train --model-size m --epochs 100 --device cuda \
--train-images data/images --train-masks data/masks \
--val-images data/val_img --val-masks data/val_mask --num-classes 21
flashseg predict --model best.pth --source images/ --save-dir output/
flashseg val --model best.pth --val-images data/val --val-masks data/val_mask
flashseg export --model best.pth --output model.onnx --simplify
Models
| Model | Params | FP16 Size | Input | mIoU (VOC) |
|---|---|---|---|---|
| FlashSeg-n | 0.3M | ~0.7 MB | 256 | — |
| FlashSeg-s | 0.8M | ~1.6 MB | 256 | — |
| FlashSeg-m | 1.5M | ~3.0 MB | 512 | — |
| FlashSeg-l | 3.2M | ~6.4 MB | 512 | — |
Config-driven Training
flashseg train --config configs/flashseg_m_512_voc.yaml
flashseg train --config configs/flashseg_s_256_cityscapes.yaml
flashseg train --config configs/flashseg_m_512_lora.yaml
Solutions
Built-in high-level applications:
from flashseg import Predictor
from flashseg.solutions import BackgroundRemover, LaneDetector, SceneParser, AreaCalculator
predictor = Predictor(model_path="best.pth", num_classes=21)
# Remove background
remover = BackgroundRemover(predictor, foreground_classes=[15])
result = remover.remove(image)
# Detect lanes
lanes = LaneDetector(predictor, lane_class_id=1)
# Parse scenes
parser = SceneParser(predictor, class_names=["bg", "road", "building", ...])
stats = parser.parse(image) # {"road": 35.2, "building": 12.1, ...}
# Calculate areas
calc = AreaCalculator(predictor, pixels_per_meter=10.0)
areas = calc.calculate(image) # {class_id: area_m2, ...}
| Solution | Description |
|---|---|
| BackgroundRemover | Remove/replace backgrounds, generate alpha mattes |
| LaneDetector | Detect road lanes from segmentation |
| SceneParser | Break scene into labeled regions with area stats |
| AreaCalculator | Measure real-world areas from masks |
Training
Standard
flashseg train --model-size m --epochs 100 --num-classes 21 --device cuda
LoRA Fine-Tuning
flashseg train --model-size m --lora --config configs/flashseg_m_512_lora.yaml
Mixed Precision
flashseg train --model-size m --amp --device cuda
Examples
| Script | What it does |
|---|---|
train_voc.py |
Train on Pascal VOC |
predict_image.py |
Segment a single image |
background_removal.py |
Remove image background |
export_onnx.py |
Export to ONNX |
benchmark_model.py |
Measure FPS and latency |
Project Structure
FlashSeg/
├── flashseg/ # Main package
│ ├── cfg/ # Configuration + YAML loading
│ ├── data/ # Datasets, transforms
│ ├── engine/ # Trainer, Predictor, Exporter, Validator
│ ├── models/ # ShuffleNetV2, FPN, SegHead
│ ├── losses/ # CE, Dice, Focal, Combined
│ ├── nn/ # ConvBnRelu, ASPP, DepthwiseSeparable
│ ├── utils/ # Metrics, visualization
│ ├── solutions/ # Background removal, lanes, scene parsing
│ └── analytics/ # Benchmark, profiler
├── configs/ # YAML configs (pick & train)
├── examples/ # Ready-to-run scripts
├── tests/ # Unit tests
├── docker/ # Dockerfile + compose
├── pyproject.toml # Package config
└── LICENSE # MIT
Docker
docker build -t flashseg -f docker/Dockerfile .
docker run --gpus all -v $(pwd)/data:/app/data flashseg predict --model best.pth --source data/
Contributing
git clone https://github.com/FlashVision/FlashSeg.git
cd FlashSeg
pip install -e ".[dev,all]"
ruff check flashseg/
pytest tests/ -v
License
MIT — see LICENSE.
FlashVision — Open-source lightweight AI
Metadata
Release files for flashseg 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| flashseg-1.0.0.tar.gz | 24.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| flashseg-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 54.7 kB
Release files / flashseg-1.0.0.tar.gz
| Download URL | flashseg-1.0.0.tar.gz |
|---|---|
| Size | 24.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0a2b9b8457d7481554c93601c043aadb67f6da5ee035140543d314044fa1bb91
|
|
BLAKE2b-256 checksum How to use checksums |
1ad3cfd4bb8b04ff15f7ea76a7fbe9817b105a1b8ccee72de3b6ffb3ea00eb75
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.11
|
Release files / flashseg-1.0.0-py3-none-any.whl
| Download URL | flashseg-1.0.0-py3-none-any.whl |
|---|---|
| Size | 30.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1798da485b56d891f7967277c1d1aba84966e34610331f5dea06d09ba9156623
|
|
BLAKE2b-256 checksum How to use checksums |
38a6d71f496c36a6a1c2c91b895fa983a0d5951351667d9b28185daf588aad16
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.11
|
Security for flashseg 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.