[英]How to solve the shapes of model are incompatible?
This is my train & test split shape:这是我的训练和测试拆分形状:
print(X_train.shape)
print(X_test.shape)
print(y_train.shape)
print(y_test.shape)
----------------------
(120000, 72)
(12000, 72)
(120000, 6)
(12000, 6)
I reshape the data for CNN:我为 CNN 重塑数据:
X_train = X_train.reshape(len(X_train), X_train.shape[1], 1)
X_test = X_test.reshape(len(X_test), X_test.shape[1], 1)
X_train.shape, X_test.shape
-------------------------------------------------------------------
((120000, 72, 1), (12000, 72, 1))
Making the deep learning function:制作深度学习 function:
def model():
model = Sequential()
model.add(Conv1D(filters=64, kernel_size=6, activation='relu',
padding='same', input_shape=(72, 1)))
model.add(BatchNormalization())
# adding a pooling layer
model.add(MaxPooling1D(pool_size=(3), strides=2, padding='same'))
model.add(Conv1D(filters=64, kernel_size=6, activation='relu',
padding='same', input_shape=(72, 1)))
model.add(BatchNormalization())
model.add(MaxPooling1D(pool_size=(3), strides=2, padding='same'))
model.add(Conv1D(filters=64, kernel_size=6, activation='relu',
padding='same', input_shape=(72, 1)))
model.add(BatchNormalization())
model.add(MaxPooling1D(pool_size=(3), strides=2, padding='same'))
model.add(Flatten())
model.add(Dense(64, activation='relu'))
model.add(Dense(64, activation='relu'))
model.add(Dense(3, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
return model
When i fit it shows error: Shapes (32, 6) and (32, 3) are incompatible当我适合时它显示错误:Shapes (32, 6) and (32, 3) are incompatible
model = model()
model.summary()
logger = CSVLogger('logs.csv', append=True)
his = model.fit(X_train, y_train, epochs=30, batch_size=32,
validation_data=(X_test, y_test), callbacks=[logger])
---------------------------------------------------------------
ValueError: Shapes (32, 6) and (32, 3) are incompatible
What problem and how can i solve it?什么问题,我该如何解决?
Your targets are 6 dimensional, but your prediction is 3 dimensional, thus the mismatch.您的目标是 6 维的,但您的预测是 3 维的,因此不匹配。 You should have Dense(6) as the last layer of your model, not Dense(3)您应该将 Dense(6) 作为 model 的最后一层,而不是 Dense(3)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.