尝试拟合模型python时出现A​​ssertionError

时间:2018-08-16 06:58:15

标签: python neural-network keras

在尝试拟合模型时,我一直遇到AssertionError。我在Python引发AssertionError时做了一些阅读。积压如下

File "G:/test3/main.py", line 167, in <module>
model.fit([images, captions], next_words, batch_size=128, epochs=50)

File "C:\Users\Acer\Anaconda3\lib\site-packages\keras\engine\training.py", line 950, in fit
batch_size=batch_size)

File "C:\Users\Acer\Anaconda3\lib\site-packages\keras\engine\training.py", line 671, in _standardize_user_data
self._set_inputs(x)

File "C:\Users\Acer\Anaconda3\lib\site-packages\keras\engine\training.py", line 575, in _set_inputs
assert len(inputs) == 1

AssertionError

我的代码如下

model=Sequential()

model.add(Concatenate([image_model, language_model]))
model.add(LSTM(1000, return_sequences=False))
model.add(Dense(vocab_size))
model.add(Activation('softmax'))
model.compile(loss='categorical_crossentropy', optimizer=Nadam(), metrics=['accuracy'])

model.fit([images, captions], next_words, batch_size=5, epochs=50)
model.summary()

model.save_weights("./models/vgg16_weights_tf_dim_ordering_tf_kernels.h5")

图像的形状为(18724,1000),标题的形状为(18724,43)

1 个答案:

答案 0 :(得分:1)

您收到此错误,是因为您没有为模型指定任何输入,而Keras尝试在调用procedure TForm1.FormClick(Sender: TObject); begin DateTimePicker1.MaxDate := IncDay(Now, 4); // DateTimePicker1.ResetRange; // uncomment to see resetting in action end; 时设置它们。之所以存在断言,是因为包装在model.fit()容器中的每个模型应仅接受一个输入。

要实现所需的功能,您可能想要使用Keras的Functional API而不是Sequential API。遵循以下原则:

Sequential