我有一個(gè)多輸入 Keras 模型。這里的輸入:[<tf.Tensor 'input_1:0' shape=(None, 256, 256, 3) dtype=float32>, <tf.Tensor 'input_2:0' shape=(None, 256, 256, 3) dtype=float32>, <tf.Tensor 'input_3:0' shape=(None, 256, 256, 3) dtype=float32>, <tf.Tensor 'input_4:0' shape=(None, 256, 256, 3) dtype=float32>]這里是模型的輸入形狀:[(None, 256, 256, 3), (None, 256, 256, 3), (None, 256, 256, 3), (None, 256, 256, 3)]訓(xùn)練數(shù)據(jù)形狀如下:(4, 422, 256, 256, 3)4 = number of inputs (consist of appended arrays together).422 = number of training images in each input.256, 256, 3 = shape of the images當(dāng)我調(diào)用該fit函數(shù)時(shí):model.fit(train_x, train_y, validation_split=0.20, epochs=5, batch_size=3)出現(xiàn)以下錯(cuò)誤:ValueError:層 conv1_pad_0 的輸入 0 與該層不兼容:預(yù)期 ndim=4,發(fā)現(xiàn) ndim=5。收到的完整形狀:[3, 422, 256, 256, 3]我已經(jīng)嘗試過這篇文章中給出的解決方案,但我發(fā)現(xiàn)基數(shù)不匹配。ValueError:數(shù)據(jù)基數(shù)不明確:我嘗試過像下面這樣傳遞火車數(shù)據(jù),它有效:model.fit([train_x[0], train_x[1], train_x[2], train_x[3]], train_y, validation_split=0.20, epochs=5, batch_size=3)現(xiàn)在,如果我想將模型擴(kuò)展到 20 個(gè)輸入,上面的代碼行將會(huì)出現(xiàn)問題。更新:該模型基于預(yù)訓(xùn)練的ResNet50,所有輸入都是沒有頂層的 resnet50 ,并從以下三層開始:input_1_0 (InputLayer) [(None, 256, 256, 3) 0 conv1_pad_0 (ZeroPadding2D) (None, 262, 262, 3) 0 input_1_0[0][0]conv1_conv_0 (Conv2D) (None, 128, 128, 64) 9472 conv1_pad_0[0][0] 用于訓(xùn)練/測(cè)試模型的數(shù)據(jù)處理如下:for row in np.array(tmp_data): row = images_preprocessing(row) # Depends on the model used train_x, test_x, train_y, test_y = split_data(row, target) # Here the train_test_split is used train_X.append(train_x) test_X.append(test_x) train_Y.append(train_y) test_Y.append(test_y)
1 回答

繁華開滿天機(jī)
TA貢獻(xiàn)1816條經(jīng)驗(yàn) 獲得超4個(gè)贊
嘗試
train_x_list = [tf.squeeze(tx) for tx in tf.split(train_x, num_or_size_splits=train_x.shape[0], axis=0)]
它將生成一個(gè)張量列表,其中訓(xùn)練數(shù)據(jù)沿維度 0 分割。然后使用第二個(gè)解決方案,將列表提供給fit()
。
添加回答
舉報(bào)
0/150
提交
取消