入門 tensorflow(一)

tensorflow-gpu的幾個坑

  1. 940mx顯卡:cuda8+cudnn5
  2. 1050:cuda8安裝選自定義安裝,僅僅選擇cuda即可,cudnn6
  3. 配置cudnn路徑變量
  4. vs2017不支持,僅僅支持2013,2015
  5. 安裝tensorflow之前需要配置:C:\Windows\System32\msvcp140.dll環(huán)境變量
  6. 參考1 參考2
  7. vs2015地址

你的第一個Grpah & run it in a session

在開始之前不妨先了解下特你tensorflow的一些基本概念:中文社區(qū),當然如果你已經了解,跳過。

A TensorFlow program is typically split into two parts:

  • the first part builds a computation graph (this is called the construction phase)

  • the second part runs it (this is the execution phase). The construction phase typically builds a computation graph representing the ML model and the computations required to train it. The execution phase generally runs a loop that evaluates a training step repeatedly (for example, one step per mini-batch), gradually improving the model parameters.

# encoding: utf-8

"""
@version: python3.5.2 
@author: kaenlee  @contact: lichaolfm@163.com
@software: PyCharm Community Edition
@time: 2017/8/3 10:01
purpose:
"""

import tensorflow as tf

# creates a computation graph
x = tf.Variable(3, name="x")
y = tf.Variable(4, name='y')
f = tf.add(tf.multiply(tf.multiply(x, x), y), tf.add(y, 2)) #多個op組合成一個op

#The following code creates a session, initializes the variables,
sess = tf.Session()
initial = tf.global_variables_initializer()
sess.run(initial)

#evaluates, and f then closes the session
result = sess.run(f)
print(result)
sess.close()

# 另外一種寫法
with tf.Session() as sess:
    x.initializer.run()
    y.initializer.run()
    res = sess.run(f)
    print(res)
sess.close()
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容