【发布时间】:2017-03-17 21:09:44
【问题描述】:
到目前为止,这是我所做的:
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:提要的值不能是 tf.Tensor 对象。可接受的提要值包括 Python 标量、字符串、列表或 numpy ndarray。
但我在 pts_count 中看不到张量,所以我不知道发生了什么。
【问题讨论】:
标签: python-3.x numpy tensorflow