0.1.109
This commit is contained in:
parent
6f78f12717
commit
170cd45bb6
@ -1,7 +1,7 @@
|
||||
[metadata]
|
||||
# replace with your username:
|
||||
name = guan
|
||||
version = 0.1.108
|
||||
version = 0.1.109
|
||||
author = guanjihuan
|
||||
author_email = guanjihuan@163.com
|
||||
description = An open source python package
|
||||
|
@ -1,6 +1,6 @@
|
||||
Metadata-Version: 2.1
|
||||
Name: guan
|
||||
Version: 0.1.108
|
||||
Version: 0.1.109
|
||||
Summary: An open source python package
|
||||
Home-page: https://py.guanjihuan.com
|
||||
Author: guanjihuan
|
||||
|
@ -254,6 +254,12 @@ def save_model(model, filename='./model.pth'):
|
||||
import torch
|
||||
torch.save(model, filename)
|
||||
|
||||
# 使用TorchScript形式保存模型到文件(TorchScript允许模型在不依赖Python解释器的情况下运行,适合在生产环境中部署)
|
||||
def save_model_with_torch_jit_script(model, filename='model_scripted_with_torch_jit.pth'):
|
||||
import torch
|
||||
scripted_model = torch.jit.script(model)
|
||||
scripted_model.save(filename)
|
||||
|
||||
# 以字典的形式保存模型的所有信息到文件(保存时需要模型的类可访问,此外还要输入模型的实例化函数)
|
||||
def save_model_with_all_information(model, model_class, model_instantiation, note='', filename='./model_with_all_information.pth'):
|
||||
import torch
|
||||
@ -281,6 +287,12 @@ def load_model(filename='./model.pth'):
|
||||
model = torch.load(filename)
|
||||
return model
|
||||
|
||||
# 加载TorchScript形式的模型
|
||||
def load_model_with_torch_jit_script(filename='model_scripted_with_torch_jit.pth'):
|
||||
import torch
|
||||
scripted_model = torch.jit.load(filename)
|
||||
return scripted_model
|
||||
|
||||
# 加载包含所有信息的模型(包含了模型的类和实例化函数等,返回的是模型对象)
|
||||
def load_model_with_all_information(filename='./model_with_all_information.pth', note_print=0):
|
||||
import torch
|
||||
|
Loading…
x
Reference in New Issue
Block a user