[keras] 模型保存、加载、model类方法、打印各层权重

本文介绍了Keras中模型的保存和加载,强调了在加载权重前需先编译模型。同时,对比了sequential和functional两种模型的区别,并详细阐述了model类的方法,包括如何获取和打印各层权重。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.模型保存

model.save_model()可以保存网络结构权重以及优化器的参数
model.save_weights() 仅仅保存权重

2.模型加载

from keras.models import load_model
load_model()只能load 由save_model保存的,将模型和weight全load进来

 filepath: String, path to the saved model.
 custom_objects: Optional dictionary mapping names
     (strings) to custom classes or functions to be
     considered during deserialization.
 compile: Boolean, whether to compile the model
     after loading.

model.load_weights(self, filepath, by_name=False):
在加载权重之前,model必须编译好

        metrics = ['accuracy']
        if self.nb_classes >= 10:
            metrics.append('top_k_categorical_accuracy')

       # self.input_shape = (seq_length, features_length)
        self.model,self.original_model = self.zf_model()
        optimizer 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值