windows10安装Python3.6版的CNTK2.3.1,带GPU支持,不使用ASGD。

一、CNTK简介

二、环境说明及预准备

1、硬件配置

CPU: e5-2676v3 12C24T 2.4Ghz

内存:32GB DDR4 2400Mhz 8GB*4 四通道

硬盘:垃圾SATA SSD就不提了

GPU:GeForce GTX 970 1290MHz 4GB 1664CUDA

2、操作系统及驱动

Windows 10 (1709) build 16299

NVIDIA 驱动程序 390.65

CUDA Toolkit 8.0

cuDNN v6.0

驱动和cnDNN的安装就不多说了,下下来安装复制就行了。CUDA目录需要加入环境变量,这个也不赘述了。

3、编程软件

Anaconda 4.4.7 (with python 3.6.3)

Visual Studio 2015 update 3

4、预准备安装环境

为了避免坑爹的Python各种版本不兼容带来的一系列问题,以及显卡驱动和CUDA版本的问题,强烈建议使用conda创建一个虚拟环境来运行Python。

添加conda虚拟环境

conda create -n cntk2.3.1_GPU_noASGD_python3.6 python=3.6 ipykernel

创建一个名为cntk2.3.1_GPU_noASGD_python3.6的虚拟环境,需要注意的是该环境预先安装的python版本为3.6,并且为了方便在jupyter notebook使用该环境的python kernel,所以直接安装ipykernel省去手动配置的麻烦。如果jupyter配置是自己管理的,请另行手动配置。

为虚拟环境添加依赖

conda install -n  cntk2.3.1_GPU_noASGD_python3.6  pytest pandas matplotlib pillow seaborn h5py

pytest pandas matplotlib *pillow *seaborn *h5py都是我在运行cntk教程中遇到的没有安装的包(打*号的代表不是必须,只有画图之用),在这里提前安装,避免掉坑。

需要说明的是,我使用conda安装的matplotlib有问题,找不到matplotlib.pyplot,所以先移除conda的安装:

conda remove -n cntk2.3.1_GPU_noASGD_python3.6 matplotlib

然后激活环境

activate cntk2.3.1_GPU_noASGD_python3.6

用pip安装

pip install matplotlib

至此系统驱动和Python环境的准备工作已经完成了,可以开始安装CNTK了。

三、安装CNTK

1、通过下载whl包用pip安装

微软CNTK官网找到对应的下载链接。

本文安装的是CNTK2.3.1,Python3.6,GPU版本(无1bit-SGD支持),链接是 https://cntk.ai/PythonWheel/GPU/cntk-2.3.1-cp36-cp36m-win_amd64.whl

下载好后,激活虚拟环境,进入下载的文件夹:

activate cntk2.3.1_GPU_noASGD_python3.6

cd  /download_folder/

pip install cntk-2.3.1-cp36-cp36m-win_amd64.whl

当然可以直接pip install 链接

pip install https://cntk.ai/PythonWheel/GPU/cntk-2.3.1-cp36-cp36m-win_amd64.whl

等进度条读完,不出意外就装好了。

安装多卡适用的ASGD版本

 

 

2、编译安装

未完待续。

3、脚本安装

未完待续

四、测试

1、简单测试

激活安装的conda环境:输入以下命令:

python -c “import cntk; print(cntk.__version__)”

如果输出 2.3.1 就说明成功啦!

2、运行tutorials

下载https://notebooks.azure.com/cntk/libraries/tutorials的jupyter notebook的教程

激活虚拟环境,进入该文件夹,运行jupyter notebook,从第一个教程开始,一句一句的跑。

能跑完就说明没有问题了。

3、运行faster-rcnn

未完待续

五、跳坑记录

1、无法使用GPU训练

参考微软CNTK官方文档

The purpose of this tutorial is to help you understand some of the facilities CNTK provides to make the development of deep learning models easier. Some of the advice here are considered good programming practices in general, but we will still cover them in the context of building models.

In [1]:
from __future__ import print_function
import cntk as C
import numpy as np
import scipy.sparse as sparse
import sys
import cntk.tests.test_utils
cntk.tests.test_utils.set_device_from_pytest_env() # (only needed for our build system)

cntk.tests.test_utils.set_device_from_pytest_env() # (only needed for our build system)
巨坑,它设成cpu模式了,需要改为下面的来使用GPU
cntk.device.try_set_default_device(C.device.gpu(0))

Why isn’t CNTK using my GPU?

First check the following. – You have an NVidia GPU – It is listed when running nvidia-smi

Then make sure CNTK sees your GPU: all_devices() returns all the available devices. If your GPU is not listed here, your installation is somehow broken. If CNTK lists a GPU, make sure no other CNTK process is using it (check nvidia-smi, underC:\Program Files\NVIDIA Corporation\NVSMI\nvidia-smi.exe on Windows and /usr/bin/nvidia-smi on Linux). If you have a zombie process using it you can try this

  • on Linux

    $ fuser -k /var/lock/CNTK_exclusive_lock_for_GPU_0
    

    will kill the process that created /var/lock/CNTK_exclusive_lock_for_GPU_0

  • on Windows

  • Make sure you have Process Explorer

  • Open Process Explorer and under View -> Select Columns… click on the GPU tab and check all the checkboxes

  • Now you should be able to sort all processes based on things like “GPU System Bytes” or other attributes. You can kill Python processes that are hogging your GPU(s) and this will automatically release the lock on this device.

Even if some other process is using the GPU you can still use it as well with try_set_default_device(C.gpu(0)); the locks are only meant for automatic device selection to not accidentally allocate one GPU to two processes that are going to it heavily. If you know that’s not the case, it’s better to specify the GPU explicitly with try_set_default_device

In [2]:
C.all_devices()
Out[2]:
(GPU[0] GeForce GTX TITAN X, CPU)
In [3]:
success=C.try_set_default_device(C.gpu(0))
print(success)
True
In [4]:
dev=C.use_default_device()
print(dev)

GPU[0] GeForce GTX TITAN X

2、又一个不让用GPU的坑点

In the block below, we check if we are running this notebook in the CNTK internal test machines by looking for environment variables defined there. We then select the right target device (GPU vs CPU) to test this notebook. In other cases, we use CNTK’s default policy to use the best available device (GPU, if available, else CPU).

if ‘TEST_DEVICE’ in os.environ:
if os.environ[‘TEST_DEVICE’] == ‘cpu’:
C.device.try_set_default_device(C.device.cpu())
else:
C.device.try_set_default_device(C.device.gpu(0))

问题是,你特么根本没有设置TEST_DEVICE啊,然后默认设备又是cpu,狗屁gpu。

解决办法:

直接删了上面的代码,用

C.device.try_set_default_device(C.device.gpu(0))

取代之。

可以看出cntk教程也是不同人写的,上述代码正确的写法应该是:

try:
C.device.try_set_default_device(C.device.gpu(0))
except:
print(“GPU unavailable. Using CPU instead.”)

这样如果不能调用GPU则直接使用CPU,不需要提前设置环境变量,弄得很乱。

3、py2转到py3各种恶心

①cntk教程有些地方要引入Image,但他是直接用py2自动转换过来的,有些库不兼容,比如PIL

from PIL import Image

error:

ImportError: No module named PIL

真他妈的恶心,垃圾Python,需要手动安装pillow才能在py3上使用。

pip install pillow

0 条评论

发表评论