为了账号安全,请及时绑定邮箱和手机立即绑定

使用自定义数据集进行人脸识别而不是 MNIST

使用自定义数据集进行人脸识别而不是 MNIST

茅侃侃 2021-10-26 10:20:57
我想使用包含不同人脸图像的自定义数据集。我计划使用 CNN 和堆叠自动编码器对我的图像进行分类。我应该改变 (x_train, _), (x_test, _) = mnist.load_data() 吗?或更改 input_img ,我认为问题出在输入数据上,但我不知道应该在哪里修改。我迷路了,我需要帮助。from keras.layers import Input, Dense, Conv2D, MaxPooling2D, UpSampling2Dfrom keras.models import Modelfrom keras import backend as Kinput_img = Input(shape=(28, 28, 1))  # adapt this if using`channels_first` image data formatx = Conv2D(16, (3, 3), activation='relu', padding='same')(input_img)x = MaxPooling2D((2, 2), padding='same')(x)x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)x = MaxPooling2D((2, 2), padding='same')(x)x = Conv2D(8, (3, 3), activation='relu', padding='same')(x) encoded = MaxPooling2D((2, 2), padding='same')(x)# at this point the representation is (4, 4, 8) i.e. 128-dimensionalx = Conv2D(8, (3, 3), activation='relu', padding='same')(encoded)x = UpSampling2D((2, 2))(x)x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)x = UpSampling2D((2, 2))(x)x = Conv2D(16, (3, 3), activation='relu')(x)x = UpSampling2D((2, 2))(x)decoded = Conv2D(1, (3, 3), activation='sigmoid', padding='same')(x)autoencoder = Model(input_img, decoded)autoencoder.compile(optimizer='adadelta', loss='binary_crossentropy')from keras.datasets import mnistimport numpy as np(x_train, _), (x_test, _) = mnist.load_data()x_train = x_train.astype('float32') / 255.x_test = x_test.astype('float32') / 255.x_train = np.reshape(x_train, (len(x_train), 28, 28, 1))  # adapt this if using `channels_first` image data formatx_test = np.reshape(x_test, (len(x_test), 28, 28, 1))  # adapt this if using `channels_first` image data formatfrom keras.callbacks import TensorBoardautoencoder.fit(x_train, x_train,               epochs=50,               batch_size=128,               shuffle=True,               validation_data=(x_test, x_test),               callbacks=[TensorBoard(log_dir='/tmp/autoencoder')])decoded_imgs = autoencoder.predict(x_test)
查看完整描述

2 回答

?
一只斗牛犬

TA贡献1784条经验 获得超2个赞

您需要使用数据加载器更改 (x_train, _), (x_test, _) = mnist.load_data() 。您可以使用 kerasImageDataGenerator类来完成此操作或构建您自己的. 如果您的图像尺寸远大于28 x 28您可能需要更改模型架构,因为直接28 x 28将它们重塑为不会产生好的结果。


查看完整回答
反对 回复 2021-10-26
?
慕田峪7331174

TA贡献1828条经验 获得超13个赞

您需要加载数据集并将其拆分为两个子集:x_trainx_test.

您的数据以哪种格式存储?


查看完整回答
反对 回复 2021-10-26
  • 2 回答
  • 0 关注
  • 196 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信