Deep Learning - Tiziran

Tiziran
Computer Vision
Deep Learning
Go to content

Main menu:

Deep Learning

Farshid Pirahansiah; Computer Vision; Deep Learning; Video analysis; OpenCV 3.2; C++; Ubuntu 16; DIGITS 5; Caffe; Recurrent Neural Networks (RNNs); Long Short Term Memory (LSTM); Gated Recurrent Units (GRU); classify action of human in video; deep learnin

Download from www.tiziran.com/Book_DeepLearning_ComputerVision.html   

Telegram Deep Learning in Computer Vision Group

https://telegram.me/joinchat/CZ8vFgt1Idg8U06TBp5h8g  

Hands-on, Practical, Experiments, Tutorial, Step by Step

Deep Learning in Computer Vision for 2017

Farshid PirahanSiah

 www.pirahansiah.com

 

Contents

Install, compile, setup, configure, build system for deep learning. 3

First: Install Ubuntu. 3

Second: Install NVidia graphic card driver 5

Third: Install CUDA.. 5

Forth: Setup cuDNN.. 6

Fifth: Build Torch. 6

Build Torch7. 6

Setup Torch7. 6

Sixth: Build Caffe. 7

Seventh: Build Digits. 8

Hands-on DIGITS. 9

First: Dataset 10

Example of create database for deep learning in digits. 11

Set the path of dataset in digits for classification. 12

Classification. 14

Setting. 15

Network setting. 16

Process. 17

After first epoch. 18

Download the trained models. 19

Upload pre trained model to digits, how to use. 21

Upload pre trained model to digits, how to use. 21

Upload pre trained model to digits – second way. 25

OpenCV 3.2. 28

YouTube channel 40

Slides. 40

Files and source code (download projects) 40

Group for Deep Learning and Computer Vision. 40

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Install, compile, setup, configure, build system for deep learning 

First: Install Ubuntu

Download and install Ubuntu 16 from http://releases.ubuntu.com/16.04.1/ubuntu-16.04.1-desktop-amd64.iso . Then if you using windows you can download the Rufus USB installer form https://rufus.akeo.ie/downloads/rufus-2.11.exe . By helping the Rufus you can create bootable UBS/Pen Drive/Flash for installing Ubuntu alongside your windows/Mac OS.

Find your Nvidia GPU compute capability which is show the suitable version of CUDA, cuDNN, and driver for your graphic card from https://developer.nvidia.com/cuda-gpus . Table 1 shows several new model of GeForce GTX compute capability.

Table 1. Compute capability of some Nvidia GPU.

GPU

Compute Capability

GeForce GTX 1080

6.1

GeForce GTX 1070

6.1

GeForce GTX 1060

6.1

GeForce GTX 980

5.2

GeForce GTX 980M

5.2

GeForce GTX 970M

5.2

GeForce GTX 965M

5.2

GeForce GTX 960M

5

GeForce GTX 950M

5

GeForce 940M

5

GeForce 930M

5

GeForce 920M

3.5

GeForce 910M

5.2

GeForce GTX 880M

3

GeForce GTX 870M

3

GeForce GTX 860M

3

GeForce GTX 850M

5

 

Also you can find your GPU architecture from https://en.wikipedia.org/wiki/List_of_Nvidia_graphics_processing_units . For example Fermi (GFxxx), Kepler (GKxxx), Maxwell Architecture (GMxxx), Pascal (GPxxx), (except Quadro 400 with Tesla 2).

Based on this information you can find suitable version of driver from https://launchpad.net/~graphics-drivers/+archive/ubuntu/ppa . For example the latest driver which can be install for Maxwell Architecture is 375. Figure 1 shows the image of Nvidia driver for Ubuntu.

Figure 1. Ubuntu driver for Nvidia graphic cards.

Based on this information you can find suitable version of CUDA from https://en.wikipedia.org/wiki/CUDA . For example:

·      CUDA SDK 8.0 support for Compute Capability 2.0 – 6.x (Fermi, Kepler, Maxwell, Pascal)

·      CUDA SDK 7.5 support for Compute Capability 2.0 – 5.x (Fermi, Kepler, Maxwell)

·      CUDA SDK 6.5: Last Version with support for Tesla with Compute Capability 1.x

See the comparison of speed test between different GPU in Deep Learning

https://github.com/jcjohnson/cnn-benchmarks/blob/master/README.md

 

 

 

Second: Install NVidia graphic card driver

Install the graphic card driver in Ubuntu.

1.    Press Alt+Ctrl+F1

2.    Type your username and password

3.    sudo add-apt-repository ppa:graphics-drivers/ppa

4.    sudo apt-get update

5.    sudo apt-get install nvidia-375

6.    sudo reboot

 

Third: Install CUDA

1.    Download CUDA 8

2.    Install CUDA without installing the driver fro GPU

Forth: Setup cuDNN

          https://developer.nvidia.com/cudnn

Fifth: Build Torch

Build Torch7

The instruction can be find in https://github.com/NVIDIA/DIGITS/blob/master/docs/BuildTorch.md

sudo apt-get install --no-install-recommends git software-properties-common

export TORCH_ROOT=~/torch

git clone https://github.com/torch/distro.git $TORCH_ROOT --recursive

cd $TORCH_ROOT

./install-deps

./install.sh -b

source ~/.bashrc

 

sudo apt-get install --no-install-recommends libhdf5-serial-dev liblmdb-dev

luarocks install tds

luarocks install "https://raw.github.com/deepmind/torch-hdf5/master/hdf5-0-0.rockspec"

luarocks install "https://raw.github.com/Neopallium/lua-pb/master/lua-pb-scm-0.rockspec"

luarocks install lightningmdb 0.9.18.1-1 LMDB_INCDIR=/usr/include LMDB_LIBDIR=/usr/lib/x86_64-linux-gnu

 

luarocks install https://raw.githubusercontent.com/ngimel/nccl.torch/master/nccl-scm-1.rockspec

 

Setup Torch7

          export TORCH_ROOT=~/torch

          export PATH=$PATH:~/torch/install/bin

          source ~/.bashrc

Sixth: Build Caffe

 

The instruction can be find in https://github.com/NVIDIA/DIGITS/blob/master/docs/BuildCaffe.md

 

sudo apt-get install --no-install-recommends build-essential cmake git gfortran libatlas-base-dev libboost-all-dev libgflags-dev libgoogle-glog-dev libhdf5-serial-dev libleveldb-dev liblmdb-dev libopencv-dev libprotobuf-dev libsnappy-dev protobuf-compiler python-all-dev python-dev python-h5py python-matplotlib python-numpy python-opencv python-pil python-pip python-protobuf python-scipy python-skimage python-sklearn

 

export CAFFE_ROOT=~/caffe

git clone https://github.com/NVIDIA/caffe.git $CAFFE_ROOT

 

sudo pip install -r $CAFFE_ROOT/python/requirements.txt

                     cat $CAFFE_ROOT/python/requirements.txt | xargs -n1 sudo pip install

cd $CAFFE_ROOT

mkdir build

cd build

cmake ..

make --jobs=4

 

source ~/.bashrc

 

 

Seventh: Build Digits

The instruction can be find in https://github.com/NVIDIA/DIGITS/blob/master/docs/BuildDigits.md

sudo apt-get install --no-install-recommends git graphviz python-dev python-flask python-flaskext.wtf python-gevent python-h5py python-numpy python-pil python-pip python-protobuf python-scipy

DIGITS_ROOT=~/digits

git clone https://github.com/NVIDIA/DIGITS.git $DIGITS_ROOT

sudo pip install -r $DIGITS_ROOT/requirements.txt

sudo pip install -e $DIGITS_ROOT

source ~/.bashrc

 

./digits-devserver –p 7000

Hands-on DIGITS

 

 

 

First: Dataset

 

 

 

 

Example of create database for deep learning in digits

We use 4 objects and put the images for each object into folder with specific label

The more images the better accuracy

Select “Datasets” -> form “New Dataset” on the right select -> “Classification”

In the “Training Images” put the path of your dataset “/home/farshid/Documents/4_ObjectCategories/”

You should see the folders inside. You have at least 2 folders/objects to be classified.

Set the path of dataset in digits for classification 

Set “Group Name”

Set “Dataset Name”

If you want to use “LeNet” you can change the image type to “Grayscale” and change the image size to 28 * 28

 

 

DB created and you can see the Mean of images and number of images for each categories.

In this case the number of images for each categories is around 800 except the last one which is around 400.

If you want good accuracy you have to have much more images for each categories

 

 

 

 

Classification

Click on “DIGITS” top left side of page

Go to Models

Form the “New Model” click on “Images” and select

Setting

Under “New Image Classification Model” select your dataset which is created before

If your GPU has 2 or less memory set the “Batch size” to 1

 

 

Network setting

Form “Standard Networks” select “Caffe” then select any of the standard networks like “LeNet”, AlexNet” or “GoogLeNet”

The fastest on is “LeNet” which use 28 * 28 grayscale images (if your dataset is color or larger it will change automatically for you)

From “Group Name” put your group

For model name put any name you want

Click on “Create

Process

After finishing the “Epoch” 1 you can see first accuracy. It will increase.

You can see memory and GPU usage

You can see CPU and memory usage

If your memory on GPU higher you can set more batch size

After first epoch

You can see

Accuracy (val)

Loss (val)

Loss (train)

Download the trained models

You can download the model and use it.

You can used the trained models in OpenCV 3.2

You can test the trained models with a single image

You can used trained models in pretrained model

Upload pre trained model to digits, how to use

 

Upload pre trained model to digits, how to use

Select “Pretrained Models”

Click on “Images” from “load model”

Click on “Upload Pretrained Model

Put any name on the “Jobname”

Select the caffemodel file

Select the model definition

Select the labels file

Click on upload model

From the “models” select classification

 

 

 

 

 

Select the pre trained model from the pretrained networks tab

Click on “customize”

Change “num_output: 1000” in line 2141 to 4

Change last layer name in line 2154,2131,2128 to new name

 

 

Upload pre trained model to digits – second way

 

Select model based on download trained model

In this case we download GooLeNet model

Click on “customize”

 

Put the path of Caffe model which is download

“Pretrained model(s)”

Must change several things in the model definition

 

 

 

Uncomment the “num_output:1000”

Line

2460

1727

936

If you want faster training change learning rate to 0.0001

Change the batch size

 

OpenCV 3.2

 

       Compile windows 10 (64 bit), Visual Studio 2015, OpenCV + contribute (DNN)

       https://github.com/opencv/opencv

       https://github.com/opencv/opencv_contrib

       Open cmake

       Path of OpenCV source code (OpenCV master)

       Path to build folder (not inside the OpenCV source code folder )

       Click on configure

       Insert the path of OpenCV contribute into “OPENCV_EXTRA_MODULES_PATH”

       C:/opencv32/opencv_contrib-master/modules

       Click on configure again

       Click on  generate

       Open the “OpenCV.sln” file (the OpenCV project in visual studio)

       Build Debug and release based x64

       Build install

 

 

http://docs.opencv.org/master/

Main modules:

core. Core functionality

imgproc. Image processing

imgcodecs. Image file reading and writing

videoio. Video I/O

highgui. High-level GUI

video. Video Analysis

calib3d. Camera Calibration and 3D Reconstruction

features2d. 2D Features Framework

objdetect. Object Detection

ml. Machine Learning

flann. Clustering and Search in Multi-Dimensional Spaces

photo. Computational Photography

stitching. Images stitching

cudaarithm. Operations on Matrices

cudabgsegm. Background Segmentation

cudacodec. Video Encoding/Decoding

cudafeatures2d. Feature Detection and Description

cudafilters. Image Filtering

cudaimgproc. Image Processing

cudalegacy. Legacy support

cudaobjdetect. Object Detection

cudaoptflow. Optical Flow

cudastereo. Stereo Correspondence

cudawarping. Image Warping

cudev. Device layer

shape. Shape Distance and Matching

superres. Super Resolution

videostab. Video Stabilization

viz. 3D Visualizer

Extra modules:

aruco. ArUco Marker Detection

bgsegm. Improved Background-Foreground Segmentation Methods

bioinspired. Biologically inspired vision models and derivated tools

ccalib. Custom Calibration Pattern for 3D reconstruction

cnn_3dobj. 3D object recognition and pose estimation API

cvv. GUI for Interactive Visual Debugging of Computer Vision Programs

datasets. Framework for working with different datasets

dnn. Deep Neural Network module

dpm. Deformable Part-based Models

face. Face Recognition

freetype. Drawing UTF-8 strings with freetype/harfbuzz

fuzzy. Image processing based on fuzzy mathematics

hdf. Hierarchical Data Format I/O routines

line_descriptor. Binary descriptors for lines extracted from an image

matlab. MATLAB Bridge

optflow. Optical Flow Algorithms

phase_unwrapping. Phase Unwrapping API

plot. Plot function for Mat data

reg. Image Registration

rgbd. RGB-Depth Processing

saliency. Saliency API

sfm. Structure From Motion

stereo. Stereo Correspondance Algorithms

structured_light. Structured Light API

surface_matching. Surface Matching

text. Scene Text Detection and Recognition

tracking. Tracking API

xfeatures2d. Extra 2D Features Framework

ximgproc. Extended Image Processing

xobjdetect. Extended object detection

xphoto. Additional photo processing algorithms

 

 

OpenCV version

1999  start project

2006  version 1

2009  version 2

2015  version 3     

December 2016      version 3.2

Include file

core.hpp

imgproc.hpp

video.hpp

highgui.hpp

contrib.hpp

 

 

opencv_aruco320d.lib             

opencv_bgsegm320d.lib

opencv_bioinspired320d.lib       

opencv_calib3d320d.lib

opencv_ccalib320d.lib            

opencv_core320d.lib

opencv_datasets320d.lib          

opencv_dnn320d.lib

opencv_dpm320d.lib               

opencv_face320d.lib

opencv_features2d320d.lib        

opencv_flann320d.lib

opencv_fuzzy320d.lib             

opencv_highgui320d.lib

opencv_imgcodecs320d.lib         

opencv_imgproc320d.lib

opencv_line_descriptor320d.lib   

opencv_ml320d.lib

opencv_objdetect320d.lib         

opencv_optflow320d.lib

opencv_phase_unwrapping320d.lib  

opencv_photo320d.lib

opencv_plot320d.lib              

opencv_reg320d.lib

opencv_rgbd320d.lib              

opencv_saliency320d.lib

opencv_shape320d.lib             

opencv_stereo320d.lib

opencv_stitching320d.lib         

opencv_structured_light320d.lib

opencv_superres320d.lib          

opencv_surface_matching320d.lib

opencv_text320d.lib             

opencv_tracking320d.lib

opencv_video320d.lib             

opencv_videoio320d.lib

opencv_videostab320d.lib         

opencv_xfeatures2d320d.lib

opencv_ximgproc320d.lib          

opencv_xobjdetect320d.lib

opencv_xphoto320d.lib

 

 

#include <opencv2/opencv.hpp>

 

void main(void) {

cv::Mat img = cv::imread("c:\\farshidpirahansiah\\tiziran.png");

cv::imshow("Farshid", img);

cv::waitKey(100);

}

 

 

 

Download the latest version of OpenCV 3.2 (2017) based on Visual Studio 2013, windows 64bit, CUDA 7.5 (GPU-Nvida)

http://wikisend.com/download/247034/OpenCV32VS2013Win7x64Cuda75.rar 

http://wikisend.com/download/560028/OpenCV32Win32VS2015Full.zip 

Deep learning OpenCV

http://www.filedropper.com/opencv31vs2015win64 

http://www.filedropper.com/farshidpirahansiah

 

 

 

http://docs.opencv.org/trunk/d5/de7/tutorial_dnn_googlenet.html

https://raw.githubusercontent.com/ludv1x/opencv_contrib/master/modules/dnn/samples/bvlc_googlenet.prototxt 

http://dl.caffe.berkeleyvision.org/bvlc_googlenet.caffemodel  

https://raw.githubusercontent.com/ludv1x/opencv_contrib/master/modules/dnn/samples/synset_words.txt

 

 

 

 

 

 

 

 

 

 

 

 

 

 

YouTube channel

https://www.youtube.com/tiziran 

Slides

http://www.slideshare.net/pirahansiah/layers-in-deep-learningcaffe-layers-model-architecture 

http://www.slideshare.net/pirahansiah/how-to-install-digits-51-on-ubuntu-14 

http://www.slideshare.net/pirahansiah/deep-learning-for-video-analysis-part-1-deepstream-sdk-nvidia-tensorrt-nvidia-gpu-inference-engine-gie 

http://www.slideshare.net/pirahansiah/computer-vision-deep-learning-opencv 

Files and source code (download projects)

www.tiziran.com  

https://github.com/pirahansiah 

Group for Deep Learning and Computer Vision

https://www.linkedin.com/groups/10320678 

 

 

Tiziran
Back to content | Back to main menu