Code Monkey home page Code Monkey logo

linksense / lightnet Goto Github PK

View Code? Open in Web Editor NEW
715.0 29.0 175.0 89.78 MB

LightNet: Light-weight Networks for Semantic Image Segmentation (Cityscapes and Mapillary Vistas Dataset)

Home Page: https://ansleliu.github.io/LightNet.html

License: MIT License

Python 97.18% C 0.39% Shell 0.07% Cuda 1.40% C++ 0.96%
semantic-segmentation mobilenet-v2 deeplabv3plus wide-residual-networks pytorch cityscapes mapillary-vistas-dataset shufflenet inplace-activated-batchnorm mobilenet

lightnet's Introduction

LightNet

This repository contains the code (in PyTorch) for: "LightNet: Light-weight Networks for Semantic Image Segmentation " (underway) by Huijun Liu @ TU Braunschweig.

  • MobileNetV2Plus: Modified MobileNetV2[1,8] + Spatial-Channel Sequeeze & Excitation (SCSE)[6] + ASPP[2,3] + Encoder-Decoder Arch.[3] + InplaceABN[4].
  • RF-MobileNetV2Plus: Modified MobileNetV2 + SCSE + Receptive Field Block (RFB)[5] + Encoder-Decoder Arch. + InplaceABN.
  • MobileNetV2Vortex: Modified MobileNetV2 + SCSE + Vortex Pooling[24] + Encoder-Decoder Arch. + InplaceABN.
  • MobileNetV2Share: Split Image & Concat Features + Modified MobileNetV2 + SCSE + ASPP/RFB + Encoder-Decoder Arch. + InplaceABN.
  • Mixed-scale DenseNet: Modified Mixed-scale DenseNet[11] + SCSE + ASPP/RFB + InplaceABN.
  • SE-WResNetV2: Modified WResNetV2 (InplaceABN & SCSE/SE)[4,6,7,13] + SCSE/SE + ASPP/RFB + Encoder-Decoder Arch. + InplaceABN.
  • ShuffleNetPlus: Modified ShuffleNet[9] + SCSE + ASPP/RFB + Encoder-Decoder Arch. + InplaceABN.

!!!New!!!: add Vortex Pooling[24]

I no longer have GPUs to continue more experiments and model training (I borrowed 2 GPUs from the Institute for Computer Graphics @ TU Braunschweig to complete preliminary experiments, so thank them and Lukas Zhang here.), so if you like, welcome to experiment with other under-training models and my ideas!

Contents

  1. Introduction
  2. Usage
  3. Results
  4. Contacts
  5. References
  6. Acknowledgement

Introduction

Semantic Segmentation is a significant part of the modern autonomous driving system, as exact understanding the surrounding scene is very important for the navigation and driving decision of the self-driving car. Nowadays, deep fully convolutional networks (FCNs) have a very significant effect on semantic segmentation, but most of the relevant researchs have focused on improving segmentation accuracy rather than model computation efficiency. However, the autonomous driving system is often based on embedded devices, where computing and storage resources are relatively limited. In this paper we describe several light-weight networks based on MobileNetV2, ShuffleNet and Mixed-scale DenseNet for semantic image segmentation task, Additionally, we introduce GAN for data augmentation[17] (pix2pixHD) concurrent Spatial-Channel Sequeeze & Excitation (SCSE) and Receptive Field Block (RFB) to the proposed network. We measure our performance on Cityscapes pixel-level segmentation, and achieve up to 70.72% class mIoU and 88.27% cat. mIoU. We evaluate the trade-offs between mIoU, and number of operations measured by multiply-add (MAdd), as well as the number of parameters.

Network Architecture

Usage

Dependencies

Train

As an example, use the following command to train a LightNet on Cityscapes or Mapillary Vistas Dataset:

> python3 train_mobile.py
> python3 train_mobile_mvd.py 
> python3 train_share.py 
> python3 train_mixscale.py 
> python3 train_shuffle.py 
> python3 train_inplace.py 

Evaluation

We take the Cityscapes model trained above as an example.

To evaluate the trained model:

> python3 deploy_model.py
> python3 evaluation_cityscapes.py
> python3 demo_cityscapes.py

Other Options

We also include Mixed-scale DenseNet/RF-Mixed-scale DenseNet, ShuffleNetPlus/RFShuffleNetPlus, SE-DPShuffleNet, SE-Wide-ResNetV2 implementation in this repository.

Results

Mixed-scale DenseNet/RF-Mixed-scale DenseNet, ShuffleNetPlus/RFShuffleNetPlus, SE-DPShuffleNet, SE-Wide-ResNetV2 under-training (Ask a friend for help)

Results on Cityscapes (Pixel-level/Semantic Segmentation)

Model GFLOPs Params gtFine/gtCoarse/GAN mIoU Classes(val./test S.S*) mIoU Cat.(val./test S.S*) Result(*.cvs) Pytorch Model&Checkpoint
MobileNetV2Plus 117.1? 8.3M Yes/No/No 70.13/68.90 87.95/86.85 GoogleDrive /
MobileNetV2SDASPP ? ?M Yes/No/Yes 73.17/70.09 87.98/87.84 GoogleDrive GoogleDrive
MobileNetV2Plus 117.1? 8.3M Yes/No/Yes 73.89/70.72 88.72/87.64 GoogleDrive GoogleDrive
RF-MobileNetV2Plus 87.6? 8.6M Yes/No/Yes 72.37/70.68 88.31/88.27 GoogleDrive GoogleDrive
ShuffleNetPlus 229.3? 15.3M Yes/No/Yes * * * *
Mixed-scale DenseNet 49.9? 0.80M Yes/No/Yes * * * *
SE-WResNetV2 ? ?M Yes/No/No 80.13/77.15 90.87/90.59 GoogleDrive /
  • S.S.: Single Scale

Contact

[email protected]
[email protected]

Any discussions or concerns are welcomed!

References

[1]. Inverted Residuals and Linear Bottlenecks: Mobile Networks for Classification, Detection and Segmentation
[2]. Rethinking Atrous Convolution for Semantic Image Segmentation
[3]. Encoder-Decoder with Atrous Separable Convolution for Semantic Image Segmentation
[4]. In-Place Activated BatchNorm for Memory-Optimized Training of DNNs
[5]. Receptive Field Block Net for Accurate and Fast Object Detection
[6]. Concurrent Spatial and Channel Squeeze & Excitation in Fully Convolutional Networks
[7]. Squeeze-and-Excitation Networks
[8]. MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications
[9]. ShuffleNet: An Extremely Efficient Convolutional Neural Network for Mobile Devices
[10]. Averaging Weights Leads to Wider Optima and Better Generalization
[11]. A mixed-scale dense convolutional neural network for image analysis
[12]. Dual Path Networks
[13]. Wide Residual Networks
[14]. Densely Connected Convolutional Networks
[15]. CondenseNet: An Efficient DenseNet using Learned Group Convolutions
[16]. Full-Resolution Residual Networks for Semantic Segmentation in Street Scenes
[17]. High-Resolution Image Synthesis and Semantic Manipulation with Conditional GANs
[18]. SGDR: Stochastic Gradient Descent with Warm Restarts
[19]. Cyclical Learning Rates for Training Neural Networks
[20]. Group Normalization
[21]. Context Encoding for Semantic Segmentation
[22]. ExFuse: Enhancing Feature Fusion for Semantic Segmentation
[23]. The Lovász-Softmax loss: A tractable surrogate for the optimization of the intersection-over-union measure in neural networks
[24]. Vortex Pooling: Improving Context Representation in Semantic Segmentation

Acknowledgement

[0]. Lukas Zhang: Lend me GPUs.
[1]. meetshah1995: pytorch-semseg.
[2]. ruinmessi: RFBNet.
[3]. Jackson Huang: ShuffleNet.
[4]. Ji Lin: pytorch-mobilenet-v2.
[5]. ericsun99: MobileNet-V2-Pytorch.
[6]. Ross Wightman: pytorch-dpn-pretrained.
[7]. mapillary: inplace_abn.
[8]. Cadene: pretrained-models.pytorch.
[9]. Maxim Berman: LovaszSoftmax.

lightnet's People

Contributors

ansleliu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lightnet's Issues

ImageNet prtrained weights

@ansleliu , thanks for your nice work, but I am a little confused with your image pre-processing.
dd
ddd
Which kind of ImageNet pretrained weights are you using for mobinenet, since the img pre-processing is different from those pre-weights provided by caffe and pytorch?

Upgrade cffi to CppExtension in pytorch 1.0

Just for enchancement, this repo are helpful for build realtime segmentation applications, but now that Pytorch official has been depracted cffi, would that be a good idea to upgrade into CppExtenstion under modules cuda and cpp files?

The network can not be convergent

I feel very confused. I use the train_mobile.py to train the model with out pre-trained on the cityscapes dataset. I can only get the mIoU of 30~40. How can we get the mIoU of 70? How many epochs ?

Mapillary vistas dataset

I want to use the vistas dataset for semantic segmentation training, but the official provide labelids images with only instance segmentation, and no labelids images with semantic segmentation. What should I do?

mobilenetv2exfuse problem

in LightNet-master\models\mobilenetv2exfuse.py

line 184: if self.traval == "train" and self.n_class != 0:
line 208: elif self.traval == "train" and self.n_class != 0:

why a repetition?
Thanks for reply!

How to train with my own dataset?

Hello, I wonder if I can use my own dataset to train on these networks? And is there any limitation about the objects' classes? For example, some housewares. If the segmentation task on them can be done, could you please tell me the pipeline? I have no idea how to organize my data into a proper form to fit in the code. Thanks a lot!

how about SE-WResNetV2?

hi,I have trained SE-WResNetV2 about 100 epochs, i get mIOU=0.756, it is far away from 0.8013 mIOU which you've get and share, en , i want to known there is some tricks about train SE-WResNetV2? And how to get the same mIOU with you?

network model mobilenetplus

I don't know what that means. Can you elaborate on the specific function of this piece? Why use the 3x3 convolution kernel?

self.score = nn.Sequential(OrderedDict([("norm.1", norm_act(out_sec + in_stag2_up_chs)),
("conv.1", nn.Conv2d(out_sec + in_stag2_up_chs,
out_sec + in_stag2_up_chs,
kernel_size=3, stride=1, padding=2,
dilation=2, bias=False)),
("norm.2", norm_act(out_sec + in_stag2_up_chs)),
("conv.2", nn.Conv2d(out_sec + in_stag2_up_chs, self.n_class,
kernel_size=1, stride=1, padding=0,
bias=True)),
("up1", nn.Upsample(size=in_size, mode='bilinear'))]))

About pytorch encoding and the training speed

Hi,
Thank you for your great work! I am trying to do some distillation work on the small mobile net. I have some questions:
The code need the package pytorch encoding, but the pytorch encoding requires the pytorch to be 0.5.0. Your code is about pytorch 0.3.0+. I wonder how do you install the package of pytorch encoding?

However, the code can run under pytorch 0.5.0, but the training speed is very slow. I used a single P100 to have a try, and it need nearly 7 minutes to finish one epoch. If we need to train 10000 epochs, it will take nearly 48 days.
Is this because the different pytorch version?

Thanks,
Yifan

Train error with no CUDA-capable device is detected

I have build pytorch from source with CUDA 8 and cudnn 7 and installed pytroch-Encoding succesfully.
But when I try to train the model, it shows the following error.

➜ LightNet git:(master) ✗ python scripts/train_mobile.py

+++++++++++++++++++++++++++++++++++++++++++++++++++++++

  1. Setting up DataLoader...

+++++++++++++++++++++++++++++++++++++++++++++++++++++++

Found 2975 train images...
Found 500 val images...

+++++++++++++++++++++++++++++++++++++++++++++++++++++++

  1. Setting up Model...
    THCudaCheck FAIL file=/home/kenzhang/pytorch/aten/src/THC/THCGeneral.cpp line=70 error=38 : no CUDA-capable device is detected
    Traceback (most recent call last):
    File "scripts/train_mobile.py", line 372, in
    train(train_args, data_path, save_path)
    File "scripts/train_mobile.py", line 75, in train
    model = torch.nn.DataParallel(model, device_ids=[0, 1]).cuda()
    File "/opt/miniconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 230, in cuda
    return self._apply(lambda t: t.cuda(device))
    File "/opt/miniconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 152, in _apply
    module._apply(fn)
    File "/opt/miniconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 152, in _apply
    module._apply(fn)
    File "/opt/miniconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 152, in _apply
    module._apply(fn)
    File "/opt/miniconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 158, in _apply
    param.data = fn(param.data)
    File "/opt/miniconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 230, in
    return self._apply(lambda t: t.cuda(device))
    RuntimeError: cuda runtime error (38) : no CUDA-capable device is detected at /home/kenzhang/pytorch/aten/src/THC/THCGeneral.cpp:70

Train and Dataset issue

May I ask how to train model with both gtFine and gtCoarse dataset? And another question, how to get the model mIOU when test on val dataset?Thank you !

torch.FatalError: function_attributes(): after cudaFuncGetAttributes: invalid device function

The following error occurred when I ran the train_mobile_mvd:
/workfs/lhhuang/anaconda3/envs/pytorch0.3/lib/python3.6/site-packages/torch/cuda/init.py:95: UserWarning:
Found GPU0 Tesla V100-SXM2-16GB which requires CUDA_VERSION >= 9000 for
optimal performance and fast startup time, but your PyTorch was compiled
with CUDA_VERSION 8000. Please install the correct PyTorch binary
using instructions from http://pytorch.org

warnings.warn(incorrect_binary_warn % (d, name, 9000, CUDA_VERSION))
^M 0%| | 0/9000 [00:00<?, ?it/s]['/workfs/lhhuang/segment/LightNet-master2/LightNet-master/scripts', '/workfs/lhhuang/segment/LightNet-master2/LightNet-master/scripts', '/dat01/lhhuang/models/research', '/dat01/lhhuang/models/research/slim', '/dat01/lhhuang/models/research/delf', '/workfs/lhhuang/anaconda3/envs/pytorch0.3/lib/python36.zip', '/workfs/lhhuang/anaconda3/envs/pytorch0.3/lib/python3.6', '/workfs/lhhuang/anaconda3/envs/pytorch0.3/lib/python3.6/lib-dynload', '/home/lhhuang/.local/lib/python3.6/site-packages', '/workfs/lhhuang/anaconda3/envs/pytorch0.3/lib/python3.6/site-packages', '/workfs/lhhuang/segment/LightNet-master2/LightNet-master/datasets', '/workfs/lhhuang/segment/LightNet-master2/LightNet-master']

+++++++++++++++++++++++++++++++++++++++++++++++++++++++

  1. Setting up DataLoader...

+++++++++++++++++++++++++++++++++++++++++++++++++++++++

There are 66 labels in the config file
Found 18000 training images...
There are 66 labels in the config file
Found 2000 validation images...

+++++++++++++++++++++++++++++++++++++++++++++++++++++++

  1. Setting up Model...
  2. Model Training start...
    ^M 0%| | 1/9000 [00:04<12:23:13, 4.96s/it]^M> Epoch [1/256]: 0%| | 1/9000 [00:04<12:23:13, 4.96s/it]Traceback (most recent call last):
    File "train_mobile_mvd.py", line 348, in
    train(train_args, data_path, save_path)
    File "train_mobile_mvd.py", line 185, in train
    out_stg1, out_stg2, out_stg3 = model(images) # Here we have 3 output for 3 loss
    File "/workfs/lhhuang/anaconda3/envs/pytorch0.3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 357, in call
    result = self.forward(*input, **kwargs)
    File "/workfs/lhhuang/segment/LightNet-master2/LightNet-master/models/mobilenetv2plus.py", line 169, in forward
    de_stg1 = self.aspp(stg8)[1]
    File "/workfs/lhhuang/anaconda3/envs/pytorch0.3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 357, in call
    result = self.forward(*input, **kwargs)
    File "/workfs/lhhuang/anaconda3/envs/pytorch0.3/lib/python3.6/site-packages/torch/nn/modules/container.py", line 67, in forward
    input = module(input)
    File "/workfs/lhhuang/anaconda3/envs/pytorch0.3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 357, in call
    result = self.forward(*input, **kwargs)
    File "/workfs/lhhuang/segment/LightNet-master2/LightNet-master/modules/misc.py", line 334, in forward
    x = self.in_norm(x)
    File "/workfs/lhhuang/anaconda3/envs/pytorch0.3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 357, in call
    result = self.forward(*input, **kwargs)
    File "/workfs/lhhuang/segment/LightNet-master2/LightNet-master/modules/bn.py", line 96, in forward
    self.activation, self.slope)
    File "/workfs/lhhuang/segment/LightNet-master2/LightNet-master/modules/functions.py", line 97, in forward
    _act_forward(ctx, x)
    File "/workfs/lhhuang/segment/LightNet-master2/LightNet-master/modules/functions.py", line 41, in _act_forward
    _ext.leaky_relu_cuda(x, ctx.slope)
    File "/workfs/lhhuang/anaconda3/envs/pytorch0.3/lib/python3.6/site-packages/torch/utils/ffi/init.py", line 180, in safe_call
    result = torch._C._safe_call(*args, **kwargs)
    torch.FatalError: function_attributes(): after cudaFuncGetAttributes: invalid device function

Hei

sofa, nice job

How to train SE-WResNetV2?

I got some errors like:

RuntimeError: cuda runtime error (2) : out of memory

How to solve this problem?

Thanks

Question about the pretrained RFMobilenetV2Plus model.

Excuse me but, I'd like to ask about the RFMobilenetV2Plus pretrained model. When will you upload those pretrained model (either pretrained on imagenet or cityscape)?
I didnt's find any clue in your README.md
Thanks.

ModuleNotFoundError

File "c:\Users\Administrator\Desktop\LightNet-master\modules_ext_init_.py", line 2, in
from .__ext import lib as _lib, ffi as _ffi
ModuleNotFoundError: No module named 'modules._ext.__ext'

I can not find " .__ext" in your project
can you upload it?

NoMoudle named encoding

Hello Authors,

I am encountering this issue, and am not able to solve this.

Traceback (most recent call last): File "scripts/train_mobile_scannet.py", line 22, in <module> from models.rfmobilenetv2plus import RFMobileNetV2Plus File "/nfs/home/us000146/LightNet/models/rfmobilenetv2plus.py", line 6, in <module> from modules import SCSEBlock, InPlaceABN, InPlaceABNWrapper, RFBlock File "/nfs/home/us000146/LightNet/modules/__init__.py", line 4, in <module> from . context_encode import ContextEncodeInplaceABN, ContextEncodeDropInplaceABN File "/nfs/home/us000146/LightNet/modules/context_encode.py", line 4, in <module> import encoding ModuleNotFoundError: No module named 'encoding'

I am running under the following configuration:

Python 3.6.13
GCC 7.3.0 [on linux]
Torch 0.4.1.post2

I have tried a few things but nothing works out and I am stuck here, without being able to train the model. Please suggest what should I do?

Regards,
Nitin Bansal

something wrong

warnings.warn(ABI_INCOMPATIBILITY_WARNING.format(compiler))

+++++++++++++++++++++++++++++++++++++++++++++++++++++++

  1. Setting up DataLoader...

+++++++++++++++++++++++++++++++++++++++++++++++++++++++

Found 8925 train images...
Found 1500 val images...

+++++++++++++++++++++++++++++++++++++++++++++++++++++++

  1. Setting up Model...
    THCudaCheck FAIL file=/pytorch/aten/src/THC/THCGeneral.cpp line=74 error=30 : unknown error
    Traceback (most recent call last):
    File "train_mobile.py", line 374, in
    train(train_args, data_path, save_path)
    File "train_mobile.py", line 77, in train
    model = torch.nn.DataParallel(model, device_ids=[0,1]).cuda()
    File "/home/dl/anaconda2/envs/test_py3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 258, in cuda
    return self._apply(lambda t: t.cuda(device))
    File "/home/dl/anaconda2/envs/test_py3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 185, in _apply
    module._apply(fn)
    File "/home/dl/anaconda2/envs/test_py3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 185, in _apply
    module._apply(fn)
    File "/home/dl/anaconda2/envs/test_py3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 185, in _apply
    module._apply(fn)
    File "/home/dl/anaconda2/envs/test_py3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 191, in _apply
    param.data = fn(param.data)
    File "/home/dl/anaconda2/envs/test_py3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 258, in
    return self._apply(lambda t: t.cuda(device))

i don't know what to do ...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.