python - ValueError:检查输入时出错:预期 time_distributed_input 的形状为 (None, 224, 224, 3) 但得到的数组的形状为 (224, 224, 3, 1)
问题描述
我正在尝试使用 CNN-LSTM 对具有形状 (844、224、224、3) 的 rgb 图像数据进行分类。我开始使用代码将其重塑为 (844, 224, 224, 3, 1)
x_train = np.reshape(train_data, (train_data.shape[0], train_data.shape[1], train_data.shape[2], train_data.shape[3], 1))
x_test = np.reshape(test_data, (test_data.shape[0], test_data.shape[1], test_data.shape[2], test_data.shape[3], 1))
然后我使用了下面的模型:
model = Sequential()
model.add(TimeDistributed(Conv2D(64, (3, 3), activation='relu'), input_shape=(None, 224, 224, 3)))
model.add(TimeDistributed(Conv2D(64, (3, 3), activation='relu')))
model.add(TimeDistributed(GlobalAveragePooling2D()))
model.add(LSTM(1024, activation='relu', return_sequences=False))
model.add(Dense(1024, activation='relu'))
model.add(Dropout(.5))
model.add(Dense(3, activation='sigmoid'))
model.compile('adam', loss='categorical_crossentropy')
当我适合模型时
model.fit(x_train, y_tr, epochs=3, validation_data=(x_test, y_ts))
我得到了错误
ValueError: Error when checking input: expected time_distributed_input to have shape (None, 224, 224, 3) but got array with shape (224, 224, 3, 1)
请你帮我解决它。
解决方案
推荐阅读
- python - 不正确的 if-else 语句
- java - 使用 Mockito 2 模拟服务导致存根错误
- java - 两个同步的 ScrollPanes 未对齐
- linked-list - Python链表在末尾删除节点
- excel - 如何在excel vba上简化这个?可能吗?
- sql - mysql错误,springframework.jdbc.BadSqlGrammarException:我收到错误消息,找不到原因
- flutter - 如何将我的列表视图宽度设置为全屏宽度以及如何使其自动滚动
- c - 尝试在 CMake 中将 SDL2_mixer 和 SDL2 添加为 ExternalProject
- android - 我的改造响应正文为空,但它适用于 Postman
- graphql - 如何处理 GraphQL 中的嵌套输入