TensorFlow安装及简单命令
1、官网及帮助文档
官网: https://www.tensorflow.org/install/install_windows
中文帮助文档:https://efeiefei.gitbooks.io/tensorflow_documents_zh/install/install_windows.html
1.1、cpu版本安装
pip3 install --upgrade tensorflow
上面试默认安装最新版本的tensorflow,如果想安装指定版本的tensorflow,如1.4.0,命令:pip3 install tensorflow==1.4.0
1.2、gpu版本安装
pip3 install --upgrade tensorflow-gpu,需要先安装cuda,cudnn,需要注意版本
备注:目前tensorflow在windows只支持python3.5.x及以上版本,需要使用pip3安装tensorflow。
1.3、安装包下载地址
https://pypi.tuna.tsinghua.edu.cn/simple/tensorflow/
2、cpu版本安装可能遇到的问题
2.1、ImportError: Could not find 'msvcp140.dll'. TensorFlow requires that this DLL...
解决方案:安装微软为VS2015提供的组件Visual C++ Redistributable for Visual Studio 2015,网址https://www.microsoft.com/zh-CN/download/details.aspx?id=48145,下载后直接安装就好了。
2.2、Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
应该是编译问题,解决方案:
import os os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' #忽略警告
3、简单命令
a)查看tensorflow版本及安装路径
import tensorflow as tf
tf.__version__ #版本
tf.__path__ #路径
4、TensorFlow for Java安装
https://vimsky.com/article/3623.html
5、第一个tensorflow示例程序
>>> import tensorflow as tf >>> hello = tf.constant('Hello, TensorFlow!') >>> sess = tf.Session() >>> print(sess.run(hello)) Hello,TensorFlow!
在tensorflow官网Develop栏中有TensorFlow 使用入门示例程序,根据文档说明利用git把示例程序down下来,然后安装说明运行即可。另外也可以把"models/samples/core/get_started/"中的四个python文件拷贝到pyCharm工程运行。
6、教程
精通Tensorflow 1.x: https://www.kancloud.cn/wizardforcel/mastering-tf-1x-zh/1278657
tf.keras.layers.GRUCell:https://runebook.dev/zh-CN/docs/tensorflow/keras/layers/grucell
使用TensorFlow实现LSTM和GRU网络:https://www.cnblogs.com/zyly/p/9029591.html#_label3_3