jud*_*zha 23 python tensorflow
我是一个更新的tensorflow,我真的不知道如何解决这个问题.
代码如下:
给火车喂食价值:
sess.run(train_op, feed_dict={images: e, labels: l, keep_prob_fc2: 0.5})
Run Code Online (Sandbox Code Playgroud)使用CNN中的值:
x = tf.placeholder(tf.float32, [None, 10 * 1024])
Run Code Online (Sandbox Code Playgroud)然后有错误
Run Code Online (Sandbox Code Playgroud)InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'Placeholder' with dtype float [[Node: Placeholder = Placeholder[dtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/gpu:0"]()]]
我打印输入值类型print(e.dtype)
,结果是float32
和e.shape:(10, 32, 32, 1)
.
我真的不知道为什么会发生这种错误.
代码格式
第一:
define the CNN model
"image = tf.placeholder(tf.float32, [FLAGS.batch_size, 32,32,1])" is here
Run Code Online (Sandbox Code Playgroud)
第二:
loss funtion and train_op is here
"label = tf.placeholder(tf.float32, [None, FLAGS.batch_size])" is here
Run Code Online (Sandbox Code Playgroud)
第三是会议:
images, labels = getShuffleimage()#here will get shuffle data
num_examples = 0
init = tf.initialize_local_variables()
with tf.Session() as sess:
# Start populating the filename queue.
sess.run(init)
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord, sess=sess)
try:
step = 0
while not coord.should_stop():
start_time = time.time()
image, label = sess.run([images, labels])#get shuffle images
print(image.shape)
print(image.dtype)
sess.run(train_op, feed_dict={image: image, label: label , keep_prob_fc2: 0.5})
duration = time.time() - start_time
except tf.errors.OutOfRangeError:
print('Done training after reading all data')
finally:
# When done, ask the threads to stop.
coord.request_stop()
# Wait for threads to finish.
coord.join(threads)
sess.close()
Run Code Online (Sandbox Code Playgroud)
xxi*_*xxi 13
一些问题
首先,
为什么你使用sess = tf.InteractiveSession()
,with tf.Session() as sess:
同时,只是好奇
第二你有什么占位符的名称x
或images
?
如果名字x
,{images: x_data...}
不会喂x_data
到x
,它覆盖(?)images
我觉得feed_dict应该是{x: x_data...}
如果名称是images
,images
您的程序中是否有两个,placeholder
并shuffle data
尝试修改变量名称
归档时间: |
|
查看次数: |
55537 次 |
最近记录: |