思路:在nvidia/cuda镜像中安装Dockerfile提到的内容
参照flownet2-docker-master中的Dockfile
1、创建nvidia/cuda
容器
在一个你希望和容器文件建立映射的路径下运行以下命令
docker run -it --runtime=nvidia -v $PWD:/home/share --gpus all nvidia/cuda:8.0-cudnn5-devel-ubuntu16.04 bash
2、上传flownet2-docker-master
到容器中,也就是建立映射的路径
3、安装
apt-get update && \
apt-get install -y --no-install-recommends \
module-init-tools \
build-essential \
ca-certificates \
wget \
git \
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-dev \
python-numpy \
python-scipy \
python-protobuf \
python-pillow \
python-skimage
4、安装flownet2
1)这里我把github上的代码下载之后放到了码云上,免得被墙。以下是在flownet2-docker-master
文件下,一行一行运行
git clone https://gitee.com/haixusong/flownet2
cp ./FN2_Makefile.config ./flownet2/Makefile.config
cp ./FN2_run-flownet-docker.py ./flownet2/scripts/run-flownet-docker.py
cd flownet2
rm -rf .git
cd models
2)使用vim打开models
下的download-models.sh
文件,里面有三个模型的链接,手动下载吧,毕竟被墙了。这模型文件挺大的,不能放到码云,这也就是为啥我没用Dockerfile的原因。
下载后上传并解压到models文件夹,例如:
tar xvzf flownet2-models.tar.gz -C ……/flownet2/models
记得换成自己models的路径。
rm flownet2-models.tar.gz && \
cd .. && \
make -j`nproc` && \
make -j`nproc` pycaffe
3)删除不需要的软件
apt-get remove -y \
module-init-tools \
build-essential \
ca-certificates \
git \
wget && \
apt-get install -y --no-install-recommends \
sudo && \
apt-get autoremove -y && \
apt-get autoclean -y && \
rm -rf /var/lib/apt/lists/*
参照run-network.sh,在创建的容器中
1)flownet2中配置caffe环境:source set-env.sh
2)运行.py文件
非kitti
在这之前可先创建output文件夹,这是个绝对路径。cd /output 可查看运行结果
python run-flownet-docker.py --gpu 0 /home/share/flownet2-docker-master/flownet2/models/FlowNet2/FlowNet2_weights.caffemodel* /home/share/flownet2-docker-master/flownet2/models/FlowNet2/FlowNet2_deploy.prototxt.template data/0000000-imgL.png data/0000001-imgL.png flow.flo
同时运行多个:
python run-flownet-docker.py --gpu 0 /home/share/flownet2-docker-master/flownet2/models/FlowNet2/FlowNet2_weights.caffemodel* /home/share/flownet2-docker-master/flownet2/models/FlowNet2/FlowNet2_deploy.prototxt.template data/flowinput/0003-first.txt data/flowinput/0003-second.txt data/flowout/0003.txt
kitti
python run-flownet-docker.py --gpu 0 /home/share/flownet2-docker-master/flownet2/models/FlowNet2-KITTI/FlowNet2-KITTI_weights.caffemodel* /home/share/flownet2-docker-master/flownet2/models/FlowNet2-KITTI/FlowNet2-KITTI_deploy.prototxt.template data/0000000-imgL.png data/0000001-imgL.png flow.flo
python run-flownet-docker.py --gpu 0 /home/share/flownet2-docker-master/flownet2/models/FlowNet2-KITTI/FlowNet2-KITTI_weights.caffemodel* /home/share/flownet2-docker-master/flownet2/models/FlowNet2-KITTI/FlowNet2-KITTI_deploy.prototxt.template data/flowinput/0003-first.txt data/flowinput/0003-second.txt data/flowout/0003.txt
容器ID1641e69a108c
3)每次重启容器,再代码时候都要配置caffe的环境,比较麻烦,将环境加到.bashrc文件里
在flownet2文件下:
echo $( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
以上可获得CAFFE_PATH
的数值
vim ~/.bashrc
复制以下内容:
CAFFE_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
RELEASE_PATH="$CAFFE_PATH/build"
export PYTHONPATH="$CAFFE_PATH/python:$PYTHONPATH"
export LD_LIBRARY_PATH="$RELEASE_PATH/lib:$LD_LIBRARY_PATH"
export PATH="$RELEASE_PATH/tools:$RELEASE_PATH/scripts:$PATH"
export CAFFE_BIN="$RELEASE_PATH/tools/caffe"
记得替换CAFFE_PATH的数值,这个内容其实就参照的set-env.sh
。最后
source ~/.bashrc