版权声明:本文为博主原创文章,未经博主允许不得转载。 https://cloud.tencent.com/developer/article/1338339
本文主要是记录使用docker/nvidia-docker安装深度学习图片文字识别,开发运行环境.
在做图片文字识别的,需要用到CTPN以及crnn,服务器是ubuntu16的,但是上述两种框架(github现有的)只能运行在ubuntu14上面。考虑到,发布等问题,决定使用docker在ubuntu16搭建ubuntu14 cuda7.5 cudnn3开发运行环境。 crnn的docker安装是在CTPN的docker的基础上面安装。
安装之前记得thpp_build.sh文件要做一定的修改(cuda兼容):
# replace error, https://github.com/facebook/thpp/commit/d9f982c68d7522db9e77e50d135eaa86d84bab85#diff-22577c98d557ea9eca089e8e84d7f98d
sed -i '191s/.*/return THTensor_(max)(values, indices, t, dim,1);/' detail/TensorGeneric.h
sed -i '195s/.*/return THTensor_(min)(values, indices, t, dim,1);/' detail/TensorGeneric.h
sed -i '198s/.*/return THTensor_(sum)(r, t, dim,1);/' detail/TensorGeneric.h
sed -i '201s/.*/return THTensor_(prod)(r, t, dim,1);/' detail/TensorGeneric.h
docker文件如下:
# 基于前面的CTPN
FROM ctpn_docker
MAINTAINER xiongyu haluoluo@qq.com
RUN apt-get update && apt-get install -y \
software-properties-common \
libssl-dev \
libzmq3-dev \
python-dev \
python-zmq \
sudo
# Run Torch7 installation scripts
RUN git clone https://github.com/torch/distro.git /root/torch --recursive && cd /root/torch && \
bash install-deps && \
./install.sh
# Export environment variables manually
ENV LUA_PATH='/root/.luarocks/share/lua/5.1/?.lua;/root/.luarocks/share/lua/5.1/?/init.lua;/root/torch/install/share/lua/5.1/?.lua;/root/torch/install/share/lua/5.1/?/init.lua;./?.lua;/root/torch/install/share/luajit-2.1.0-beta1/?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua'
ENV LUA_CPATH='/root/.luarocks/lib/lua/5.1/?.so;/root/torch/install/lib/lua/5.1/?.so;./?.so;/usr/local/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so'
ENV PATH=/root/torch/install/bin:$PATH
ENV LD_LIBRARY_PATH=/root/torch/install/lib:$LD_LIBRARY_PATH
ENV DYLD_LIBRARY_PATH=/root/torch/install/lib:$DYLD_LIBRARY_PATH
ENV LUA_CPATH='/root/torch/install/lib/?.so;'$LUA_CPATH
ADD torch-0.1.12.post2-cp27-none-linux_x86_64.whl /root/pytorch_install/torch-0.1.12.post2-cp27-none-linux_x86_64.whl
WORKDIR /root/pytorch_install/
RUN pip install torch-0.1.12.post2-cp27-none-linux_x86_64.whl &&\
rm torch-0.1.12.post2-cp27-none-linux_x86_64.whl
RUN pip install torchvision
RUN pip install lmdb -i https://pypi.tuna.tsinghua.edu.cn/simple/
RUN pip install mahotas -i https://pypi.tuna.tsinghua.edu.cn/simple/
RUN pip install Flask -i https://pypi.tuna.tsinghua.edu.cn/simple/
# Install fblualib and its dependencies :
ADD install_all.sh /root/install_all.sh
ADD thpp_build.sh /root/thpp_build.sh
WORKDIR /root
RUN chmod +x ./install_all.sh
RUN ./install_all.sh
# Clone the crnn repo :
RUN git clone https://github.com/bgshih/crnn.git
RUN apt-get update && apt-get install -y \
liblmdb-dev
WORKDIR /root/crnn/src
RUN chmod +x build_cpp.sh
RUN ./build_cpp.sh
# 下面的locale是为了,显示中文
RUN locale-gen en_US.UTF-8
ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' LC_ALL='en_US.UTF-8'
运行结果:
最终基于flask做了一个web demo,运行结果如下: