BiSeNet

CoinCheungMIT活跃维护

BiSeNet 语义分割网络的 PyTorch 实现,支持 Cityscapes、ADE20K、COCO-Stuff 数据集,并提供 ncnn、OpenVINO、TensorRT、Triton 等推理部署方案。

Add bisenetv2. My implementation of BiSeNet

0.1.0发布于 2026-11-09 12:54 UTC1,643star335fork同步于 2026-11-07 23:28 UTC

怎么上手

由 README 提炼,执行前请确认
python tools/demo.py --config configs/bisenetv2_city.py --weight-path /path/to/your/weights.pth --img-path ./example.png
硬件要求按 README 说明

README 给出的测试平台为 NVIDIA Tesla T4 GPU(驱动 450.80.02)、CUDA 10.2/11.3、cuDNN 8;未说明 CPU 运行与显存需求。

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

BiSeNetV1/V2 实时语义分割的 PyTorch 实现,带预训练权重和多种部署方案

BiSeNet 语义分割网络的 PyTorch 实现,支持 Cityscapes、ADE20K、COCO-Stuff 数据集,并提供 ncnn、OpenVINO、TensorRT、Triton 等推理部署方案。

核心能力

  • 提供 BiSeNetV1 与 BiSeNetV2 两套分割网络实现
  • 在 cityscapes 上给出 ss/ssc/msf/mscf 多种评测 mIOU 与 fps
  • 附带 cityscapes、cocostuff、ade20k 预训练权重下载
  • 支持 TensorRT、ncnn、OpenVINO、Triton 四种部署路径
  • 提供单图、视频与摄像头推理脚本及自定义数据集训练配置

容易踩的坑

推理需自行从 release 下载对应 .pth 权重,仓库不含权重文件;训练 cocostuff 因 171 类显存占用更高,需拆到多于 2 张 GPU;BiSeNetV2 虽 flops 更少但训练迭代次数远多于 V1,且结果方差较大。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

2 个版本0.1.0
  1. 0.1.0最新正式版2026-11-09 · 2026-11-09 12:54 UTC

    single gpu training, tuned lr/wd, smaller heads; weights are not compatible with 0.0.0 code

  2. 0.0.0original implementation2020-08-06 · 2020-08-06 02:21 UTC
    查看更新说明

    It is a back up commit of the original implementation which is not so clear. After this release, the code will be refactored.

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    BiSeNetV1 & BiSeNetV2

    My implementation of BiSeNetV1 and BiSeNetV2.

    mIOUs and fps on cityscapes val set:

    nonesssscmsfmscffps(fp32/fp16/int8)link
    bisenetv175.4476.9477.4578.8671/165/426download
    bisenetv274.9575.5876.5377.0872/171/108download

    mIOUs on cocostuff val2017 set:

    nonesssscmsfmscflink
    bisenetv131.4931.4232.4632.55download
    bisenetv230.4930.5531.8131.73download

    mIOUs on ade20k val set:

    nonesssscmsfmscflink
    bisenetv136.1536.0437.2736.58download
    bisenetv232.5332.4333.2331.72download

    Tips:

    1. ss means single scale evaluation, ssc means single scale crop evaluation, msf means multi-scale evaluation with flip augment, and mscf means multi-scale crop evaluation with flip evaluation. The eval scales and crop size of multi-scales evaluation can be found in configs.

    2. The fps is tested in different way from the paper. For more information, please see here.

    3. The authors of bisenetv2 used cocostuff-10k, while I used cocostuff-123k(do not know how to say, just same 118k train and 5k val images as object detection). Thus the results maybe different from paper.

    4. The authors did not report results on ade20k, thus there is no official training settings, here I simply provide a "make it work" result. Maybe the results on ade20k can be boosted with better settings.

    5. The model has a big variance, which means that the results of training for many times would vary within a relatively big margin. For example, if you train bisenetv2 on cityscapes for many times, you will observe that the result of ss evaluation of bisenetv2 varies between 73.1-75.1.

    deploy trained models

    1. tensorrt
      You can go to tensorrt for details.

    2. ncnn
      You can go to ncnn for details.

    3. openvino
      You can go to openvino for details.

    4. tis
      Triton Inference Server(TIS) provides a service solution of deployment. You can go to tis for details.

    platform

    My platform is like this:

    • ubuntu 18.04
    • nvidia Tesla T4 gpu, driver 450.80.02
    • cuda 10.2/11.3
    • cudnn 8
    • miniconda python 3.8.8
    • pytorch 1.11.0

    get start

    With a pretrained weight, you can run inference on an single image like this:

    $ python tools/demo.py --config configs/bisenetv2_city.py --weight-path /path/to/your/weights.pth --img-path ./example.png
    

    This would run inference on the image and save the result image to ./res.jpg.

    Or you can run inference on a video like this:

    $ python tools/demo_video.py --config configs/bisenetv2_coco.py --weight-path res/model_final.pth --input ./video.mp4 --output res.mp4
    

    This would generate segmentation file as res.mp4. If you want to read from camera, you can set --input camera_id rather than input ./video.mp4.

    prepare dataset

    1.cityscapes

    Register and download the dataset from the official website. Then decompress them into the datasets/cityscapes directory:

    $ mv /path/to/leftImg8bit_trainvaltest.zip datasets/cityscapes
    $ mv /path/to/gtFine_trainvaltest.zip datasets/cityscapes
    $ cd datasets/cityscapes
    $ unzip leftImg8bit_trainvaltest.zip
    $ unzip gtFine_trainvaltest.zip
    

    2.cocostuff

    Download train2017.zip, val2017.zip and stuffthingmaps_trainval2017.zip split from official website. Then do as following:

    $ unzip train2017.zip
    $ unzip val2017.zip
    $ mv train2017/ /path/to/BiSeNet/datasets/coco/images
    $ mv val2017/ /path/to/BiSeNet/datasets/coco/images
    
    $ unzip stuffthingmaps_trainval2017.zip
    $ mv train2017/ /path/to/BiSeNet/datasets/coco/labels
    $ mv val2017/ /path/to/BiSeNet/datasets/coco/labels
    
    $ cd /path/to/BiSeNet
    $ python tools/gen_dataset_annos.py --dataset coco
    

    3.ade20k

    Download ADEChallengeData2016.zip from this website and unzip it. Then we can move the uncompressed folders to datasets/ade20k, and generate the txt files with the script I prepared for you:

    $ unzip ADEChallengeData2016.zip
    $ mv ADEChallengeData2016/images /path/to/BiSeNet/datasets/ade20k/
    $ mv ADEChallengeData2016/annotations /path/to/BiSeNet/datasets/ade20k/
    $ python tools/gen_dataset_annos.py --dataset ade20k
    

    4.custom dataset

    If you want to train on your own dataset, you should generate annotation files first with the format like this:

    munster_000002_000019_leftImg8bit.png,munster_000002_000019_gtFine_labelIds.png
    frankfurt_000001_079206_leftImg8bit.png,frankfurt_000001_079206_gtFine_labelIds.png
    ...
    

    Each line is a pair of training sample and ground truth image path, which are separated by a single comma ,.

    I recommand you to check the information of your dataset with the script:

    $ python tools/check_dataset_info.py --im_root /path/to/your/data_root --im_anns /path/to/your/anno_file
    

    This will print some of the information of your dataset.

    Then you need to change the field of im_root and train/val_im_anns in the config file. I prepared a demo config file for you named bisenet_customer.py. You can start from this conig file.

    train

    Training commands I used to train the models can be found in here.

    Note:

    1. though bisenetv2 has fewer flops, it requires much more training iterations. The the training time of bisenetv1 is shorter.
    2. I used overall batch size of 16 to train all models. Since cocostuff has 171 categories, it requires more memory to train models on it. I split the 16 images into more gpus than 2, as I do with cityscapes.

    finetune from trained model

    You can also load the trained model weights and finetune from it, like this:

    $ export CUDA_VISIBLE_DEVICES=0,1
    $ torchrun --nproc_per_node=2 tools/train_amp.py --finetune-from ./res/model_final.pth --config ./configs/bisenetv2_city.py # or bisenetv1
    

    eval pretrained models

    You can also evaluate a trained model like this:

    $ python tools/evaluate.py --config configs/bisenetv1_city.py --weight-path /path/to/your/weight.pth
    

    or you can use multi gpus:

    $ torchrun --nproc_per_node=2 tools/evaluate.py --config configs/bisenetv1_city.py --weight-path /path/to/your/weight.pth
    

    Be aware that this is the refactored version of the original codebase. You can go to the old directory for original implementation if you need, though I believe you will not need it.