使用InceptionV3,VGG16进行多类分类,具有101个分类的准确性非常低 [英] Multi class classification using InceptionV3,VGG16 with 101 classes very low accuracy

查看:133
本文介绍了使用InceptionV3,VGG16进行多类分类,具有101个分类的准确性非常低的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试建立具有101个类别的食物分类模型.数据集每个类别有1000张图像.我训练的模型的准确性不到6%.我曾尝试使用imagenet权重实现NASNet和VGG16,但准确性并未提高.我尝试使用带有或不带有amsgrad的Adam优化器.我也曾尝试将学习率更改为0.01和0.0001,但仍然将精度保持在单位数内.请提出将精度提高到至少60%的方法.由于硬件限制(Macbook air 2017),我无法训练非常深的模型.

I am trying to build a food classification model with 101 classes. The dataset has 1000 image for each class. The accuracy of the model which I trained is coming less than 6%. I have tried implementing NASNet and VGG16 with imagenet weights but the accuracy did not increase. I have tried using Adam optimizer with or without amsgrad. I have also tried to change the learning rate to both 0.01 and 0.0001 but still, accuracy remains in the single-digit.Please suggest the methods to increase the accuracy to at least 60 percent. Due to hardware restriction(Macbook air 2017) I cannot train very deep model.

数据集: https://www.kaggle.com/kmader/food41

import tensorflow as tf
from tensorflow.keras.applications.inception_v3 import InceptionV3


train_data_dir=".../food_data/images"

data=tf.keras.preprocessing.image.ImageDataGenerator(
    featurewise_center=False,
    samplewise_center=False,
    featurewise_std_normalization=False,
    samplewise_std_normalization=False,
    zca_whitening=False,
    zca_epsilon=1e-06,
    rotation_range=45,
    width_shift_range=0.2,
    height_shift_range=0.2,
    brightness_range=None,
    shear_range=0.2,
    zoom_range=0.2,
    channel_shift_range=0.0,
    fill_mode="nearest",
    cval=0.0,
    horizontal_flip=True,
    vertical_flip=True,
    rescale=1./255,
)
datagen=data.flow_from_directory(
        train_data_dir,
        target_size=(360, 360),
        batch_size=10,
        class_mode='categorical')


base_model = InceptionV3(weights='imagenet',input_shape=(360,360,3), include_top=False)

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


x = base_model.output
x = tf.keras.layers.GlobalAveragePooling2D()(x)
x = tf.keras.layers.Dropout(0.3)(x)
x = tf.keras.layers.Dense(1024, activation='relu')(x)
x = tf.keras.layers.BatchNormalization()(x)
x = tf.keras.layers.Dense(512, activation='relu')(x)
x = tf.keras.layers.Dense(256, activation='relu')(x)
predictions = tf.keras.layers.Dense(101, activation='softmax')(x)
model = tf.keras.models.Model(inputs=base_model.input, outputs=predictions)

adam=tf.keras.optimizers.Adam(
    learning_rate=0.001,
    beta_1=0.9,
    beta_2=0.999,
    epsilon=1e-07,
    amsgrad=False,
    name="Adam",
)

model.compile(optimizer='rmsprop', loss='categorical_crossentropy',metrics=['accuracy'])
model.fit_generator(datagen,steps_per_epoch=100,epochs=50)

model.save('trained_food_new.h5')

推荐答案

几乎没有什么可以提高分类准确性的:

There are few that may improve the classification accuracy:

  1. 使用带有nosy_student权重的EfficientNet.需要训练的参数数量较少.由于它具有可伸缩的体系结构,因此具有更高的准确性.

  1. Use EfficientNet with noisy_student weights. There are less number of parameters to train. It gives better accuracy due to the scalable architecture it has.

您可以使用测试时间增加.在测试数据生成器中,执行简单的水平翻转,垂直翻转(如果数据看起来逼真)和仿射变换.它将生成数据的多个视图,并帮助模型对更可能的类进行平均.

You can use test time augmentation. In your test data generator, do a simple horizontal flip, vertical flip (if data looks realistic) and affine transformations. It will generate multiple views of the data and helps the model to average out more probable class.

签出图像库(压纹,锐化,添加噪点等).另外,还提供了random_eraser,剪切和混合策略,这些方法已被证明是有用的.

Checkout imgaug library (embossing, sharpening, noise addition, etc.). Plus, there are random_eraser, cut out and mix up strategies that have been proved to be useful.

尝试平滑标签.它还可以帮助您的分类器为正确的分类提供更多的可能性.

Try label smoothing. It can also help your classifier to give more probability to the correct class.

尝试学习率预热.像这样的东西:

Try learning rate warmup. Something like this:

LR_START = 0.0001
LR_MAX = 0.00005
LR_MIN = 0.0001
LR_RAMPUP_EPOCHS = 4
LR_SUSTAIN_EPOCHS = 6
LR_EXP_DECAY = .8


def lrfn(epoch):
    if epoch < LR_RAMPUP_EPOCHS:
        lr = (LR_MAX - LR_START) / LR_RAMPUP_EPOCHS * epoch + LR_START
    elif epoch < LR_RAMPUP_EPOCHS + LR_SUSTAIN_EPOCHS:
        lr = LR_MAX
    else:
        lr = (LR_MAX - LR_MIN) * LR_EXP_DECAY**(epoch - LR_RAMPUP_EPOCHS - LR_SUSTAIN_EPOCHS) + LR_MIN
    return lr

  1. 您还可以提取特征并应用整体特征分类(XGBoost,Adaboost,BaggingClassifier)或三元组损失.

这篇关于使用InceptionV3,VGG16进行多类分类,具有101个分类的准确性非常低的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆