【发布时间】:2020-10-15 20:11:25
【问题描述】:
# Creating a Sequential Model and adding the layers
input_img = Input(shape=(28, 28, 1))
#63 kernels - Conv of 3X3
conv_1 = Conv2D(63, kernel_size=(3,3),activation='relu', padding='same')(input_img)
#Then pooling of 2X2
encoded = MaxPooling2D((2, 2), padding='same')(conv_1)
#model.add(Dropout(0.2))
###Classification###
# Flattening the 2D arrays for fully connected layers
flatten = Flatten()(encoded)
# Adding dense layer
fc = Dense(1000, activation='relu')(flatten)
fc1 = (Dropout(0.2))(fc)
#A6 = model.add(Dropout(0.2),name = 'A6') #Combat Overfitting, drop random elements
#Softmax layer must have neurons = range of labels, 0-9 for this case
softmax = Dense(5, activation='softmax', name='classification')(fc1)
model = Model(inputs=input_img, outputs=[softmax])
当我运行 model.fit 模型时,出现以下错误:
ValueError: Data cardinality is ambiguous:
x sizes: 30703
y sizes: 30703, 51660
Please provide data which shares the same first dimension.
我想要实现的是,我正在尝试在 mnist 数据集上运行 keras 分类,并且我已经删除了一些数字,只剩下 0、1、2、3、9,总共 5 个整数,我需要对整数进行索引,这样我就可以输出 5 个输出的密集层,而不必坚持 10(覆盖整数 9)。我已经完成了以下操作,但出现上述错误,请告知谢谢
# Transform y_train (and similarly y_test).
uniquetrain, index = np.unique(y_train, return_inverse=True)
y_train = np.arange(len(uniquetrain))[index]
# To get back the original labels, just index into the unique values.
unique[y_train]
# Transform y_train (and similarly y_test).
uniquetest, index1 = np.unique(y_test, return_inverse=True)
y_test = np.arange(len(uniquetest))[index1]
# To get back the original labels, just index into the unique values.
unique[y_test]
【问题讨论】:
标签: python keras classification