当前位置:网站首页>3.2 model saving and loading
3.2 model saving and loading
2022-07-29 03:23:00 【smiling0927】
Table of Contents
Model preservation
# Save the entire network
torch.save(net, PATH)
# Save parameters in the network , Fast , Less space
torch.save(net.state_dict(),PATH)General model loading
model_dict=torch.load(PATH)
model_dict=model.load_state_dict(torch.load(PATH))
Save model details
torch.save({'epoch': epochID + 1, 'state_dict': model.state_dict(), 'best_loss': lossMIN,
'optimizer': optimizer.state_dict(),'alpha': loss.alpha, 'gamma': loss.gamma},
checkpoint_path + '/m-' + launchTimestamp + '-' + str("%.4f" % lossMIN) + '.pth.tar')
eg:
for epoch in range(init_epoch, basic_configs['num_epochs']):
logger.info("Begin training epoch {}".format(epoch + 1))
train_function(epoch)
net_checkpoint_name = args.exp + "_net_epoch" + str(epoch + 1)
net_checkpoint_path = os.path.join(exp_ckpt_dir, net_checkpoint_name)
net_state = {"epoch": epoch + 1,
"network": net.module.state_dict()}
torch.save(net_state, net_checkpoint_path)
Model parameter freezing
for p in self.parameters():
p.requires_grad = False
class RESNET_YYT(nn.Module):
def init(self, model, pretrained):
super(RESNET_YYT, self).__init__()
self.resnet = model(pretrained)
for p in self.parameters():
p.requires_grad = False
self.f = SpectralNorm(nn.Conv2d(2048, 512, 1))
self.g = SpectralNorm(nn.Conv2d(2048, 512, 1))
self.h = SpectralNorm(nn.Conv2d(2048, 2048, 1))
Print network layers
model_dict = torch.load('/001_net_epoch5loss0.08947')['network']
dict_name = list(model_dict)
for i, p in enumerate(dict_name):
print(i, p)
边栏推荐
- Introduction to JVM foundation I (memory structure)
- Introduction and advanced MySQL (XIV)
- C traps and defects Chapter 3 semantic "traps" 3.8 operators &, |, and!
- 3D高级渲染器:Artlantis studio 2021.2中文版
- Multiline text omission
- 腾讯云使用pem登录
- Verilog:阻塞赋值和非阻塞赋值
- 01-SDRAM:初始化模块的代码
- 【打开新世界大门】看测试老鸟如何把API 测试玩弄在鼓掌之间
- Several methods of converting object to string
猜你喜欢

Verilog:阻塞赋值和非阻塞赋值

Learn more than 4000 words, understand the problem of this pointing in JS, and handwrite to realize call, apply and bind

今晚7:30 | 连界、将门、百度、碧桂园创投四位大佬眼中的AI世界,是继续高深还是回归商业本质?...

Apache文件管理自学笔记——映射文件夹和基于单ip多域名配置apache虚拟机

Pp-yoloe details

逐步分析类的拆分之案例——五彩斑斓的小球碰撞

Redis configuration cache expiration listening event trigger

Ten thousand words detailed Google play online application standard package format AAB

Calculation of array serial number of force deduction questions (daily question 7/28)

简历竟然敢写精通并发编程,那你说说AQS为什么要用双向链表?
随机推荐
C traps and defects Chapter 3 semantic "traps" 3.2 pointers to non arrays
01-sdram: Code of initialization module
mycat读写分离配置
How dare you write a resume that is proficient in concurrent programming? Why do you use a two-way linked list in AQS?
3D advanced renderer: artlandis studio 2021.2 Chinese version
STC MCU drive 1.8 'TFT SPI screen demonstration example (including data package)
shell脚本总结
04 | background login: login method based on account and password (Part 1)
【C】 Array
Let's talk about the summary of single merchant function modules
How to solve the time zone problem in MySQL timestamp
Wechat's crazy use of glide - life cycle learning
C and pointer Chapter 3 semantic "trap" 3.5 null pointer is not a string
【打开新世界大门】看测试老鸟如何把API 测试玩弄在鼓掌之间
一种简单通用的获取函数栈空间大小的方法
ROS - create workspace
NXP i.mx8mp-deepviewrt
MySQL流程控制之while、repeat、loop循环实例分析
Score addition and subtraction of force deduction and brushing questions (one question per day 7/27)
C traps and defects Chapter 3 semantic "traps" 3.1 pointers and arrays