神经网络+ VGG在测试图像和Google图像上非常准确,但在“真实”图像上却非常差

我制作了一个模型来对猫和狗的图片进行分类。在VGG上对模型进行了转移学习训练,然后对kaggle https://www.kaggle.com/c/dogs-vs-cats/data的猫和猫数据集进行了训练。

我训练了20,000张,然后在剩余的5000张图像上进行了测试。准确率> 95%。当我从Google处抓取一些大约20-200kb的图片时,据我所知,它的效果很好。

但是当图像较大(高度/宽度数千个像素)时,例如从我的手机中拍摄时,它确实很可怕。

为什么会这样?我缺少图像处理功能吗?还是一个学习问题?不管哪种方式,我该如何解决并将模型扩展到大图像?

型号:

def get_transfer_model(self):
        model = VGG16(include_top=False,input_shape=(224,224,3))  # Use VGG transfer model
        for layer in model.layers:
            layer.trainable = False    # already trained

        added_layers = [ 
            flatten(),Dense(512,activation='relu'),BatchNormalization(),Dropout(0.5),Dense(1,activation='sigmoid'))
        ]

        result = model.layers[-1].output # init result
        for layer in added_layers:
            result = layer(result)        # apply to result

        model = Model(inputs=model.inputs,outputs=result)
        opt = SGD(lr=0.001,momentum=0.9)
        model.compile(optimizer=opt,loss='binary_crossentropy',metrics=['accuracy'])
        return model

结果计算:

from keras.preprocessing.image import load_img,img_to_array
from keras.models import load_model

def result(img_path,weights_path='dogs_cats.h5'):
    img = load_img(img_path,target_size=(224,224))
    img = img_to_array(img)
    img = img.reshape(1,244,3) # reshape to tensor with 3 color channels
    img = img.astype('float32')
    img = img - [123.68,116.779,103.939] # center image to trained mean

    model = load_model(weights_path)
    dog = int(model.predict(img)[0][0])
    if dog:
        return 'DOG'
    return 'CAT'
kuaihuoniao 回答:神经网络+ VGG在测试图像和Google图像上非常准确,但在“真实”图像上却非常差

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3077916.html

大家都在问