All Projects → MaybeShewill-CV → Bisenetv2 Tensorflow

MaybeShewill-CV / Bisenetv2 Tensorflow

Licence: mit
Unofficial tensorflow implementation of real-time scene image segmentation model "BiSeNet V2: Bilateral Network with Guided Aggregation for Real-time Semantic Segmentation"

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Bisenetv2 Tensorflow

Ademxapp
Code for https://arxiv.org/abs/1611.10080
Stars: ✭ 333 (+139.57%)
Mutual labels:  semantic-segmentation, cityscapes
Tusimple Duc
Understanding Convolution for Semantic Segmentation
Stars: ✭ 567 (+307.91%)
Mutual labels:  semantic-segmentation, cityscapes
Panoptic Deeplab
This is Pytorch re-implementation of our CVPR 2020 paper "Panoptic-DeepLab: A Simple, Strong, and Fast Baseline for Bottom-Up Panoptic Segmentation" (https://arxiv.org/abs/1911.10194)
Stars: ✭ 355 (+155.4%)
Mutual labels:  semantic-segmentation, cityscapes
Nas Segm Pytorch
Code for Fast Neural Architecture Search of Compact Semantic Segmentation Models via Auxiliary Cells, CVPR '19
Stars: ✭ 126 (-9.35%)
Mutual labels:  semantic-segmentation, cityscapes
Contrastiveseg
Exploring Cross-Image Pixel Contrast for Semantic Segmentation
Stars: ✭ 135 (-2.88%)
Mutual labels:  semantic-segmentation, cityscapes
Pspnet Tensorflow
TensorFlow-based implementation of "Pyramid Scene Parsing Network".
Stars: ✭ 313 (+125.18%)
Mutual labels:  semantic-segmentation, cityscapes
Fasterseg
[ICLR 2020] "FasterSeg: Searching for Faster Real-time Semantic Segmentation" by Wuyang Chen, Xinyu Gong, Xianming Liu, Qian Zhang, Yuan Li, Zhangyang Wang
Stars: ✭ 438 (+215.11%)
Mutual labels:  semantic-segmentation, cityscapes
Dilation-Pytorch-Semantic-Segmentation
A PyTorch implementation of semantic segmentation according to Multi-Scale Context Aggregation by Dilated Convolutions by Yu and Koltun.
Stars: ✭ 32 (-76.98%)
Mutual labels:  semantic-segmentation, cityscapes
Deeplabv3 Plus
Tensorflow 2.3.0 implementation of DeepLabV3-Plus
Stars: ✭ 32 (-76.98%)
Mutual labels:  semantic-segmentation, cityscapes
Lightnet
LightNet: Light-weight Networks for Semantic Image Segmentation (Cityscapes and Mapillary Vistas Dataset)
Stars: ✭ 698 (+402.16%)
Mutual labels:  semantic-segmentation, cityscapes
Erfnet pytorch
Pytorch code for semantic segmentation using ERFNet
Stars: ✭ 304 (+118.71%)
Mutual labels:  semantic-segmentation, cityscapes
Chainer Pspnet
PSPNet in Chainer
Stars: ✭ 76 (-45.32%)
Mutual labels:  semantic-segmentation, cityscapes
DST-CBC
Implementation of our paper "DMT: Dynamic Mutual Training for Semi-Supervised Learning"
Stars: ✭ 98 (-29.5%)
Mutual labels:  semantic-segmentation, cityscapes
Edgenets
This repository contains the source code of our work on designing efficient CNNs for computer vision
Stars: ✭ 331 (+138.13%)
Mutual labels:  semantic-segmentation, cityscapes
LightNet
LightNet: Light-weight Networks for Semantic Image Segmentation (Cityscapes and Mapillary Vistas Dataset)
Stars: ✭ 710 (+410.79%)
Mutual labels:  semantic-segmentation, cityscapes
Icnet Tensorflow
TensorFlow-based implementation of "ICNet for Real-Time Semantic Segmentation on High-Resolution Images".
Stars: ✭ 396 (+184.89%)
Mutual labels:  semantic-segmentation, cityscapes
semantic-segmentation-tensorflow
Semantic segmentation task for ADE20k & cityscapse dataset, based on several models.
Stars: ✭ 84 (-39.57%)
Mutual labels:  semantic-segmentation, cityscapes
plusseg
ShanghaiTech PLUS Lab Segmentation Toolbox and Benchmark
Stars: ✭ 21 (-84.89%)
Mutual labels:  semantic-segmentation, cityscapes
Efficient Segmentation Networks
Lightweight models for real-time semantic segmentationon PyTorch (include SQNet, LinkNet, SegNet, UNet, ENet, ERFNet, EDANet, ESPNet, ESPNetv2, LEDNet, ESNet, FSSNet, CGNet, DABNet, Fast-SCNN, ContextNet, FPENet, etc.)
Stars: ✭ 579 (+316.55%)
Mutual labels:  semantic-segmentation, cityscapes
Pytorch Auto Drive
Segmentation models (ERFNet, ENet, DeepLab, FCN...) and Lane detection models (SCNN, SAD, PRNet, RESA, LSTR...) based on PyTorch 1.6 with mixed precision training
Stars: ✭ 32 (-76.98%)
Mutual labels:  semantic-segmentation, cityscapes

BiseNetv2-Tensorflow

Use tensorflow to implement a real-time scene image segmentation model based on paper "BiSeNet V2: Bilateral Network with Guided Aggregation for Real-time Semantic Segmentation". You may refer https://arxiv.org/abs/2004.02147 for details.

The main network architecture is as follows:

Network Architecture NetWork_Architecture

Installation

This software has only been tested on ubuntu 16.04(x64), python3.5, cuda-9.0, cudnn-7.0 with a GTX-1070 GPU. To use this repo you need to install tensorflow-gpu 1.12.0 and other version of tensorflow has not been tested but I think it will be able to work properly if new version was installed in your local machine. Other required package can be installed by

pip3 install -r requirements.txt

CityScapes Dataset preparation

The repo's model was mainly trained on cityscapes dataset. First you need to prepare cityscapes dataset well. An example cityscapes dataset file hierarchy can be found in ./data/example_dataset

The cityscapes dataset hierarchy:

CityScapes Dataset Hierarchy

Dataset_File_Hierarchy

Once you have prepared the dataset's image well you may generate the training image index file by

python ./data/example_dataset/cityscapes/image_file_index/make_image_file_index.py

If it was successfully executed you may see train.txt etc in folder ./data/example_dataset/cityscapes/image_file_index/. Each row of the file contains a pair of training samples.

Test model

In this repo I uploaded a model trained on cityscapes dataset CityScapes. The pretrained model can be found at ./model/cityscapes/bisenetv2. The pretrained model can reach a miou of 72.386 on cityscapes validation dataset. This implementation can reach a 83fps on GTX 1070 accelerated by tensorrt. The pretrained model can be downloaded here

You can test a single image on the trained model as follows

python tools/cityscapes/test_bisenetv2_cityscapes.py --weights_path ./model/cityscapes/bisenetv2/cityscapes.ckpt 
--src_image_path ./data/test_image/test_01.png

The results are as follows:

Test Input Image 1

Test Input

Decoded Output Mask Image 1

Test Lane_Mask

Test Input Image 2

Test Input

Decoded Output Mask Image 2

Test Lane_Mask

Test Input Image 3

Test Input

Decoded Output Mask Image 3

Test Lane_Mask

If you want to evaluate the model on the whole cityscapes validation dataset you may call

python tools/cityscapes/evaluate_bisenetv2_cityscapes.py 
--pb_file_path ./checkpoint/bisenetv2_cityscapes_frozen.pb
--dataset_dir ./data/example_dataset/cityscapes

You may get the final mious on the whole validation dataset

Evaluation Result Eval_Miou

The validation procedure doesn't adopt any evaluation tricks such as sliding-window evaluation and multi-scale testing which can improve accuracy but are time-consuming. With the input of 2048 × 1024 resolution, we first resize it to 1024 × 512 resolution to inference and then resize the prediction to the original size of the input. You can do a multiscale evaluation via adjust the min_scale and max_scale in the evaluation script.

The instruction can be reached by

python tools/cityscapes/evaluate_bisenetv2_cityscapes.py --help

Train model from scratch

Data Preparation

For speed up the training procedure. Convert the origin training images into tensorflow records was highly recommended here which is also very memory consuming. If you don't have enough ROM you may adjust the data_provider in training scripts into ./data_provider/cityscapes_reader and use feed dict to train the model which can be pretty slow. If you have enough ROM then you may convert the training images into tensorflow records.

First modified the ./config/cityscapes_bisenetv2.yml with right dataset dir path

Config file dataset field Cityscapes_config_file_dataset_filed

Then sse the script here to generate the tensorflow records file

python tools/cityscapes/make_cityscapes_tfrecords.py

Train model

You may start your training procedure simply by

CUDA_VISIBLE_DEVICES="0, 1, 2, 3" python tools/cityscapes/train_bisenetv2_cityscapes.py

By default multi gpu training mode was used here. You may read ./config/cityscapes_bisenetv2.yml for details. If you do not have multi gpu you may forbid multi gpu training mode in the config file which may drop the model's performance since bn can not perform well in small batch size.

The main model's hyperparameter are as follows:

epoch nums: 905

learning rate: 0.05

lr decay strategy: poly with power 0.9

optimizer: SGD

batch size: 16

origin image size: [2048, 1024]

cropped image size: [2048, 1024]

step scaling range: [0.75, 2.0]

training example nums: 2975

testing example nums: 1525

validation example nums: 500

Other hyperparameter can be found in the config file.

You may monitor the training process using tensorboard tools

During my experiment the Total loss dropped as follows:
Training loss

The L2 loss dropped as follow: L2 loss

The Learning rate decayed as follows: Lr rate

The Miou increased as follows: Miou

Time Profile Model

Here supply some tools to time profile the model's performance. First make sure tf2onnx converter was successfully installed in your local machine. You may follow the instruction here to install it.

I have uploaded a frozen tensorflow pb model in ./checkpoint folder. You may run follows to freeze your own trainned models

python tools/cityscapes/freeze_cityscapes_bisenetv2_model.py 
--weights_path ./model/cityscapes/bisenetv2/cityscapes.ckpt

Once you have frozen pb model locally you may run following command to convert the pb model into onnx model.

bash scripts/convert_tensorflow_model_into_onnx.sh ./checkpoint/bisenetv2_cityscapes_frozen.pb ./checkpoint/bisenetv2_cityscapes_frozen.onnx

A pre-converted onnx model was supplied also if you want your time be saved. After all was done mentioned above you may simply run following command to time profile the model's performance.

python tools/cityscapes/timeprofile_cityscapes_bisenetv2.py 
--input_image_path ./data/test_image/test_01.png

Basically the script do such few things:

  1. Convert the onnx model into tensorrt engine
  2. Run origin tensorflow frozen model for 500 times to calculate a mean inference time comsuming and fps.
  3. Run accelarated tensorrt engine for 500 times to calculate a mean inference time comsuming and fps.
  4. Calculate the model's gflops statics.

The following result should be generated if nothing goes wrong.

TimeProfile Result Time_Profile

Disscussion

  1. The origin paper can reach a miou of 73.4 on cityscapes validation dataset which is outperformer than my implementation. I suspect the reason may be I did not use the standard synchronized bn in training procedure. Sereval experiments was doing recently. I will upload new model if I'm able to train a better one.
  2. Sereval params mentioned in the paper was not very clear for me. Here is a brief look at my confusion https://github.com/ycszen/BiSeNet/issues/2

If you have any ideas about such problem mentioned above or you have futher update. You're welcomed to pull a request to make this repo better.

Experiments on other dataset

Release a pretrainde model on CELEBAMASK_HQ dataset. The model can reach 107 fps with a input image of (512, 512) size. The pretrained mode can be downloaded here

Testing model script comes as follows:

python tools/celebamask_hq/test_bisenetv2_celebamaskhq.py 
--weights_path PATH/TO/YOUR/CKPT/FILE 
--src_image_path ./data/test_image/celebamask_hq/test_01.jpg

Celebamask_hq Test Source Input Image celebamask_test_input

Celebamask_hq Test Result Image

celebamask_test_result

TODO

  • [x] Add OHEM module
  • [ ] Search better hyperparameter for cityscapes dataset.
  • [ ] Do experiments on other dataset such as CamVid etc.
  • [x] Organize the code and release bisenetv1 training scripts and pretrained model.

Acknowledgement

Finally thanks to the origin author ycszen. BiseNet series are excellent work in my opinion. Really appreciate it.

Please cite my repo bisenetv2-tensorflow if you use it.

Contact

Scan the following QR to disscuss :) qr

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].