我正在尝试将此tflearn DCNN示例(使用图像预处理和augmemtation)转换为keras:Tflearn示例:import tflearnfrom tflearn.data_utils import shuffle, to_categoricalfrom tflearn.layers.core import input_data, dropout, fully_connectedfrom tflearn.layers.conv import conv_2d, max_pool_2dfrom tflearn.layers.estimator import regressionfrom tflearn.data_preprocessing import ImagePreprocessingfrom tflearn.data_augmentation import ImageAugmentation# Data loading and preprocessingfrom tflearn.datasets import cifar10(X, Y), (X_test, Y_test) = cifar10.load_data()X, Y = shuffle(X, Y)Y = to_categorical(Y, 10)Y_test = to_categorical(Y_test, 10)# Real-time data preprocessingimg_prep = ImagePreprocessing()img_prep.add_featurewise_zero_center()img_prep.add_featurewise_stdnorm()# Real-time data augmentationimg_aug = ImageAugmentation()img_aug.add_random_flip_leftright()img_aug.add_random_rotation(max_angle=25.)# Convolutional network buildingnetwork = input_data(shape=[None, 32, 32, 3], data_preprocessing=img_prep, data_augmentation=img_aug)network = conv_2d(network, 32, 3, activation='relu')network = max_pool_2d(network, 2)network = conv_2d(network, 64, 3, activation='relu')network = conv_2d(network, 64, 3, activation='relu')network = max_pool_2d(network, 2)network = fully_connected(network, 512, activation='relu')network = dropout(network, 0.5)50个纪元后产生了以下结果:Training Step: 26050 | total loss: 0.35260 | time: 144.306s| Adam | epoch: 050 | loss: 0.35260 - acc: 0.8785 | val_loss: 0.64622 - val_acc: 0.8212 -- iter: 50000/50000然后,我尝试使用相同的DCNN图层,参数和图像预处理/增强功能将其转换为Keras这会产生差得多的验证准确性结果:Epoch 50/50521/521 [==============================] - 84s 162ms/step - loss: 0.4723 - acc: 0.8340 - val_loss: 3.2970 - val_acc: 0.2729Test score: 3.2969648239135743Accuracy: 27.29%谁能帮我理解原因?我在Keras中是否误用了/误解了图像预处理/增强功能?
1 回答
桃花长相依
TA贡献1860条经验 获得超8个赞
在Keras模型中,您也忘记了标准化验证数据。您可以通过使用训练数据datagen.mean并对其进行datagen.std计算来做到这一点:
# normalize test data; add a small constant to avoid division by zero,
# you can alternatively use `keras.backend.epsilon()`
X_test = (X_test - datagen.mean) / (datagen.std + 1e-8)
或者您可以使用该datagen.standardize()方法对测试数据进行规范化:
X_test = datagen.standardize(X_test)
有关更多信息,请参见SO上的这个问题:预测期间,数据标准化如何在keras中起作用?
别忘了您应该通过对训练数据计算出的统计数据对测试数据进行归一化。永远不要通过自己的统计数据对测试数据进行归一化。
警告:似乎也standardize 改变了它的参数...是的,您可以在源代码中确认这一点。
添加回答
举报
0/150
提交
取消