tensorflow.python.framework.errors_impl.InvalidArgumentError:您必须输入占位符张量'sequential_input'的值

时间:2019-08-20 09:13:13

标签: python tensorflow keras ensemble-learning

我正在研究OVA(一个对所有)分类问题。为此,我训练了具有Sigmoid函数和binary_crossentropy的Keras二进制分类器。我需要将它们整合到类似于here的多类模型中,当我尝试这样做时,出现以下错误

 tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'sequential_input' with dtype float and shape [?,224,224,3]
         [[{{node sequential_input}}]]

程序代码

for i in os.listdir(model_root): //loading all the models
print(i)
filename = model_root + "/" + i
# load model
model = load_model(filename, custom_objects={'KerasLayer': hub.KerasLayer})
models.append(model)
print(len(models))  //3

#Merge layer to fit a model

inputs = tf.keras.Input(shape=(224,224,3))
outputs = [m(inputs) for m in models]
outputs = tf.keras.layers.concatenate(outputs, axis=-1)
ensemble = tf.keras.models.Model(inputs, outputs)
ensemble.compile(optimizer=tf.keras.optimizers.Adam(), loss='categorical_crossentropy', metrics=['accuracy'])

#To fit the loaded models to the data

steps_per_epoch = image_data.samples // image_data.batch_size
validation_steps = image_data_val.samples / image_data_val.batch_size
ensemble.fit((item for item in image_data), epochs=2,
          steps_per_epoch=steps_per_epoch,
          validation_data=(item for item in image_data_val), validation_steps=validation_steps, verbose=2)

我在fit函数上遇到此错误。这是回溯

Epoch 1/2
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Program Files\JetBrains\PyCharm 2019.2\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm 2019.2\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/Users/Pawandeep/Desktop/Python projects/ensemble_image.py", line 85, in <module>
    validation_data=(item for item in image_data_val), validation_steps=validation_steps, verbose=2)
  File "C:\Python\lib\site-packages\tensorflow\python\keras\engine\training.py", line 673, in fit
    initial_epoch=initial_epoch)
  File "C:\Python\lib\site-packages\tensorflow\python\keras\engine\training.py", line 1433, in fit_generator
    steps_name='steps_per_epoch')
  File "C:\Python\lib\site-packages\tensorflow\python\keras\engine\training_generator.py", line 264, in model_iteration
    batch_outs = batch_function(*batch_data)
  File "C:\Python\lib\site-packages\tensorflow\python\keras\engine\training.py", line 1175, in train_on_batch
    outputs = self.train_function(ins)  # pylint: disable=not-callable
  File "C:\Python\lib\site-packages\tensorflow\python\keras\backend.py", line 3292, in __call__
    run_metadata=self.run_metadata)
  File "C:\Python\lib\site-packages\tensorflow\python\client\session.py", line 1458, in __call__
    run_metadata_ptr)
tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'dense_1_target' with dtype float and shape [?,?]
     [[{{node dense_1_target}}]]

我的模特看起来像

        Model: "model"
__________________________________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to                     
==================================================================================================
input_1 (InputLayer)            [(None, 224, 224, 3) 0                                            
__________________________________________________________________________________________________
sequential_4 (Sequential)       (None, 1)            3541267     input_1[0][0]                    
__________________________________________________________________________________________________
sequential_8 (Sequential)       (None, 1)            3541267     input_1[0][0]                    
__________________________________________________________________________________________________
sequential_2 (Sequential)       (None, 1)            3541267     input_1[0][0]                    
__________________________________________________________________________________________________
concatenate (Concatenate)       (None, 3)            0           sequential_4[1][0]               
                                                                 sequential_8[1][0]               
                                                                 sequential_2[1][0]               
==================================================================================================
Total params: 10,623,801
Trainable params: 3,006
Non-trainable params: 10,620,795
__________________________________________________________________________________________________

我找不到张量密集_1_目标。我不明白它指的是哪一个。

我的数据如下:

image_data = image_generator.flow_from_directory(str(data_root), target_size=IMAGE_SIZE, subset='training')
for image_batch, label_batch in image_data:
print("Image batch shape: ", image_batch.shape) // (32, 224, 224, 3)
print("Label batch shape: ", label_batch.shape) // (32, 3)

现在我可以在哪里放置占位符,以及如何将其与输入数据相关联。

0 个答案:

没有答案