所以我花了很多时间在这个图像分类模型上。我有70000张图像和375个类。我试着用Vgg 16,Xception,Resnet和Mobilenet训练它......我总是得到相同的45%的验证限制。
As you can see here
我试过添加丢失层和正则化,它得到了相同的验证结果,数据扩增也没有多大帮助,你知道为什么这不起作用吗?
下面是我使用的上一个模型的代码片段:
from keras.models import Sequential
from keras.layers import Dense
from tensorflow import keras
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from keras import regularizers
from PIL import Image
from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True
validation_datagen = ImageDataGenerator(rescale=1./255)
target_size = (height, width)
datagen = ImageDataGenerator(rescale=1./255,
validation_split=0.2)
train_generator = datagen.flow_from_directory(
path,
target_size=(height, width),
batch_size=batchSize,
shuffle=True,
class_mode='categorical',
subset='training')
validation_generator = datagen.flow_from_directory(
path,
target_size=(height, width),
batch_size=batchSize,
class_mode='categorical',
subset='validation')
num_classes = len(train_generator.class_indices)
xception_model = Xception(weights='imagenet',input_shape=(width, height, 3), include_top=False,classes=num_classes)
x = xception_model.output
x = GlobalAveragePooling2D()(x)
x = Dense(512, activation='relu')(x)
out = Dense(num_classes, activation='softmax')(x)
opt = Adam()
model.compile(optimizer=opt, loss='categorical_crossentropy', metrics=['accuracy'])
n_时间点= 15
历史记录=model.fit(训练生成器,每个epoch的步骤数=训练生成器.样本//批次大小,验证数据=验证生成器,验证步骤数=验证生成器.样本//批次大小,详细信息=1,epoch = n_epoch)
1条答案
按热度按时间vmdwslir1#
是的,您可能需要数据集中每个类别之间的平衡数据集,以获得更好的模型训练性能。请通过更改
class_mode='sparse'
和loss='sparse_categorical_crossentropy'
重试,因为您正在使用图像数据集。另外,冻结预训练模型层'xception_model.trainable = False'
。检查以下代码:(我使用了5个类的花卉数据集)
输出: