win10下搭建Mask Rcnn环境详细教程并运行第一个demo程序(包含Anaconda+Tensorflow-gpu+Cuda+cuDnn安装过程及各种坑)_GuoFei_1314的博客-CSDN博客?
前言 查看显卡计算能力和各版本匹配
想要用GPU计算,需要 CUDA 和 cuDNN 的支持,你要查看你的英伟达显卡是否支持CUDA以及对应的计算能力,最好在3.0以上,作者显卡是GTX950M,计算能力为5.0。 附上网址:https://developer.nvidia.com/cuda-gpus
满足条件后就证明你的电脑可以继续下一步了。注意、注意、注意:不要着急马上安装,需要知道版本匹配问题。
? a. Windows环境下不能安装Python2.7版本的tensorflow; ? b.?tensorflow、Python、cuda、cudnn必须严格匹配,不然就会出现各种奇奇怪怪的问题;
Linux
Mac
?Windows
keras和tensorflow版本对应
?python 3.6? ?cuda10.0? cudnn7.6.3? tensorflow-gpu1.13.1? keras 2.2.4
?1 Mask R-CNN环境
Mask R-CNN是基于Python3,Keras,TensorFlow。
- Python 3.4+(自行安装,本文为Python 3.6)
- Jupyter Notebook
- TensorFlow>=1.3.0
- Keras>=2.0.8
- numpy、scipy、Pillow、cython、matplotlib、scikit-image、opencv-python、h5py、imgaug、IPython[all]
2为conda设置清华源
打开Anaconda Prompt,输入清华仓库镜像,这样更新会快一些:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes
3 创建虚拟环境
a. 运行win+r,输入cmd,进入命令行模式 b. 创建虚拟环境
conda create --name mrcnn python=3.6
c. 查看虚拟环境
conda info --envs
d. clone代码到移动硬盘m:\code中,代码文件夹名为Mask_RCNN-master
git clone https://github.com/matterport/Mask_RCNN.git
报错:?Failed to connect to github.com port 443: Timed
解决:
git config --global http.proxy http://127.0.0.1:1080
git config --global https.proxy http://127.0.0.1:1080
报错:?OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 10054
解决:变https为git
小知识:
我们可以根据所下载文件的容量来设置Postbuffer的数值。例如,将Postbuffer的值设为500M(500×1024×1024),在终端输入命令:
git config --global http.postBuffer 524288000
4 安装tensorflow-gpu版
a. 激活环境
conda activate mrcnn
b. 下载
pip install tensorflow-gpu==1.13.1 -i https://pypi.tuna.tsinghua.edu.cn/simple
务必注意一点,在安装完tensroflow后,由于我们是新创建的conda环境,该环境中基本上是空的,有很多包和IDE并没有安装进来,通过以下命令安装Anaconda基础包。
conda install anaconda
tensorflow卸载
sudo pip uninstall protobuf
sudo pip uninstall tensorflow
5 安装cuda cudnn(我之前已经装过了)
跳过!
6 安装keras
pip install keras==2.2.4 -i https://pypi.tuna.tsinghua.edu.cn/simple
7 测试
a. 查看是否使用GPU
python
import tensorflow as tf
tf.test.gpu_device_name()
?import tensorflow as tf报错!(下面)
?b. 查看在使用哪个GPU
from tensorflow.python.client import device_lib
device_lib.list_local_devices()
?c. 查看已安装tensorflow版本
python
import tensorflow as tf
tf.__version__
d. 查看已安装tensorflow安装路径
python
import tensorflow as tf
tf.__path__
e. 确定自己的TensorFlow是CPU还是GPU的版本
import numpy
import tensorflow as tf
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
print(sess.run(c))
f. 查看keras版本
python
import keras as k
print(k.__version__)
g. 查看tensorflow是否安装成功
import tensorflow as tf
hello = tf.constant('Hello')
sess=tf.Session()
print(sess.run(hello))
8 安装requirements中的内容
pip3 install -r requirements.txt
报错:pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.?
?
9 基于mask?rcnn的其他需要安装部分?
a.?git安装(已安装,跳过)
b.?pycocotools 安装 参考: https://blog.csdn.net/XCCCCZ/article/details/82725409 https://blog.csdn.net/qq_39622065/article/details/82023317 https://blog.csdn.net/gxiaoyaya/article/details/78363391 https://blog.csdn.net/chixia1785/article/details/80040172 借了一下别人成功的方法: 第一步:去GitHub上下代码的话非常慢,这里给出压缩包:链接:https://pan.baidu.com/s/19RAjr6Y2VwJLIZ_ZT-Bxqg 提取码:i9vo 第二步:解压,命令行进入解压文件目录,执行以下代码: cd coco/PythonAPI python setup.py build_ext --inplace
报错:ModuleNotFoundError: No module named 'Cython'(在下面)
第三步:python setup.py build_ext install 经过上面三个步骤,已经安装好了pycocotools到python库了,进入python3命令行就可以直接导入了,执行下面命令不报错,类似下图说明已经安装成功了。
c.?包Shapely安装
用pip命令这个包一般安装不成功,但是又需要,那怎么办?来看下面。 首先,查看你电脑支持的python包后缀(安装python出现is not a supported wheel on this platform解决办法)
import pip._internal
print(pip._internal.pep425tags.get_supported())
然后,去这个网站:https://www.lfd.uci.edu/~gohlke/pythonlibs/ 下载你电脑对应的安装文件,我的是Shapely-1.6.4.post1-cp37-cp37m-win_amd64.whl 百度网盘资源:https://pan.baidu.com/s/1duGeqwHa0BjeYUIzHIyKiQ 提取码:qz6g 下载完后切换到下载下的路径,再用pip就成功安装。
d. visual c++ 2015 bulid tools安装
百度网盘资源:https://pan.baidu.com/s/1BWS01bydmNQQsJaGrMrVcQ 提取码:clah 默认安装就可以。
e. 如遇到h5py_init_.py:36:错误
h5py 和 numpy 版本冲突,h5py 官方已修复合并到 master 分支,但是还没发新版,在发版之前可以用降级 numpy 的方法跳过这个问题。降级命令如下:
pip install numpy==1.13.3
7.如遇到tensorflow-tensorboard 0.4.0rc3 has requirement bleach==1.5.0, but you’ll have bleach 2.0.0 which is incompatible错误 解决方法:
pip install tensorflow-tensorboard
?
?
问题
1? ?import tensorflow as tf报错:
D:\anaconda3\envs\mrcnn\lib\site-packages\tensorflow\python\framework\dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint8 = np.dtype([("qint8", np.int8, 1)])
D:\anaconda3\envs\mrcnn\lib\site-packages\tensorflow\python\framework\dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint8 = np.dtype([("quint8", np.uint8, 1)])
D:\anaconda3\envs\mrcnn\lib\site-packages\tensorflow\python\framework\dtypes.py:528: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint16 = np.dtype([("qint16", np.int16, 1)])
D:\anaconda3\envs\mrcnn\lib\site-packages\tensorflow\python\framework\dtypes.py:529: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint16 = np.dtype([("quint16", np.uint16, 1)])
D:\anaconda3\envs\mrcnn\lib\site-packages\tensorflow\python\framework\dtypes.py:530: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint32 = np.dtype([("qint32", np.int32, 1)])
D:\anaconda3\envs\mrcnn\lib\site-packages\tensorflow\python\framework\dtypes.py:535: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
np_resource = np.dtype([("resource", np.ubyte, 1)])
解决:numpy版本太高,降低其版本? a. 查看当前版本?
import numpy
numpy.__version__
'1.19.5'
b. 卸载
pip uninstall numpy
?c. 安装低版本
pip install numpy==1.16.4 -i https://pypi.tuna.tsinghua.edu.cn/simple
2 报错:ModuleNotFoundError: No module named 'Cython'
pip install Cython
|