当前位置:网站首页>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)
边栏推荐
- Tonight at 7:30 | is the AI world in the eyes of Lianjie, Jiangmen, Baidu and country garden venture capital continue to be advanced or return to the essence of business
- 照片比例校正工具:DxO ViewPoint 3 直装版
- 单例模式(饿汉式 懒汉式)
- 再学EXKMP(EXKMP模板)
- Singleton mode (hungry and lazy)
- 军品研制过程-转阶段
- C语言基础知识点汇总
- MySQL installation and configuration super detailed tutorial and simple database and table building method
- C traps and defects Chapter 3 semantic "traps" 3.9 integer overflow
- Introduction and advanced level of MySQL (12)
猜你喜欢

【科技1】

During the year, the first "three consecutive falls" of No. 95 gasoline returned to the "8 Yuan era"“

2022-07-28 study notes of group 4 self-cultivation class (every day)

STC单片机驱动1.8‘TFT SPI屏幕演示示例(含资料包)

Engineering boy: under 20 years old, ordinary but not mediocre

带你来浅聊一下,单商户功能模块汇总

照片比例校正工具:DxO ViewPoint 3 直装版

Reproduce 20 character short domain name bypass and XSS related knowledge points

C language programming | exchange binary odd and even bits (macro Implementation)

Shardingsphere's level table practice (III)
随机推荐
Asynchronous callback future mode of concurrent mode
Apache文件管理自学笔记——映射文件夹和基于单ip多域名配置apache虚拟机
makefile详解
Several methods of converting object to string
Typescript学习(一)
后缀自动机(sam)板子 from jly
Anti vulnerability · benefit from uncertainty --- management?
[open the door to the new world] see how the old bird of testing plays API testing between applause
再学EXKMP(EXKMP模板)
增量实时灾备笔记
基于单片机烟雾温湿度甲醛监测设计
Design of smoke temperature, humidity and formaldehyde monitoring based on single chip microcomputer
C traps and defects Chapter 2 syntax "traps" 2.6 problems caused by "hanging" else
C traps and defects Chapter 3 semantic "traps" 3.6 Boundary Calculation and asymmetric boundary
Kubernetes-1.24.x feature
4000 多字学懂弄通 js 中 this 指向问题,顺便手写实现 call、apply 和 bind
3D高级渲染器:Artlantis studio 2021.2中文版
[robot learning] matlab kinematics and ADMAS dynamics analysis of manipulator gripper
"PHP Basics" output approximate value of PI
ROS-Errror:Did you forget to specify generate_ messages(DEPENDENCIES ...)?