NASNet: You are trying to load a weight file containing 532 layers into a model with 526 layers.

47 篇文章 6 订阅
15 篇文章 1 订阅

NASNet: You are trying to load a weight file containing 532 layers into a model with 526 layers.

1.软件环境    

2.问题描述

3.解决办法

3.1.先不使用预训练权重,使用随机权重来初始化模型

3.2.使用load_weights函数加载预训练权重


1.软件环境    

Windows 10-10.0.17134-SP0

Keras 2.1.6

Python  3.6.3

Tensorflow 1.7.0

2.问题描述

        如题,如果你在使用NASNetLarge时,遇到该问题:

        你肯定会很奇怪为什么官方给出的预训练权重不能加载到模型中去,这个报错显示的意思是模型和训练权重的层数不匹配,一个是532个layers一个是526个layers。

3.解决办法

3.1.先不使用预训练权重,使用随机权重来初始化模型

import numpy as np
from MixupImageDataGenerator import MixupImageDataGenerator
from PIL import ImageFile, Image
from sacred import Experiment
from sacred.observers import MongoObserver
from tensorflow.keras import optimizers
from tensorflow.keras import regularizers
from tensorflow.keras.applications import *
from tensorflow.keras.callbacks import LearningRateScheduler, EarlyStopping, ModelCheckpoint, TensorBoard
from tensorflow.keras.layers import *
from tensorflow.keras.losses import *
from tensorflow.keras.metrics import FalseNegatives, FalsePositives, TrueNegatives, TruePositives, BinaryAccuracy, \
    CategoricalAccuracy, Precision, Recall
from tensorflow.keras.models import *
from tensorflow.keras.preprocessing.image import ImageDataGenerator

base_model = NASNetLarge(weights=None, include_top=False)

3.2.使用load_weights函数加载预训练权重


base_model.load_weights("你的权重路径", by_name=True)

这样就可以使用带有预训练权重的NASNet了!

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

任博啥时候能毕业?

有用的话,请博主喝杯咖啡吧!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值