制作的docker镜像 Anaconda3+tensorflow-gpu1.12 踩坑记录
前提:已经安装好了docker和nvidia-docker
一、dockerfile制作镜像
1、创建dockerfile所在的文件夹
mkdir tfgpu
cd tfgpu
vim DockerFile
DockerFile内容
RUN echo -e “[global]\nindex-url = https://pypi.mirrors.ustc.edu.cn/simple/” >> ~/pip.conf这一步貌似美起作用,可以不写,直接临时换源下载即可
tensorflow可以直接指定为1.12.0,默认不写会下载为2.1.0,最后还的卸载
FROM nvidia/cuda:9.0-cudnn7-devel-ubuntu16.04
MAINTAINER bobwang<wanglongtin@163.com>
# install basic dependencies
RUN apt-get update
RUN apt-get install -y wget \
vim \
cmake
# install Anaconda3
RUN wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-5.2.0-Linux-x86_64.sh -O ~/anaconda3.sh
RUN bash ~/anaconda3.sh -b -p /home/anaconda3 \
&& rm ~/anaconda3.sh
ENV PATH /home/anaconda3/bin:$PATH
# change mirror
RUN mkdir ~/.pip \
&& cd ~/.pip
RUN echo -e "[global]\nindex-url = https://pypi.mirrors.ustc.edu.cn/simple/" >> ~/pip.conf
# install tensorflow
RUN /home/anaconda3/bin/pip install wrapt --ignore-installed && pip install --upgrade pip -i https://mirrors.aliyun.com/pypi/simple/ && /home/anaconda3/bin/pip install tensorflow-gpu -i https://mirrors.aliyun.com/pypi/simple/
3、制作镜像
docker build -t tf-gpu .
4、运行镜像
sudo nvidia-docker run -it --rm --name test c225e83ca98e /bin/bash
5、使用tensorflow
import tensorflow as tf
报错
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-uGQnzpFB-1587399659477)(/home/bob/.config/Typora/typora-user-images/image-20200420141725441.png)]
关键信息
W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libnvinfer.so.6'; dlerror: libnvinfer.so.6: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/local/nvidia/lib:/usr/local/nvidia/lib64
解决:
可能原因1、tensorRT包缺少
原因2:tensorflow版本与cuda不兼容,
对照表
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-UXvqfWa4-1587399659484)(/home/bob/.config/Typora/typora-user-images/image-20200420151538217.png)]
查看cuda的版本
cat /usr/local/cuda/version.txt
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-y7lWUTD1-1587399659487)(/home/bob/.config/Typora/typora-user-images/image-20200420153933596.png)]
查看cudnn的版本
cat /usr/local/cuda/include/cudnn.h |grep CUDNN_MAJOR -A 2
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-bVl3dKIX-1587399659491)(/home/bob/.config/Typora/typora-user-images/image-20200420154134620.png)]
显示无信息
尝试1:安装与cuda对应的tensorflow版本1.12
pip uninstall tensorflow-gpu
pip install tensorflow-gpu==1.12.0 -i https://mirrors.aliyun.com/pypi/s

最低0.47元/天 解锁文章
2837

被折叠的 条评论
为什么被折叠?



