環境準備
centos 7
python 2.7
[root@master ~]# uname -a
linux master 3.10.0-229.el7.x86_64 #1 smp fri mar 6 11:36:42 utc 2015 x86_64 x86_64 x86_64 gnu/linux
[root@master ~]# python -v
python
2.7.5
安裝pip
[root@master ~]# yum update -y && yum install -y python
python-devel epel-release.noarch python-pip
如果出現了安裝pip失敗了就用
yum install python-pip安裝
pip安裝成功會顯示
[root@master ~]# pip
usage:
pip [options]
commands:
install install packages.
download download packages.
uninstall uninstall packages.
freeze output installed packages in requirements format.
list list installed packages.
show show information about installed packages.
search search pypi for packages.
wheel build wheels from your requirements.
hash compute hashes of package archives.
completion a helper command used for command completion
help show help
for commands.
使用pip安裝tensorflow
# 僅使用 cpu 的版本
$ pip install
/linux/cpu
/tensorflow-0.5.0-cp27-none-linux_x86_64.whl
# 開啟 gpu 支援的版本 (安裝該版本的前提是已經安裝了 cuda sdk)
$ pip install
/linux/gpu
/tensorflow-0.5.0-cp27-none-linux_x86_64.whl
安裝完成以後測試tensorflow是否成功
[root@master ~]# python
python 2.7
.5 (default, nov 6
2016, 00:28:07)
[gcc 4.8
.520150623 (red hat 4.8
.5-11)] on linux2
or"license"
for more information.
>>>
import tensorflow as tf
>>> hello = tf.constant('hello, tensorflow!')
>>> sess = tf.session()
i tensorflow/core/common_runtime/local_device.cc:25] local device intra op parallelism threads: 8
i tensorflow/core/common_runtime/local_session.cc:45] local session inter op parallelism threads: 8
>>>
print sess.run(hello)
hello, tensorflow!
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>>
print sess.run(a+b)
42
機器學習筆記 TensorFlow
構建乙個簡單的 tensorflow 程式,使用該程式繪製乙個預設圖並建立乙個執行該圖的會話 tensorflow 的名稱源自張量,張量是任意維度的陣列。借助 tensorflow,您可以操控具有大量維度的張量。即便如此,在大多數情況下,您會使用以下乙個或多個低維張量 tensorflow指令會建立...
機器學習 TensorFlow初學
dot 陣列的點積 dot producta np.arange 0,9 out 45 array 0,1,2,3,4,5,6,7,8 b a 1 out 47 array 8,7,6,5,4,3,2,1,0 np.dot a,b out 48 84隨機數生成 這幾個都是用於生成隨機數tensor的...
《TensorFlow機器學習實戰指南》學習筆記四
用tensorflow實現神經網路常見層,如下 import tensorflow as tf import numpy as np sess tf.session 初始化資料 data size 25 data 1d np.random.normal size data size x input ...