fetch和
feed的用法
1.fetch的用法也就是在session執行時,可以以列表的方式傳參,從而同時run多個op
# -*- coding:utf-8 -*-
import tensorflow as tf
# how to use fetch
input1 = tf.constant(3.0)
input2 = tf.constant(2.0)
input3 = tf.constant(5.0)
add = tf.add(input2,input3)
mul = tf.multiply(input1,add)
with tf.session() as sess:
result = sess.run([mul,add]) ##fetch
print(result)
2.feed的用法
即在呼叫session的run方法時,傳入乙個函式,再以字典的形式傳入其引數
# -*- coding:utf-8 -*-
import tensorflow as tf
# how to use feed
input1 = tf.placeholder(tf.float32)
input2 = tf.placeholder(tf.float32)
output = tf.multiply(input1,input2)
with tf.session() as sess:
# use feed with dict
print(sess.run(output,feed_dict=))
tensorflow使用基礎(2) 非線性回歸
import tensorflow as tf import numpy as np 生成飽含隨機噪音的資料 x data np.linspace 1.0 1.0 200 noise np.random.normal 0,0.02 200 y data x data 2 noise print x ...
tensorflow基礎使用1
1.op的設計及執行乙個簡單的圖import tensorflow as tf x tf.variable 1,2 建立變數 a tf.constant 3,3 建立常量 sub tf.subtract x,a 定義減法op add tf.add x,sub 定義加法op init tf.globa...
tensorflow基礎使用4
非線性回歸 coding utf 8 import tensorflow as tf import numpy as np import matplotlib.pyplot as plt 使用numpy生成200個隨機點 x data np.linspace 0.5,0.5,200 np.newax...