【翻译】Serialization semantics 序列化语义

参考链接: Serialization semantics

在这里插入图片描述

原文及翻译:


Serialization semantics  序列化语义
Best practices  最佳惯例
Recommended approach for saving a model  推荐采用的保存模型的方法

There are two main approaches for serializing and restoring a model.
序列化模型并保存模型和加载并恢复模型的方法主要有以下两种.




The first (recommended) saves and loads only the model parameters:
第一种方式(也是推荐使用的方式)是只保存和加载模型的参数:

torch.save(the_model.state_dict(), PATH)

Then later: 然后:

the_model = TheModelClass(*args, **kwargs)
the_model.load_state_dict(torch.load(PATH))






The second saves and loads the entire model:
第二种方式是保存和加载整个全部的模型:

torch.save(the_model, PATH)

Then later: 然后:

the_model = torch.load(PATH)

However in this case, the serialized data is bound to the specific classes 
and the exact directory structure used, so it can break in various ways 
when used in other projects, or after some serious refactors.
然而在这个例子中,序列化后的数据会关联到特定的类型以及所使用的特定的目录结构,
因此在其他项目中使用时或者在其他重要的重构之后,它会出现各种各样的问题.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值