input_image = Input(shape=(L, H)) dropout1 = Dropout(0.25)(input_image) dense1 = Dense(4096, input_shape=(L, H) , activation='relu')(dropout1) bn1 = BatchNormalization(momentum=0.93, axis=-1)(dense1) dropout2 = Dropout(0.25)(bn1) dense2 = Dense(4096, activation='relu')(dropout2) bn2 = BatchNormalization(momentum=0.93, axis=-1)(dense2) dropout3 = Dropout(0.25)(bn2) dense3 = Dense(35, activation='relu')(dropout3) input_numeric = Input(shape=(M,N)) concat = K.concatenate([input_numeric, dense3], axis=2) bn4 = BatchNormalization(momentum=0.93, axis=-1)(concat) dropout4 = Dropout(0.5)(bn4) output = Dense(26, activation='softmax')(dropout4) model = Model(inputs=[input_image, input_numeric], outputs=output) model.compile(loss='categorical_crossentropy', optimizer=Adam(lr=0.001), metrics=['accuracy']) model.fit([train_img_x, train_data_x], train_y, batch_size=15, epochs=10, validation_split=0.2) prediction = model.predict([train_img_x, train_data_x]) 报错`validation_split` is only supported for Tensors or NumPy arrays, found following types in the input: [<class 'torch.Tensor'>, <class 'torch.Tensor'>] ,如何解决
时间: 2024-01-28 07:04:43 浏览: 129
使用keras框架cnn+ctc_loss识别不定长字符图片操作
这个错误提示表明 `validation_split` 参数只支持 Tensor 或 NumPy 数组类型,但是这里输入的类型是 Torch Tensor。因此,需要将输入类型转换为 NumPy 数组类型。可以使用 `.numpy()` 方法将 Torch Tensor 转换为 NumPy 数组,例如:
```
prediction = model.predict([train_img_x.numpy(), train_data_x.numpy()])
```
这样就可以将 Torch Tensor 转换为 NumPy 数组,然后传递给 `predict` 方法进行预测。
阅读全文