当我使用tensorflow时,运行training(),它会显示:InvalidArgumentError:你必须为占位符张量'占位符'提供一个dtype float和shape [16,160,105,3] [[Node:Placeholder = Placeholderdtype = DT_FLOAT,shape = [16,160,105,3],_ device =“/ job:localhost / replica:0 / task:0 / device:CPU:0”]]
def training():
pre_trained_weights = './/vgg16_pretrain//vgg16.npy'
train_dir = 'E:/weldn/train/'
test_dir = 'E:/weldn/test/'
train_log_dir = './/logs//train//'
val_log_dir = './/logs//val//'
with tf.name_scope('input'):
train, train_label = inputdata.get_files(train_dir)
val,val_label = inputdata.get_files(test_dir)
train_batch, train_label_batch = inputdata.get_batch(train,
train_label,
IMG_W,
IMG_H,
BATCH_SIZE,
CAPACITY)
val_batch, val_label_batch = inputdata.get_batch(val,
val_label,
IMG_W,
IMG_H,
BATCH_SIZE,
CAPACITY)
x = tf.placeholder(tf.float32, shape=[BATCH_SIZE, IMG_W, IMG_H, 3])
y_ = tf.placeholder(tf.int32, shape=[BATCH_SIZE,2])
logits = VGG.VGG16(x, N_CLASSES, IS_PRETRAIN)
loss = tools.loss(logits, y_)
accuracy = tools.accuracy(logits, y_)
my_global_step = tf.Variable(0, name='global_step', trainable=False)
train_op = tools.optimize(loss, learning_rate, my_global_step)
saver = tf.train.Saver(tf.global_variables())
summary_op = tf.summary.merge(tf.get_collection(tf.GraphKeys.SUMMARIES))
init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)
# load the parameter file, assign the parameters, skip the specific layers
tools.load_with_skip(pre_trained_weights, sess, ['fc6','fc7','fc8'])
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess=sess, coord=coord)
tra_summary_writer = tf.summary.FileWriter(train_log_dir, sess.graph)
val_summary_writer = tf.summary.FileWriter(val_log_dir, sess.graph)
try:
for step in np.arange(MAX_STEP):
if coord.should_stop():
break
tra_images,tra_labels = sess.run([train_batch, train_label_batch])
_, tra_loss, tra_acc = sess.run([train_op, loss, accuracy],
feed_dict={x:tra_images, y_:tra_labels})
if step % 50 == 0 or (step + 1) == MAX_STEP:
print ('Step: %d, loss: %.4f, accuracy: %.4f%%' % (step, tra_loss, tra_acc))
summary_str = sess.run(summary_op)
tra_summary_writer.add_summary(summary_str, step)
if step % 200 == 0 or (step + 1) == MAX_STEP:
val_images, val_labels = sess.run([ val_batch, val_label_batch])
val_loss, val_acc = sess.run([loss, accuracy],
feed_dict={x:val_images,y_:val_labels})
print('** Step %d, val loss = %.2f, val accuracy = %.2f%% **' %(step, val_loss, val_acc))
summary_str = sess.run(summary_op)
val_summary_writer.add_summary(summary_str, step)
if step % 2000 == 0 or (step + 1) == MAX_STEP:
checkpoint_path = os.path.join(train_log_dir, 'model.ckpt')
saver.save(sess, checkpoint_path, global_step=step)
except tf.errors.OutOfRangeError:
print('Done training -- epoch limit reached')
finally:
coord.request_stop()
coord.join(threads)
sess.close()
当我运行training()时,追溯就在这里,我不知道为什么 . 请告诉我有什么问题 . 谢谢
InvalidArgumentError: You must feed a value for placeholder tensor
'Placeholder' with dtype float and shape [16,160,105,3]
[[Node: Placeholder = Placeholder[dtype=DT_FLOAT, shape=[16,160,105,3],
_device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]
Caused by op 'Placeholder', defined at:
File "D:\Anaconda\lib\site-packages\spyder\utils\ipython\start_kernel.py",
line 245, in <module>
main()
File "D:\Anaconda\lib\site-packages\spyder\utils\ipython\start_kernel.py",
line 241, in main
kernel.start()
File "D:\Anaconda\lib\site-packages\ipykernel\kernelapp.py", line 477, in
start
ioloop.IOLoop.instance().start()
File "D:\Anaconda\lib\site-packages\zmq\eventloop\ioloop.py", line 177, in
start
super(ZMQIOLoop, self).start()
File "D:\Anaconda\lib\site-packages\tornado\ioloop.py", line 832, in start
self._run_callback(self._callbacks.popleft())
File "D:\Anaconda\lib\site-packages\tornado\ioloop.py", line 605, in
_run_callback
ret = callback()
File "D:\Anaconda\lib\site-packages\tornado\stack_context.py", line 277,
in null_wrapper
return fn(*args, **kwargs)
File "D:\Anaconda\lib\site-packages\ipykernel\kernelbase.py", line 265, in
enter_eventloop
self.eventloop(self)
File "D:\Anaconda\lib\site-packages\ipykernel\eventloops.py", line 106, in
loop_qt5
return loop_qt4(kernel)
File "D:\Anaconda\lib\site-packages\ipykernel\eventloops.py", line 99, in
loop_qt4
_loop_qt(kernel.app)
File "D:\Anaconda\lib\site-packages\ipykernel\eventloops.py", line 83, in _loop_qt
app.exec_()
File "D:\Anaconda\lib\site-packages\ipykernel\eventloops.py", line 39, in process_stream_events
kernel.do_one_iteration()
File "D:\Anaconda\lib\site-packages\ipykernel\kernelbase.py", line 298, in do_one_iteration
stream.flush(zmq.POLLIN, 1)
File "D:\Anaconda\lib\site-packages\zmq\eventloop\zmqstream.py", line 352, in flush
self._handle_recv()
File "D:\Anaconda\lib\site-packages\zmq\eventloop\zmqstream.py", line 472, in _handle_recv
self._run_callback(callback, msg)
File "D:\Anaconda\lib\site-packages\zmq\eventloop\zmqstream.py", line 414, in _run_callback
callback(*args, **kwargs)
File "D:\Anaconda\lib\site-packages\tornado\stack_context.py", line 277, in null_wrapper
return fn(*args, **kwargs)
File "D:\Anaconda\lib\site-packages\ipykernel\kernelbase.py", line 283, in dispatcher
return self.dispatch_shell(stream, msg)
File "D:\Anaconda\lib\site-packages\ipykernel\kernelbase.py", line 235, in dispatch_shell
handler(stream, idents, msg)
File "D:\Anaconda\lib\site-packages\ipykernel\kernelbase.py", line 399, in execute_request
user_expressions, allow_stdin)
File "D:\Anaconda\lib\site-packages\ipykernel\ipkernel.py", line 196, in do_execute
res = shell.run_cell(code, store_history=store_history, silent=silent)
File "D:\Anaconda\lib\site-packages\ipykernel\zmqshell.py", line 533, in run_cell
return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
File "D:\Anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 2698, in run_cell
interactivity=interactivity, compiler=compiler, result=result)
File "D:\Anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 2808, in run_ast_nodes
if self.run_code(code, result):
File "D:\Anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 2862, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-80fac15278ee>", line 1, in <module>
training()
File "E:/04VGGTensorflow/training_and_val.py", line 66, in training
x = tf.placeholder(tf.float32, shape=[BATCH_SIZE, IMG_W, IMG_H, 3])
File "D:\Anaconda\lib\site-packages\tensorflow\python\ops\array_ops.py", line 1599, in placeholder
return gen_array_ops._placeholder(dtype=dtype, shape=shape, name=name)
File "D:\Anaconda\lib\site-packages\tensorflow\python\ops\gen_array_ops.py", line 3090, in _placeholder
"Placeholder", dtype=dtype, shape=shape, name=name)
File "D:\Anaconda\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "D:\Anaconda\lib\site-packages\tensorflow\python\framework\ops.py", line 2956, in create_op
op_def=op_def)
File "D:\Anaconda\lib\site-packages\tensorflow\python\framework\ops.py", line 1470, in __init__
self._traceback = self._graph._extract_stack() # pylint: disable=protected-access
InvalidArgumentError(请参见上面的回溯):您必须为占位符张量'占位符'提供一个值,其中dtype为float和shape [16,160,105,3] [[Node:Placeholder = Placeholderdtype = DT_FLOAT,shape = [16,160,105,3],_ device =“ /作业:本地主机/复制:0 /任务:0 /装置:CPU:0" ]]