Skip to content

yubaoliu/semseg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

System Environment

Linux ubuntu 16.04

$ uname -a
Linux yubao-Z370M-S01 4.15.0-51-generic #55~16.04.1-Ubuntu SMP Thu May 16 09:24:37 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

Cuda

10.0

cuDNN

v7.6.1+cuda 10.0

Python

2.7

External Files

Weights

Python pacages

Refer SegNet/requirements.txt

Reference

Build caffe

Dependences

CUDA

library version 7+ and the latest driver version are recommended, but 6.* is fine too 5.5, and 5.0 are compatible but considered legacy

Check current cuda version:

nvidia-smi

cuDNN

  • cuDNN for GPU acceleration (v6)
  • download: https://developer.nvidia.com/rdp/cudnn-download
    • Download cuDNN v7.6.1 (June 24, 2019), for CUDA 10.1
    • Download cuDNN v7.6.1 (June 24, 2019), for CUDA 10.0
    • Download cuDNN v7.6.1 (June 24, 2019), for CUDA 9.2
    • Download cuDNN v7.6.1 (June 24, 2019), for CUDA 9.0
# cuDNN Runtime Library for Ubuntu16.04 (Deb)
wget -c https://developer.nvidia.com/compute/machine-learning/cudnn/secure/v7.6.1.34/prod/10.0_20190620/Ubuntu16_04-x64/libcudnn7_7.6.1.34-1%2Bcuda10.0_amd64.deb
# cuDNN Developer Library for Ubuntu16.04 (Deb)
wget -c 
https://developer.nvidia.com/compute/machine-learning/cudnn/secure/v7.6.1.34/prod/10.0_20190620/Ubuntu16_04-x64/libcudnn7-dev_7.6.1.34-1%2Bcuda10.0_amd64.deb
# cuDNN Code Samples and User Guide for Ubuntu16.04 (Deb)
https://developer.nvidia.com/compute/machine-learning/cudnn/secure/v7.6.1.34/prod/10.0_20190620/Ubuntu16_04-x64/libcudnn7-doc_7.6.1.34-1%2Bcuda10.0_amd64.deb
  • Remove previous version
sudo dpkg -r libcudnn7 libcudnn7-dev
  • Install using dpkg
sudo dpkg -i <new-cudnn-runtime>.deb
sudo dpkg -i <new-cudnn-dev>.deb
sudo ldconfig

My cuda version is 10.0 so I should install v7.61 for CUDA 10.0

  • avoid auto upgrade when run apt upgrade [very important]
sudo apt-mark hold libcudnn7 libcudnn7-dev

I’m using version 7 + cuda 10 Check current cudnn version

$ cat /usr/include/cudnn.h | grep CUDNN_MAJOR -A 2
#define CUDNN_MAJOR 7

compile caffe and install

cd caffe
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=<INSTALL_PATH> ..
make all
make install
make runtest

Config python path

export PYTHONPATH=<CAFFE_PATH>/python:$PYTHONPATH

Install caffe using conda

I have not yet tried this method Create ‘caffe’ virtual environment

conda create -n caffe_gpu -c defaults python=3.6 caffe-gpu

Test python caffe

$ python
Python 2.7.12 (default, Nov 12 2018, 14:36:49)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import caffe
>>> exit()

SegNet: SegNet-Tutorial

Official: SegNet-Tutorial

Structure

$ tree -L 1
├── caffe-segnet
├── CamVid
├── docker
├── Example_Models
├── Models
├── README.md
├── requirement.txt
└── Scripts

Build caffe-segnet

mkdir build
cd build
cmake ..
make
make install

Getting Started with Live Demo

First open Scripts/webcam_demo.py and edit line 14 to match the path to your installation of SegNet.

python Scripts/webcam_demo.py --model Example_Models/segnet_model_driving_webdemo.prototxt --weights /Example_Models/segnet_weights_driving_webdemo.caffemodel --colours /Scripts/camvid12.png

Setting Up Caffe and the Dataset

Modify path of

  • CamVid/test.txt
  • CamVid/train.txt

vim:

:%s#SegNet#home/yubao/data/Project/semseg/SegNet-Tutorial-alexgkendall#g
  1. Modify file path in:
    • Models/segnet_train.prototxt
7   dense_image_data_param {
8     source: "/home/yubao/Project/semseg/SegNet-Tutorial-alexgkendall/CamVid/train.txt"  # Change this to the absolute      path to your data file
9     batch_size: 4               # Change this number to a batch size that will fit on your GPU
  • Models/segnet_inference.prototxt
  • Models/segnet_solver.prototxt
  1. Create a folder to store your training weights and solver details with mkdir /SegNet/Models/Training

SegNet

Training CamVid using SegNet-basic

Dataset

CamVid dataset contains 367 training and 233 testing images of road scenes.

Training

./SegNet/caffe-segnet/build/tools/caffe train -gpu 0 -solver /SegNet/Models/segnet_solver.prototxt  # This will begin training SegNet on GPU 0
./SegNet/caffe-segnet/build/tools/caffe train -gpu 0 -solver ./SegNet/Models/segnet_basic_solver.prototxt  # This will begin training SegNet-Basic on GPU 0
./SegNet/caffe-segnet/build/tools/caffe train -gpu 0 -solver ./SegNet/Models/segnet_solver.prototxt -weights /SegNet/Models/VGG_ILSVRC_16_layers.caffemodel  # This will begin training SegNet on GPU 0 with a pretrained encoder

Testing

python /Segnet/Scripts/compute_bn_statistics.py /SegNet/Models/segnet_train.prototxt /SegNet/Models/Training/segnet_iter_10000.caffemodel /Segnet/Models/Inference/  # compute BN statistics for SegNet
python /Segnet/Scripts/compute_bn_statistics.py /SegNet/Models/segnet_basic_train.prototxt /SegNet/Models/Training/segnet_basic_iter_10000.caffemodel /Segnet/Models/Inference/  # compute BN statistics for SegNet-Basic

Result of basics

images/SegNet/test_1_2019-06-30_15-28-30.png

images/SegNet/test_1_res1_2019-06-30_15-29-14.png

images/SegNet/test_1_res2_2019-06-30_15-29-18.png

Training Pascal VOC

Dataset

Pascal VOC

Training

Testing

Result

I0630 21:12:15.934836  5739 sgd_solver.cpp:112] Iteration 599, lr = 0.0001
I0630 21:12:17.073256  5739 solver.cpp:239] Iteration 600 (0.878424 iter/s, 1.1384s/1 iters), loss = 1.95768
I0630 21:12:17.073312  5739 solver.cpp:258]     Train net output #0: loss = 1.8794 (* 1 = 1.8794 loss)
I0630 21:12:17.073334  5739 sgd_solver.cpp:112] Iteration 600, lr = 0.0001
itt:600 accuracy:0.9596
Baseline accuracy:0.9240

Possible Errors

ImportError: No module named caffe

t$ python Scripts/compute_bn_statistics.py Example_Models/segnet_pascal.prototxt Example_Models/segnet_pascal.caffemodel Models/Inference/
Traceback (most recent call last):
  File "Scripts/compute_bn_statistics.py", line 14, in <module>
    import caffe
ImportError: No module named caffe

Solution:

export PYTHONPATH=<CAFFE_PATH>/python:$PYTHONPATH
eg:
 export PYTHONPATH=/home/yubao/data/Project/semseg/SegNet/caffe-segnet/build/install/python:$PYTHONPATH

If still not work, check relative files. For example:

Scripts/compute_bn_statistics.py

9
10 caffe_root = '/home/yubao/data/Project/semseg/SegNet/caffe-segnet/build/install/python'          # Change this to the absolute     directory to SegNet Caffe

Cudnn error when compile caffe-segnet-cudnn5

Error message:

(caffe_gpu) yubao@yubao-Z370M-S01:~/data/Project/semseg/caffe-segnet-cudnn5-TimoSaemann/build$ make
Scanning dependencies of target proto
[  0%] Building CXX object src/caffe/CMakeFiles/proto.dir/__/__/include/caffe/proto/caffe.pb.cc.o
[  0%] Linking CXX static library ../../lib/libproto.a
[  1%] Built target proto
[  1%] Building NVCC (Device) object src/caffe/CMakeFiles/cuda_compile_1.dir/layers/cuda_compile_1_generated_absval_layer.cu.o
/home/yubao/data/Project/semseg/caffe-segnet-cudnn5-TimoSaemann/include/caffe/util/cudnn.hpp(112): error: too few arguments in function call

1 error detected in the compilation of "/tmp/tmpxft_000074ef_00000000-4_absval_layer.cpp4.ii".
CMake Error at cuda_compile_1_generated_absval_layer.cu.o.Release.cmake:279 (message):
  Error generating file
  /home/yubao/data/Project/semseg/caffe-segnet-cudnn5-TimoSaemann/build/src/caffe/CMakeFiles/cuda_compile_1.dir/layers/./cuda_compile_1_generated_absval_layer.cu.o


src/caffe/CMakeFiles/caffe.dir/build.make:499: recipe for target 'src/caffe/CMakeFiles/cuda_compile_1.dir/layers/cuda_compile_1_generated_absval_layer.cu.o' failed
make[2]: *** [src/caffe/CMakeFiles/cuda_compile_1.dir/layers/cuda_compile_1_generated_absval_layer.cu.o] Error 1
CMakeFiles/Makefile2:271: recipe for target 'src/caffe/CMakeFiles/caffe.dir/all' failed
make[1]: *** [src/caffe/CMakeFiles/caffe.dir/all] Error 2
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2

Solution:

It’s happening due to cudnn.hpp (Location: include/caffe/util/cudnn.hpp) . Update cudnn.hpp file. It is not considering the current cuDNN versions.

Update the cudnn.hpp from github repo, BVLC/caffe/include/caffe/util/cudnn.hpp Or, go to this link https://github.com/BVLC/caffe/blob/master/include/caffe/util/cudnn.hpp [Copy this and replace the old one]

  • Python Caffe: Python 2.7 or Python 3.3+, numpy (>= 1.7), boost-provided boost.python
  • MATLAB Caffe: MATLAB with the mex compiler

cudnn error when testing neuron network

yubao@yubao-Z370M-S01:~/data/Project/semseg/caffe$ ./build/examples/cpp_classification/classification.bin ./models/bvlc_reference_caffenet/deploy.prototxt ./models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel ./data/ilsvrc12/imagenet_mean.binaryproto ./data/ilsvrc12/synset_words.txt ./examples/images/cat.jpg
F0630 09:11:41.399860 17359 cudnn_conv_layer.cpp:53] Check failed: status == CUDNN_STATUS_SUCCESS (1 vs. 0)  CUDNN_STATUS_NOT_INITIALIZED
Check failure stack trace: ***
    @     0x7fdf7114346d  google::LogMessage::Fail()
    @     0x7fdf71145a23  google::LogMessage::SendToLog()
    @     0x7fdf71142ffb  google::LogMessage::Flush()
    @     0x7fdf7114496e  google::LogMessageFatal::~LogMessageFatal()
    @     0x7fdf7170c0db  caffe::CuDNNConvolutionLayer<>::LayerSetUp()
    @     0x7fdf718293dc  caffe::Net<>::Init()
    @     0x7fdf7182c4a0  caffe::Net<>::Net()
    @           0x4085bb  Classifier::Classifier()
    @           0x4048c3  main
    @     0x7fdf6c775830  __libc_start_main
    @           0x405129  _start
Aborted (core dumped)

Solution:

  1. Check my cuda version via nvidia-smi

cuda 10.0

  1. Check cudnn version
yubao@yubao-Z370M-S01:~/data/Project/semseg/caffe$ dpkg -l | grep cuda |grep dnn
ii  libcudnn7                                                7.6.0.64-1+cuda10.1                                   amd64        cuDNN runtime libraries
ii  libcudnn7-dev                                            7.6.0.64-1+cuda10.1                                   amd64        cuDNN development libraries and headers

It looks like their version is inconsistent.

It is caused by apt-get upgrade

You can use

sudo apt-mark hold libcudnn7 libcudnn7-dev

to avoid auto upgrade.

  1. remove current cudnn

My cudnn directory is here: /usr/lib/x86_64-linux-gnu/libcudnn.so

Remov all related libs

sudo dpkg -r libcudnn7 libcudnn7-dev
  1. Install cuDNN again whith correct version
  2. Finually succeed:
    yubao@yubao-Z370M-S01:~/data/Project/semseg/caffe$ ./build/examples/cpp_classification/classification.bin ./models/bvlc_reference_caffenet/deploy.prototxt ./models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel ./data/ilsvrc12/imagenet_mean.binaryproto ./data/ilsvrc12/synset_words.txt ./examples/images/cat.jpg
    ---------- Prediction for ./examples/images/cat.jpg ----------
    0.3134 - "n02123045 tabby, tabby cat"
    0.2380 - "n02123159 tiger cat"
    0.1235 - "n02124075 Egyptian cat"
    0.1003 - "n02119022 red fox, Vulpes vulpes"
    0.0715 - "n02127052 lynx, catamount"
        
  3. Reference: http://nhoj62003.blogspot.com/2017/10/caffe.html