我尝试使用自定义数据集(由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)

最佳答案

您的问题在于,根据Keras InceptionV3 documentation的要求-最小输入大小为139。因此-由于您的网络输入大小为64,因此您的网络无法正常运行。要解决此问题:


将输入大小更改为n,其中n > 139
在每个flow_from_directory中-将target_size更改为(n, n)

关于python - InceptionV3微调:为什么使用InceptionV3微调会获得非常低的(.37)精度?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44879991/

10-09 01:31