【问题标题】:ValueError: Input arrays should have the same number of samples as target arrays. Found 1280 input samples and 320 target samplesValueError:输入数组应具有与目标数组相同数量的样本。找到 1280 个输入样本和 320 个目标样本
【发布时间】:2020-08-31 17:35:26
【问题描述】:
这段代码有什么问题? faces = datasets.fetch_oliveti_faces() X_train, X_test, y_train, y_test = train_test_split(faces.data,faces.target, test_size=0.2) X_train = X_train.reshape(-1,32 ,32 ,1) X_test = X_test.reshape(-1,32 , 32 ,1) # 规范化数据 X_train = X_train.astype('float32') X_test = X_test.astype('float32') X_train /= 255.0 X_test /= 255.0 # 一热 班级=40 y_train = keras.utils.to_categorical(y_train, 类) y_test = keras.utils.to_categorical(y_test, 类) #使用 Keras 构建 LetNet 模型 def LetNet(宽度,高度,深度,类): # 初始化模型 模型=顺序() # 第一层,卷积和池化 model.add(Conv2D(input_shape=(width, height, depth), kernel_size=(5, 5), filters=6, strides=(1,1), activation='tanh')) model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2))) # 第二层,卷积和池化 model.add(Conv2D(input_shape=(width, height, depth), kernel_size=(5, 5), filters=16, strides=(1,1), activation='tanh')) model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2))) # 全连接层 model.add(展平()) model.add(密集(120,激活='tanh')) model.add(密集(84,激活='tanh')) # softmax分类器 model.add(密集(类)) model.add(激活(“softmax”)) 返回模型 LetNet_model = LetNet(32,32,1,40) LetNet_model.summary() #Strat训练 LetNet_model.compile(optimizer=Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=1e-08),loss = 'categorical_crossentropy',metrics=['accuracy']) History = LetNet_model.fit(X_train, y_train, epochs=5, batch_size=32,validation_data=(X_test, y_test))

【问题讨论】:

  • 你能打印X_train.shapey_train.shape吗?

标签: python keras deep-learning face-recognition


【解决方案1】:

我的计算表明,您的输入图像的形状为 64 x 64 和 1 个通道,而不是 32 x 32。

您可以更改以下几行。

    X_train = X_train.reshape(-1, 64 ,64 ,1)
    X_test = X_test.reshape(-1, 64 , 64 ,1)

另外,更改您的模型输入。

LetNet_model = LetNet(64,64,1,40)

【讨论】:

    猜你喜欢
    • 2023-03-10
    • 2019-05-30
    • 2018-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-15
    • 2017-10-26
    • 2019-05-22
    相关资源
    最近更新 更多