我正在嘗試調整Keras MNIST Siamese 示例以使用生成器。在示例中,我們有:model.fit([tr_pairs[:, 0], tr_pairs[:, 1]], tr_y, batch_size=128, epochs=epochs, validation_data=([te_pairs[:, 0], te_pairs[:, 1]], te_y))試圖找出生成器需要返回的形狀,我做了:np.array([tr_pairs[:, 0], tr_pairs[:, 1]]).shape并得到(2, 108400, 28, 28)我的生成器然后返回這個:(data, labels) = my_generatordata.shape(2, 6, 300, 300, 3)labels.shape(6,)因此,它是兩個數組(用于 NN 輸入),具有 6 個大小為300x300x3(RGB) 的圖像 (batch_size )。下面是fit_generator()用法:...input_shape = (300, 300, 3)...model.fit_generator(kbg.generate(set='train'), steps_per_epoch=training_steps, epochs=1, verbose=1, callbacks=[], validation_data=kbg.generate(set='test'), validation_steps=validation_steps, use_multiprocessing=False, workers=0) 我想我正在為 NN 提供相同的形狀,但出現以下錯誤:ValueError: Error when checking model input: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 2 array(s), but instead gotthe following list of 1 arrays: [array([[[[[0.49803922, 0.48235294, 0.55686275], [0.63137255, 0.61176471, 0.64313725], [0.8627451 , 0.84313725, 0.84313725], ..., [0.58823529, 0.64705882, 0.631...怎么了?
1 回答

慕村9548890
TA貢獻1884條經驗 獲得超4個贊
由于模型有兩個輸入層,生成器應該生成一個包含兩個數組的列表作為兩個輸入層對應的輸入樣本,如下所示:
def my_generator(args):
# ...
yield [first_pair, second_pair], labels
其中first_pair和second_pair都具有 的形狀(n_samples, 300, 300, 3)。
添加回答
舉報
0/150
提交
取消