jingweimo的个人博客分享 http://blog.sciencenet.cn/u/jingweimo

博文

Tensorflow in Windows with Anaconda2 for Python3

已有 3518 次阅读 2017-6-21 10:38 |系统分类:科研笔记

(Updated as of 06/20/2018)

Previously, it was possible to run TensorFlow within a Windows environment by using a Docker container. There were many downsides to this method—the most significant of which was lack of GPU support.  With GPUs often resulting in more than a 10x performance increase over CPUs, it's no wonder that people were interested in running TensorFlow natively with full GPU support.  As of December 2016, this is now possible. And the best part is, it only takes a minute to setup:


1) Prerequisites: cuda + cudnn (make sure cudnn components are extracted to the right places)


2) configure virtual python environment: conda create --name tensorflow-gpu python=3.5

(note that TensorFlow is only supported by python 3.5 in windows)

(to activate this environment: conda activate tensorflow-gpu; to deactivate it is to use: conda deactivate tensorflow-gpu)


3) activate tensorflow-gpu


4) pip install tensorflow-gpu  

pip install --ignore-installed --upgrade tensorflow-gpu

Note tensorflow-gpu versions (as of 06/21/2018) (https://www.tensorflow.org/versions/) and their compatibility with cuda (https://developer.nvidia.com/cuda-toolkit-archive):

Versions: 0.12.0rc0, 0.12.0rc1, 0.12.0, 0.12.1, 1.0.0, 1.0.1, 1.1.0rc0, 1.1.0rc1, 1.1.0rc2, 1.1.0, 1.2.0rc0, 1.2.0rc1, 1.2.0rc2, 1.2.0, 1.2.1, 1.3.0rc0, 1.3.0rc1, 1.3.0rc2, 1.3.0, 1.4.0rc0, 1.4.0rc1, 1.4.0, 1.5.0rc0, 1.5.0rc1, 1.5.0, 1.5.1, 1.6.0rc0, 1.6.0rc1, 1.6.0, 1.7.0rc0, 1.7.0rc1, 1.7.0, 1.7.1, 1.8.0rc0, 1.8.0rc1, 1.8.0, 1.9.0rc0, 1.9.0rc1

https://stackoverflow.com/questions/50622525/which-tensorflow-and-cuda-version-combinations-are-compatible

The latest tensorflow-gpu 1.9 still ask for cuda9.0

https://github.com/tensorflow/tensorflow/issues/20865


5) test installation and gpu:

https://www.tensorflow.org/install/install_windows

https://www.tensorflow.org/tutorials/using_gpu

                            python #anaconda prompt

                            import tensorflow as tf

                            hello = tf.constant('Hello, TensorFlow!')

                            sess = tf.Session()

                            print(sess.run(hello))

                            a = tf.constant(10)

                            b = tf.constant(32)

                            print(sess.run(a + b))



6) run mnist_deep.py for a cnn test   #https://www.tensorflow.org/get_started/mnist/pros


The other way to run tensorflow is to install anaconda3 seperately or within the 'envs' subfolder of the anaconda 2, and then install tensorflow with pip installation as described above.

 

7) enable tensorflow as the backend of keras (https://keras.io/backend/)

modify the keras jason file:

"image_data_format": "channels_last"

"backend": "tensorflow"

 

8) import keras

C:\Users\YL\Anaconda2\envs\py35\lib\site-packages\h5py\__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
Using TensorFlow backend.


Sources:

https://www.tensorflow.org/versions/r0.12/get_started/os_setup#pip_installation_on_windows

https://www.tensorflow.org/install/install_windows#CommonInstallationProblems

https://sites.google.com/site/nttrungmtwiki/home/it/data-science---python/tensorflow/using-tensorflow-in-windows-with-a-gpu

https://github.com/jeffheaton/t81_558_deep_learning

http://blog.csdn.net/zcf1784266476/article/details/70158272

http://research.wmz.ninja/articles/2017/01/configuring-gpu-accelerated-keras-in-windows-10.html

http://lifeofajenni.com/2017/02/22/python-2x-and-3x-in-spyder/

https://conda.io/docs/user-guide/tasks/manage-python.html#installing-a-different-version-of-python

https://medium.com/@pushkarmandot/installing-tensorflow-theano-and-keras-in-spyder-84de7eb0f0df




https://blog.sciencenet.cn/blog-578676-1062054.html

上一篇:Why must the gradient be directed in an increasing direction
下一篇:Tensorflow: ptw_word_lm.py implementation
收藏 IP: 35.10.57.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-9-22 15:19

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部