FLOWNET2.0 Installation Guide

Source: Internet
Author: User

?

\ (Installation Environment: \color{red}{ubuntu16.04 + CUDA8.0 + cudnn5.0}\)

Installing Cudacuda Installation Preparation

CUDA Official Installation Documentation

First check if your PC has a CUDA-enabled GPU

lspci | grep -i nvidia

View Linux version information and GCC version

uname -m && cat /etc/*release && gcc --version
Download

Download CUDA-8.0, and note the selection deb(local) of versions, such as

?

CUDA Installation

sudo dpkg -i cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64.debsudo apt-key add /var/cuda-repo-8-0-local-ga2/7fa2af80.pubsudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pubsudo apt-get updatesudo apt-get install cuda
Environment settings

Join in . BASHRC

export PATH=/usr/local/cuda-8.0/bin${PATH:+:${PATH}}export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64 ${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}  # 64位系统export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib ${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}   # 32位
Installing Persistence Daemon

The daemon approach provides a more elegant and robust solution to this problem than persistence mode.

/usr/bin/nvidia-persistenced --verbose
Verifying the installation

View GPU-driven and CUDA version information

cat /proc/driver/nvidia/version && nvcc -V

Executive cuda-install-samples-8.0.sh

, and then in A folder will appear in the directory Nvidia_cuda-8.0_samples

cuda-install-samples-8.0.sh ~cd ~/NVIDIA_CUDA-8.0_Samplesmake -j `nproc`cd  ~/NVIDIA_CUDA-8.0_Samples/bin/x86_64/linux/release./deviceQuery
Installing CuDNN

Sign up for Nvidia account, Nvidia CUDNNV5
, select cuDNN v5 Library for Linux Download

CuDNN Official Installation Guide

tar -xzvf cudnn-8.0-linux-x64-v5.0-ga.tgzsudo cp cuda/include/cudnn.h /usr/local/cuda/includesudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*

Verifying the installation

cp -r /usr/src/cudnn_samples_v7/ $HOMEcd  $HOME/cudnn_samples_v7/mnistCUDNNmake clean && make `nproc`./mnistCUDNN

If you see the following information, congratulations, installation success

Test passed!
Environment Dependent installation
sudo apt-get updatesudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler -ysudo apt-get install --no-install-recommends libboost-all-dev -ysudo apt-get install libopenblas-dev liblapack-dev libatlas-base-dev -ysudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev -ysudo apt-get install git cmake build-essential -y
Installing OPENCV

Download OpenCV

Compiling OpenCV 3.3.1

mkdir build  # 创建编译的文件目录cd buildcmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..make -j `nproc`  # 编译sudo make installpkg-config --modversion opencv  
Installing the flownet2.0 before installation is ready

When installing flownet2.0, your installation directory of the organization may be different from me, so here I follow my installation directory to explain, so that I can explain, it should also be easy for you to understand, when you install, you just need to simply replace my installation directory with your own on it, it is so simple, Here's how to start

First of all, I'll introduce my installation directory

install_dir = /home/wangbin/github/
cd /home/wangbin/github/git clone https://github.com/lmb-freiburg/flownet2cd flownet2cp Makefile.config.example Makefile.config

Below we need to consider how to configure Caffe Makefile.config , if you are first contact Caffe, you can refer to the official Docker version of the Makefile.config configuration, you can directly use the official configuration file, not You can also use my modified version, described below

Presumably everyone is more familiar with Anaconda, because we want to use pycaffe , so we need to configure Python, seemingly caffe to Python3 support is not good, so choose python2.7. In order to not affect the operation of other software, we use Conda to configure a Virtual python2.7 environment, Anaconda installation See here

conda create -n flownet2.0 python=2.7conda install numpyconda instaLL cythonconda install scipyconda install scikit-imagepip install msgpackpip install opencv-python

My Anaconda installation directory is

/home/wangbin/software/anaconda2

Then modify the python-related variables in the file in the makefile.config

ANACONDA_HOME := $(HOME)/software/anaconda2/envs/flownet2PYTHON_INCLUDE := $(ANACONDA_HOME)/include         $(ANACONDA_HOME)/include/python2.7         $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/includePYTHON_LIB := $(ANACONDA_HOME)/libLINKFLAGS := -Wl,-rpath,$(PYTHON_LIB)

Easy reference here to post my makefile.config file

Modify the variables of the Makefile file at the same time

LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial  opencv_core opencv_highgui opencv_imgproc opencv_imgcodecsNVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
Compiling and installing Caffe

After the compilation is successful, add Pycaffe to the $PYTHONPATH

sudo echo export PYTHONPATH=:$PYTHONPATH:"~/github/flownet2/python" >> ~/.bashrc

Configure the environment, each time you use flownet2.0, do the following

Important: Use the above script to establish a FLOWNET2 environment to ensure that your Python path and system path do not contain other versions of Caffe

Download model
To test a model using the image pair

Flyingchairs test data is located in

/home/wangbin/github/flownet2/data/FlyingChairs_examples

For subsequent ease of operation, we will first copy the first sample data under this directory under the following directory

/home/wangbin/github/flownet2/models
cp /home/wangbin/github/flownet2/data/FlyingChairs_examples/0000000-*       /home/wangbin/github/flownet2/models/

0000000-gt.flo is Ground-truth light flow

(2 channel) optical flow, we are unable to open through the picture Viewer eog , we need to convert the optical flow diagram into an RGB map, the conversion tool described below

Optical Flow visualization Tool

[Middlebury Optical Flow visualization tool] (http://vision.middlebury.edu/flow/submit/)
See readme.md in the flow-code folder for specific use

wget http://vision.middlebury.edu/flow/code/flow-code.zipunzip flow-code.zipcd flow-code/imageLibmake -j `nproc`cd ..make -j `nproc`

Use the resulting executable file color_flow to convert the optical flow graph into an RGB graph, the color of the graph represents the direction of motion, and the shade of the color represents the speed of motion.

usage: ./color_flow [-quiet] in.flo out.png [maxmotion]

Use Color_flow to convert the Ground-truth optical flow 0000000-gt.flo of the first pair of Flyingchairs to an RGB map

./color_flow 0000000-gt.flo  0000000-gt.png

?

Optical Flow Visualization code (python)

If you want to use optical flow visualization in your code, there is a simple Python version that can be used (using OPENCV), simply can't believe it,

Brighter version of background

def visualize_optical_flow(frame1, blob):    # optical flow visualization    hsv = np.zeros_like(frame1)    rad, ang = cv2.cartToPolar(blob[..., 0], blob[..., 1])    hsv[..., 0] = ang * 180 / np.pi / 2    hsv[..., 1] = cv2.normalize(rad, None, 0, 255, cv2.NORM_MINMAX)    hsv[..., 2] = 255    rgb = cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)    cv2.imshow('flow', rgb)

Darker version of background

def visualize_optical_flow(frame1, blob):    # optical flow visualization    hsv = np.zeros_like(frame1)    rad, ang = cv2.cartToPolar(blob[..., 0], blob[..., 1])    hsv[..., 0] = ang * 180 / np.pi / 2    hsv[..., 2] = cv2.normalize(rad, None, 0, 255, cv2.NORM_MINMAX)    hsv[..., 1] = 255    rgb = cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)    cv2.imshow('flow', rgb)
Test Image Pair

Add the Flownet2.0/script directory to the PATH, making it easy to use scripts under script in any of our directories

sudo echo export PATH=$PATH:"/home/wangbin/github/flownet2/scripts" >> ~/.bashrc
cd models run-flownet.py FlowNet2/FlowNet2_weights.caffemodel.h5  FlowNet2/FlowNet2_deploy.prototxt.template 0000000-img0.ppm 0000000-img1.ppm 0000000-pre.flo./color_flow 0000000-pre.flo  0000000-pre.pngeog 0000000-pre.png
Video input source

We use flownet2.0 to process most of the video content, and here I have written a code about using the video as the input source, sharing it on GitHub, the need for pickup

GitHub flownet2_videocapture.py

FLOWNET2.0 Installation Guide

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.