1
自定義分類
到目前爲止,這裏是我做了什麼:無法建立tensorflow
import tensorflow as tf
dists_next_error = tf.placeholder(tf.float32)
dists_center_error = tf.placeholder(tf.float32)
pts_count = tf.placeholder(tf.float32)
ideal_polygon = tf.Variable(0.)
cost = tf.square(dists_next_error) \
+ tf.square(dists_center_error) \
+ tf.square(pts_count - ideal_polygon)
optimizer = tf.train.GradientDescentOptimizer(.05).minimize(cost)
sess = tf.Session()
init = tf.global_variables_initializer()
sess.run(init)
hund_zeros = tf.zeros([100])
hund_ones = tf.ones([100])
for i in range(1000):
sess.run(optimizer, feed_dict={
dists_next_error: hund_zeros,
dists_center_error: hund_zeros,
pts_count: hund_ones})
print(cost.eval(feed_dict={
dists_next_error: 0.,
dists_center_error: 0.,
pts_count: 6.})) #it should output 0 or close to it.
的問題是在
sess.run(optimizer, feed_dict={
dists_next_error: hund_zeros,
dists_center_error: hund_zeros,
pts_count: hund_ones})
在pts_count
線更確切地說,它說: :
TypeError: The value of a feed cannot be a tf.Tensor object. Acceptable feed values include Python scalars, strings, lists, or numpy ndarrays.
但我看不到te nsors在pts_count
,所以我不知道發生了什麼事。