我想使用包含不同人脸图像的自定义数据集。我计划使用 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)
添加回答
举报
0/150
提交
取消