Inception V3微调:为什么我在InceptionV3微调中获得非常低的(0.37)准确度?

3

我尝试用自定义数据集(包含2个类别)对InceptionV3模型进行微调,但在训练和验证过程中都获得了非常低的准确性。我应该怎么做才能提高准确性?或者您有其他网络思路/实现来达到此目的吗?

我的代码:

from keras.datasets import cifar10
from keras.utils import *
from keras.optimizers import SGD
from keras.layers import  Input,Dense,Flatten,Dropout,GlobalAveragePooling2D
from keras.preprocessing.image import ImageDataGenerator
from keras.preprocessing import image
from keras.applications.vgg16 import preprocess_input
from keras.models import Model
from keras.applications.inception_v3 import InceptionV3
import numpy as np
import cv2

epochs = 10
steps_per_epoch  = 300
validation_steps = 300
input_shape=(64, 64, 3)
image_rows=64
image_cols=64

train_datagen = ImageDataGenerator(
    rescale=1./255,
    shear_range=0.2,
    zoom_range=0.2,
    horizontal_flip=True)

test_datagen = ImageDataGenerator(rescale=1./255)

train_generator = train_datagen.flow_from_directory(
    'dataset/train',
    target_size=(image_rows, image_cols),
    batch_size=32,
    class_mode='categorical')

validation_generator = test_datagen.flow_from_directory(
    'dataset/evaluate',
    target_size=(image_rows, image_cols),
    batch_size=32,
    class_mode='categorical')


inputs = Input(shape=input_shape)

base_model = InceptionV3(weights='imagenet', include_top=False)
x = base_model.output
x = GlobalAveragePooling2D()(x)
x = Dense(1024, activation='relu')(x)
predictions = Dense(2, activation='softmax')(x)
model = Model(input=base_model.input, output=predictions)


for layer in base_model.layers:
  layer.trainable = False


model.compile(
    optimizer='rmsprop', 
    loss='categorical_crossentropy',
    metrics=['accuracy'])


model.fit_generator(
        train_generator,
        steps_per_epoch=steps_per_epoch,
        epochs=epochs,
        validation_data=validation_generator,
        validation_steps=validation_steps)

1
你能打印出你的 model.summary() 吗?看起来你的输入对于 Inception 来说太小了。 - Marcin Możejko
抱歉,文本内容过长无法在此处发布。 - Oguzhan
使用例如 Pastebin。 - Marcin Możejko
https://ufile.io/gv9l7 - Oguzhan
现在我将步数更改为150,每次验证准确性都为0.4615,即使训练准确性较小且不稳定。 - Oguzhan
1个回答

3

你的问题在于,根据Keras InceptionV3文档 - 最小输入尺寸是139。因此,由于您的网络输入尺寸为64,您的网络表现不佳。要解决这个问题:

  • 将输入尺寸更改为n,其中n > 139
  • 在每个flow_from_directory中,将target_size更改为(n, n)

谢谢您的回复!我一旦尝试了您的解决方案,就会给出反馈! - Oguzhan
前六个时期的结果为:0.4615、0.69、0.77、0.58、0.58、0.38。不确定是由于输入格式还是我的网络引起的。 - Oguzhan
将 Dense 大小减少到 128。 - Marcin Możejko
0.77 似乎是最高的准确率。也许这是由于我的自定义数据集造成的。你有其他的建议吗? - Oguzhan
救了我!提醒那些使用tf lib中的inception模型,如果你有小图像,请设置以下参数。 MODEL_INPUT_WIDTH = 250 MODEL_INPUT_HEIGHT = 188 - Eddie

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接