Keras bug NasNetlarge 没有顶

数据挖掘 机器学习 Python 喀拉斯 卷积神经网络 迁移学习
2022-02-28 02:33:59

我试图NasNetlarge在没有顶部的 Keras 中使用,但我无法摆脱顶部:

from keras.applications import NASNetLarge
model = NASNetLarge(input_shape=(224, 224, 3), include_top=False, 
                    weights="imagenet")

如果我使用 (331, 331, 3) 形状以外的任何形状,include_top=True即使我设置了include_top=False. 如果我将输入形状设置为 (331, 331, 3) 和include_topFalse它会下载顶部的权重。我做错了什么还是 Keras 模块中有错误?

1个回答

你的keras版本是什么?您可以尝试的两件事是:

  1. 将您的 keras 更新到最新版本
  2. 如果以上不行,在keras中打开nasnet.py文件,修改这部分代码:

    elif default_size == 331:  # large version
        if include_top:
            weight_path = NASNET_LARGE_WEIGHT_PATH
            model_name = 'nasnet_large.h5'
        else:
            weight_path = NASNET_LARGE_WEIGHT_PATH_NO_TOP
            model_name = 'nasnet_large_no_top.h5'
    
        weights_file = get_file(model_name, weight_path,
                                cache_subdir='models')
        model.load_weights(weights_file)
    

    对此:

    elif default_size == 331:  # large version
        if include_top:
            weight_path = NASNET_LARGE_WEIGHT_PATH
            model_name = 'nasnet_large.h5'
        else:
            weight_path = NASNET_LARGE_WEIGHT_PATH_NO_TOP
            model_name = 'nasnet_large_no_top.h5'
    
        weights_file = get_file(model_name, weight_path,
                                cache_subdir='models')
        model.load_weights(weights_file, by_name = True)