python - 与图层 CNN 多类分类算法不兼容?
问题描述
我想用这个数据包brain 4 data chanel(train data(X_train): 10 * 4 - in here 1 parameter is a T1 canal data, 2 - T2, 3- T1C, 4 - Flair), X_test 是ground truth . 但我不知道如何正确设置模型。
训练数据:
X_train([[0.487, 0.453, 0.375, 0.484],
[0.423, 0.57 , 0.289, 0.829],
[0.359, 0.921, 0.247, 1. ],
[0.497, 0.509, 0.472, 0.545],
[0.49 , 0.438, 0.435, 0.419],
[0.304, 0.713, 0.225, 1. ],
[0.441, 0.566, 0.41 , 0.655],
[0.522, 0.445, 0.435, 0.5 ],
[0.604, 0.506, 0.55 , 0.581],
[0.251, 0.46 , 0.461, 0.31 ]])
X_test([0., 2., 2., 0., 0., 2., 0., 0., 0., 0.])
测试数据:
y_train([[0.455, 0.377, 0.371, 0.597],
[0.492, 0.6 , 0.487, 0.594],
[0.407, 0.596, 0.711, 0.681],
[0.664, 0.37 , 0.733, 0.342],
[0.418, 0.63 , 0.504, 0.606],
[0.366, 0.947, 0.272, 1. ],
[0.559, 0.442, 0.539, 0.584],
[0.655, 0.362, 0.645, 0.594],
[0.6 , 0.506, 0.447, 0.548],
[0.715, 0.43 , 0.661, 0.432]])
y_test([0., 0., 2., 0., 0., 2., 0., 0., 0., 0.])
这是我的卷积神经网络:
def baseline_model():
# Create the model
model = Sequential()
model.add(Conv1D(32, 10 ,input_shape=(10,4), padding='same', activation='relu'))
model.add(Dropout(0.2))
model.add(Conv1D(32, 10, padding='same', activation='relu'))
model.add(MaxPooling1D(pool_size=(2, 2)))
model.add(Flatten())
model.add(Dense(512, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(4, activation='softmax'))
# Compile model
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
print(model.summary())
return model
#Fitt the model
h = model.fit(X_train, X_test, epochs=10, batch_size=4)
我收到以下错误
ValueError: 层序贯_74 的输入 0 与层不兼容::预期 min_ndim=3,发现 ndim=2。收到的完整形状:(无,4)
怎么了?请帮忙。
解决方案
推荐阅读
- javascript - 从 XML 获取数据并在 HTML 上显示 - 输入变量
- javascript - 如何自定义视频全屏?
- token - 当我将 CLI 与 CI 系统一起使用时,我没有获得令牌
- kubernetes - 如何保护 Istio Operator?
- android - @Compose 生成的代码位于 android 项目文件夹结构中的什么位置?
- r - 关于 Tibble 的基本了解
- java - 使用 OOPS 概念和 Java 最佳实践设计高级模式
- python-3.x - discord.py gif 命令不发送 gif
- swift - 如何为堆栈视图设置约束?
- python - VSCode 中的 Python:为什么单元格输出可以设置为 HTML,而其他的只能设置为文本?