Code Monkey home page Code Monkey logo

deeplab-v3's Introduction

DeepLab V3

Lei Mao, Shengjie Lin

University of Chicago

Toyota Technological Institute at Chicago

Introduction

DeepLab is a series of image semantic segmentation models, whose latest version, i.e. v3+, proves to be the state-of-art. Its major contribution is the use of atrous spatial pyramid pooling (ASPP) operation at the end of the encoder. While the model works extremely well, its open source code is hard to read (at least from my personal perspective). Here we re-implemented DeepLab V3, the earlier version of v3+ (which only additionally employs the decoder architecture), in a much simpler and more understandable way.

Dependencies

  • Python 3.5
  • TensorFlow 1.8
  • Tqdm 4.26.0
  • Numpy 1.14
  • OpenCV 3.4.3
  • Pillow 5.3.0

Files

.
├── archieved
├── download.py
├── feature_extractor.py
├── LICENSE.md
├── model.py
├── modules.py
├── nets
├── README.md
├── test_demo.py
├── test_any_image.py
├── train.py
└── utils.py

The nets directory contains network definition files that are directly copied from tensorflow/models/research/slim/nets

Usages

Install Dependencies

To install dependencies, please run the following command to install everything required automatically:

$ chmod +x install_dependencies.sh
$ pip install -r requirements.txt
$ ./install_dependencies.sh

If found permission problems, please run the following command instead:

$ chmod +x install_dependencies.sh
$ pip install -r requirements.txt
$ sudo ./install_dependencies.sh

Download Dataset

Download and extract VOC2012 dataset, SBD dataset, and pretrained models to designated directories.

$ python download.py --help
usage: download.py [-h] [--downloads_dir DOWNLOADS_DIR] [--data_dir DATA_DIR]
                   [--pretrained_models_dir PRETRAINED_MODELS_DIR]
                   [--pretrained_models PRETRAINED_MODELS [PRETRAINED_MODELS ...]]

Download DeepLab semantic segmentation datasets and pretrained backbone
models.

optional arguments:
  -h, --help            show this help message and exit
  --downloads_dir DOWNLOADS_DIR
                        Downloads directory
  --data_dir DATA_DIR   Data directory
  --pretrained_models_dir PRETRAINED_MODELS_DIR
                        Pretrained models directory
  --pretrained_models PRETRAINED_MODELS [PRETRAINED_MODELS ...]
                        Pretrained models to download: resnet_50, resnet_101,
                        mobilenet_1.0_224

For example, to download and extract datasets and models into directories specified:

$ python download.py --downloads_dir ./downloads --data_dir ./data --pretrained_models_dir ./models/pretrained --pretrained_models resnet_50 resnet_101 mobilenet_1.0_224

For simplicity, please just run the following command in terminal:

$ python download.py

Train Model

$ python train.py --help
usage: train.py [-h] [--network_backbone NETWORK_BACKBONE]
                [--pre_trained_model PRE_TRAINED_MODEL]
                [--trainset_filename TRAINSET_FILENAME]
                [--valset_filename VALSET_FILENAME] [--images_dir IMAGES_DIR]
                [--labels_dir LABELS_DIR]
                [--trainset_augmented_filename TRAINSET_AUGMENTED_FILENAME]
                [--images_augmented_dir IMAGES_AUGMENTED_DIR]
                [--labels_augmented_dir LABELS_AUGMENTED_DIR]
                [--model_dir MODEL_DIR] [--log_dir LOG_DIR]
                [--random_seed RANDOM_SEED]

Train DeepLab V3 for image semantic segmantation.

optional arguments:
  -h, --help            show this help message and exit
  --network_backbone NETWORK_BACKBONE
                        Network backbones: resnet_50, resnet_101,
                        mobilenet_1.0_224. Default: resnet_101
  --pre_trained_model PRE_TRAINED_MODEL
                        Pretrained model directory
  --trainset_filename TRAINSET_FILENAME
                        Train dataset filename
  --valset_filename VALSET_FILENAME
                        Validation dataset filename
  --images_dir IMAGES_DIR
                        Images directory
  --labels_dir LABELS_DIR
                        Labels directory
  --trainset_augmented_filename TRAINSET_AUGMENTED_FILENAME
                        Train augmented dataset filename
  --images_augmented_dir IMAGES_AUGMENTED_DIR
                        Images augmented directory
  --labels_augmented_dir LABELS_AUGMENTED_DIR
                        Labels augmented directory
  --model_dir MODEL_DIR
                        Trained model saving directory
  --log_dir LOG_DIR     TensorBoard log directory
  --random_seed RANDOM_SEED
                        Random seed for model training.

For simplicity, please run the following command in terminal:

$ python train.py

With learning rate of 1e-5, the mIOU could be greater 0.7 after 20 epochs, which is comparable to the test statistics of DeepLab V3 in the publication.

Demos

To show some demos, please run the following command in terminal:

$ python test_demo.py
Image Label Prediction
Image Label Prediction
Image Label Prediction
Image Label Prediction

Custom Demo

Just put some JPG-format images into demo_dir and run the following command in the terminal.

$ python test_any_image.py

Results will be written into same folder. Make sure that proper model trained and a checkpoint is saved in models_dir. See the script for details.

Contributed by pinaxe1. Will modify to accept arguments and multiple image formats.

References

L.-C. Chen, G. Papandreou, I. Kokkinos, K. Murphy, and A. L. Yuille. Deeplab: Semantic Image Segmentation with Deep Convolutional Nets, Atrous Convolution, and Fully Connected CRFs. TPAMI, 2017.

L.-C. Chen, G. Papandreou, F. Schroff, and H. Adam. Rethinking Atrous Convolution for Semantic Image Segmentation. arXiv:1706.05587, 2017.

L.-C. Chen, Y. Zhu, G. Papandreou, F. Schroff, H. Adam. Encoder-Decoder with Atrous Separable Convolution for Semantic Image Segmentation. arXiv:1802.02611, 2018.

To-Do List

  • Test script for new arbitrary test images.

deeplab-v3's People

Contributors

leimao avatar pinaxe1 avatar shengjie-lin 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

deeplab-v3's Issues

module 'tensorflow' has no attribute 'contrib'

Traceback (most recent call last):
File "train.py", line 8, in
from model import DeepLab
File "C:\Users\DGRE\DeepLab-V3\model.py", line 6, in
from feature_extractor import MobileNet, Resnet, Vgg16
File "C:\Users\DGRE\DeepLab-V3\feature_extractor.py", line 2, in
from nets import resnet_v2
File "C:\Users\DGRE\DeepLab-V3\nets\resnet_v2.py", line 55, in
from nets import resnet_utils
File "C:\Users\DGRE\DeepLab-V3\nets\resnet_utils.py", line 43, in
slim = tf.contrib.slim
AttributeError: module 'tensorflow' has no attribute 'contrib'

How to test on arbitrary images?

Hello. Newbie enthusiast here. I was just wondering if you could give a rough idea on how to test a pretrained model with random images so I can write the script on my own. Thanks!

AttributeError: module 'tensorflow' has no attribute 'contrib'

followed the instruction for installation but bumped into this error when running train.py

$ python3 train.py
2021-02-19 23:20:37.098330: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory
2021-02-19 23:20:37.098358: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Traceback (most recent call last):
  File "train.py", line 8, in <module>
    from model import DeepLab
  File ".../DeepLab-V3/model.py", line 6, in <module>
    from feature_extractor import MobileNet, Resnet, Vgg16
  File ".../DeepLab-V3/feature_extractor.py", line 2, in <module>
    from nets import resnet_v2
  File ".../DeepLab-V3/nets/resnet_v2.py", line 55, in <module>
    from nets import resnet_utils
  File ".../DeepLab-V3/nets/resnet_utils.py", line 43, in <module>
    slim = tf.contrib.slim
AttributeError: module 'tensorflow' has no attribute 'contrib'

I found some possible solutions here but couldn't figure it out..

Error In testing test_demo.py

I got the Following Error while testing

D:\Ragavendranbala\Image Processing\DeepLab_v3-master>python test_demo.py
Calculating pixel means for each channel of images...
0it [00:00, ?it/s]Traceback (most recent call last):
File "test_demo.py", line 20, in
channel_means = save_load_means(means_filename='channel_means.npz', image_filenames=None)
File "D:\Ragavendranbala\Image Processing\DeepLab_v3-master\utils.py", line 45, in save_load_means
channel_means = image_channel_means(image_filenames=image_filenames)
File "D:\Ragavendranbala\Image Processing\DeepLab_v3-master\utils.py", line 24, in image_channel_means
for image_filename in tqdm(image_filenames):
File "C:\Users\ragav\AppData\Local\Programs\Python\Python35\lib\site-packages\tqdm_tqdm.py", line 937, in iter
for obj in iterable:
TypeError: 'NoneType' object is not iterable

D:\Ragavendranbala\Image Processing\DeepLab_v3-master>

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.