chineseocr / darknet-ocr

darknet text detect and darknet cnn ocr
MIT License
1.14k stars 285 forks source link

darknet-ocr CPU版本和GPU版本docker镜像都已完成 #95

Open GandalfLiu opened 4 years ago

GandalfLiu commented 4 years ago

下载

docker pull ld1995docker/darknet-ocr:latest

gpu版本:

# 需要安装nvidia-docker
sudo docker run --gpus all -it -p 8080:8080 darknet-ocr:latest
# 进入交互模式之后更改config文件中的GPU为True
cd /cor/darknet-ocr && python app.py

cpu版本:

sudo docker run -it -p 8080:8080 darknet-ocr:latest
cd /ocr/darknet-ocr && python app.py

Dockerfile

FROM nvidia/cuda:9.0-cudnn7-devel
MAINTAINER https://github.com/chineseocr/darknet-ocr
LABEL version="1.0"
EXPOSE 8080
WORKDIR /ocr
# opencv-for-darknet中有opencv源码安装包,并且已经替换了相关文件
ADD . /ocr
RUN apt-get update && apt-get install libglib2.0 libsm6 libxrender1 libxext-dev gcc cmake sudo -y
RUN cd /ocr && sh -c '/bin/echo -e "\nyes\n\nyes" | sh Miniconda3-latest-Linux-x86_64.sh'
RUN echo -e "\ny" && /root/miniconda3/bin/conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
RUN /root/miniconda3/bin/conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
RUN /root/miniconda3/bin/conda config --set show_channel_urls yes
RUN /root/miniconda3/bin/conda install python=3.6
RUN echo -e "\ny" && /root/miniconda3/bin/conda install numpy
RUN cd /ocr/build-darknet-ocr/opencv-for-darknet/opencv-4.0.1 && mkdir build && cd build && cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/root/miniconda3 \
-D BUILD_opencv_python2=OFF \
-D BUILD_opencv_python3=ON \
-D PYTHON3_EXECUTABLE=/root/miniconda3/bin/python3.6 \
-D PYTHON3_INCLUDE_PATH=/root/miniconda3/include/python3.6m \
-D PYTHON3_LIBRARIES=/root/miniconda3/lib/libpython3.6m.so \
-D PYTHON3_NUMPY_INCLUDE_DIRS=/root/miniconda3/lib/python3.6/site-packages/numpy/core/include .. \
&& make -j2 && sudo make install
RUN /root/miniconda3/bin/pip install pillow h5py flask requests web.py -i https://mirrors.aliyun.com/pypi/simple
RUN cd /ocr/darknet-ocr/darknet && cp  Makefile-GPU Makefile && make
#CMD /root/miniconda3/bin/python /ocr/darknet-ocr/app.py 8080
ENV LANG C.UTF-8 LC_ALL=C.UTF-8

# 注意将web.py==0.40.dev0换成web.py 不然docker里运行会报ascii的错误
# 另外我发现如果不注释掉其中CMD命令, docker run的时候会报Unsupported activation: relu in function 'ReadDarknetFromCfgStream'这个错误,怎么解决都不行, 只有通过交互模式进入启动才行。
wenlihaoyu commented 4 years ago

dockerfile 加一个变量 ENV LANG C.UTF-8

cometlj commented 4 years ago

验证可用谢谢

bzqyzzld commented 4 years ago

下载

docker pull ld1995docker/darknet-ocr:latest

gpu版本:

# 需要安装nvidia-docker
sudo docker run --gpus all -it -p 8080:8080 darknet-ocr:latest
# 进入交互模式之后更改config文件中的GPU为True
cd /cor/darknet-ocr && python app.py

cpu版本:

sudo docker run -it -p 8080:8080 darknet-ocr:latest
cd /ocr/darknet-ocr && python app.py

Dockerfile

FROM nvidia/cuda:9.0-cudnn7-devel
MAINTAINER https://github.com/chineseocr/darknet-ocr
LABEL version="1.0"
EXPOSE 8080
WORKDIR /ocr
# opencv-for-darknet中有opencv源码安装包,并且已经替换了相关文件
ADD . /ocr
RUN apt-get update && apt-get install libglib2.0 libsm6 libxrender1 libxext-dev gcc cmake sudo -y
RUN cd /ocr && sh -c '/bin/echo -e "\nyes\n\nyes" | sh Miniconda3-latest-Linux-x86_64.sh'
RUN echo -e "\ny" && /root/miniconda3/bin/conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
RUN /root/miniconda3/bin/conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
RUN /root/miniconda3/bin/conda config --set show_channel_urls yes
RUN /root/miniconda3/bin/conda install python=3.6
RUN echo -e "\ny" && /root/miniconda3/bin/conda install numpy
RUN cd /ocr/build-darknet-ocr/opencv-for-darknet/opencv-4.0.1 && mkdir build && cd build && cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/root/miniconda3 \
-D BUILD_opencv_python2=OFF \
-D BUILD_opencv_python3=ON \
-D PYTHON3_EXECUTABLE=/root/miniconda3/bin/python3.6 \
-D PYTHON3_INCLUDE_PATH=/root/miniconda3/include/python3.6m \
-D PYTHON3_LIBRARIES=/root/miniconda3/lib/libpython3.6m.so \
-D PYTHON3_NUMPY_INCLUDE_DIRS=/root/miniconda3/lib/python3.6/site-packages/numpy/core/include .. \
&& make -j2 && sudo make install
RUN /root/miniconda3/bin/pip install pillow h5py flask requests web.py -i https://mirrors.aliyun.com/pypi/simple
RUN cd /ocr/darknet-ocr/darknet && cp  Makefile-GPU Makefile && make
#CMD /root/miniconda3/bin/python /ocr/darknet-ocr/app.py 8080
ENV LANG C.UTF-8 LC_ALL=C.UTF-8

# 注意将web.py==0.40.dev0换成web.py 不然docker里运行会报ascii的错误
# 另外我发现如果不注释掉其中CMD命令, docker run的时候会报Unsupported activation: relu in function 'ReadDarknetFromCfgStream'这个错误,怎么解决都不行, 只有通过交互模式进入启动才行。

关于#CMD /root/miniconda3/bin/python /ocr/darknet-ocr/app.py 8080 这个启动错误已经解决, 主要的问题就是启动的时候必须在 /ocr/darknet-ocr/ 这个目录之下执行才不会报错

在本镜像的基础上重新构建镜像

Dockerfile

FROM darknet-orc:latest
MAINTAINER https://github.com/chineseocr/darknet-ocr
CMD cd /ocr/darknet-ocr && /root/miniconda3/bin/python app.py 8080

此时发现可以正常运行, 如果需要改动为gpu模式, 将config.py 文件复制并且将GPU=True设置, 启动的时候挂载该文件就行