将keras与tensorflow结合使用”;必须为占位符张量';输入1';使用dtype float“;

将keras与tensorflow结合使用”;必须为占位符张量';输入1';使用dtype float“;,tensorflow,keras,Tensorflow,Keras,在训练GAN的鉴别器时,我遇到了一个意外错误“您必须使用dtype float为占位符张量'input_1'提供一个值” 下面是错误: W tensorflow/core/framework/op_kernel.cc:975] Invalid argument: You must feed a value for placeholder tensor 'input_1' with dtype float [[Node: input_1 = Placeholder[dtype=DT_FL

在训练GAN的鉴别器时,我遇到了一个意外错误“您必须使用dtype float为占位符张量'input_1'提供一个值”

下面是错误:

W tensorflow/core/framework/op_kernel.cc:975] Invalid argument: You must feed a value for placeholder tensor 'input_1' with dtype float
     [[Node: input_1 = Placeholder[dtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/gpu:0"]()]]
W tensorflow/core/framework/op_kernel.cc:975] Invalid argument: You must feed a value for placeholder tensor 'input_1' with dtype float
     [[Node: input_1 = Placeholder[dtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/gpu:0"]()]]
Traceback (most recent call last):
  File "new_model.py", line 204, in <module>
    main()
  File "new_model.py", line 201, in main
    train(nb_epoch=10, BATCH_SIZE=5)
  File "new_model.py", line 176, in train
    d_loss = discriminator.train_on_batch(image_to_dis, label_to_dis)            
  File "/usr/local/lib/python2.7/dist-packages/keras/models.py", line 766, in train_on_batch
    class_weight=class_weight)
  File "/usr/local/lib/python2.7/dist-packages/keras/engine/training.py", line 1320, in train_on_batch
    outputs = self.train_function(ins)
  File "/usr/local/lib/python2.7/dist-packages/keras/backend/tensorflow_backend.py", line 1943, in __call__
    feed_dict=feed_dict)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 766, in run
    run_metadata_ptr)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 964, in _run
    feed_dict_string, options, run_metadata)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1014, in _do_run
    target_list, options, run_metadata)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1034, in _do_call
    raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'input_1' with dtype float
     [[Node: input_1 = Placeholder[dtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/gpu:0"]()]]
     [[Node: moments_4/sufficient_statistics/Shape/_217 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name="edge_1267_moments_4/sufficient_statistics/Shape", tensor_type=DT_INT32, _device="/job:localhost/replica:0/task:0/cpu:0"]()]]

Caused by op u'input_1', defined at:
  File "new_model.py", line 204, in <module>
    main()
  File "new_model.py", line 201, in main
    train(nb_epoch=10, BATCH_SIZE=5)
  File "new_model.py", line 134, in train
    transformer0 = transform_model()
  File "new_model.py", line 22, in transform_model
    inputs = Input(shape=( 128, 128, 3))
  File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 1198, in Input
    input_tensor=tensor)
  File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 1116, in __init__
    name=self.name)
  File "/usr/local/lib/python2.7/dist-packages/keras/backend/tensorflow_backend.py", line 321, in placeholder
    x = tf.placeholder(dtype, shape=shape, name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/array_ops.py", line 1587, in placeholder
    name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_array_ops.py", line 2043, in _placeholder
    name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 759, in apply_op
    op_def=op_def)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2240, in create_op
    original_op=self._default_original_op, op_def=op_def)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1128, in __init__
    self._traceback = _extract_stack()

InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'input_1' with dtype float
     [[Node: input_1 = Placeholder[dtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/gpu:0"]()]]
     [[Node: moments_4/sufficient_statistics/Shape/_217 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name="edge_1267_moments_4/sufficient_statistics/Shape", tensor_type=DT_INT32, _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
我确信图像和标签符合分辩仪的输入 然而,这里的错误消息

Caused by op u'input_1', defined at:
  File "new_model.py", line 204, in <module>
    main()
  File "new_model.py", line 201, in main
    train(nb_epoch=10, BATCH_SIZE=5)
  File "new_model.py", line 134, in train
    transformer0 = transform_model()
  File "new_model.py", line 22, in transform_model
    inputs = Input(shape=( 128, 128, 3))
由操作u'input_1'引起,定义于:
文件“new_model.py”,第204行,在
main()
文件“new_model.py”,第201行,主目录
列车(nb\U历元=10,批量=5)
文件“new_model.py”,第134行,列车中
transformer0=转换_模型()
文件“new_model.py”,第22行,在transform_model中
输入=输入(形状=(128,128,3))
它说错误是由“变压器”的输入张量引起的(它是这个GAN中的发生器)

我的代码包含类似于“transformer\u with_discriminator=discriminator(transformer)”的内容,但是discriminator是在没有转换器的情况下编译的。我认为训练鉴别器与“transformer0”的输入无关

整个脚本有点长,我可以把我模型的链接放在这里吗

image_to_dis.dtype和label_to_dis.dtype都是float32,我尝试将label_to_dis.dtype转换为int


我真的不知道这件事……

它来自于分批标准化。您可以在这里看到:如何解决此问题


如果您需要更多信息,请在评论中提问:)

您能将图像打印到dis.dtype和标签打印到dis.dtype吗?可能会显示您的模型吗?@maz它们都是float32,我已经尝试将label\u转换为dis.dtype到int。@NassimBen整个脚本有点长,我可以把我的模型链接放在这里吗?可能重复的?抱歉回复太晚了。我已经看过你的解决方案了,我会试试的。但我很困惑。在我看来,“鉴别器(生成器)”和“在鉴别器中制作具有相同层的GAN模型”没有区别,它是如何工作的?是鉴别器的“学习阶段”导致了错误吗?
Caused by op u'input_1', defined at:
  File "new_model.py", line 204, in <module>
    main()
  File "new_model.py", line 201, in main
    train(nb_epoch=10, BATCH_SIZE=5)
  File "new_model.py", line 134, in train
    transformer0 = transform_model()
  File "new_model.py", line 22, in transform_model
    inputs = Input(shape=( 128, 128, 3))