当前位置:网站首页>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)
边栏推荐
- Engineering boy: under 20 years old, ordinary but not mediocre
- 3D advanced renderer: artlandis studio 2021.2 Chinese version
- Wechat's crazy use of glide - life cycle learning
- 逐步分析类的拆分之案例——五彩斑斓的小球碰撞
- ROS - create workspace
- mysql的timestamp存在的时区问题怎么解决
- Practical guidance for interface automation testing (Part I): what preparations should be made for interface automation
- 今晚7:30 | 连界、将门、百度、碧桂园创投四位大佬眼中的AI世界,是继续高深还是回归商业本质?...
- Military product development process - transition phase
- How to deploy sentinel cluster of redis
猜你喜欢

Summary of basic knowledge points of C language

Let's talk about the summary of single merchant function modules

Digital image processing Chapter 10 - image segmentation

Introduction to JVM foundation I (memory structure)

基于单片机烟雾温湿度甲醛监测设计

国产ERP有没有机会击败SAP ?

Does domestic ERP have a chance to beat sap?

A case of gradually analyzing the splitting of classes -- colorful ball collisions

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

What if MySQL forgets the password
随机推荐
Singleton and invariant modes of concurrent mode
MYCAT read / write separation configuration
Mathematical modeling -- analytic hierarchy process model
Design of smoke temperature, humidity and formaldehyde monitoring based on single chip microcomputer
C语言基础知识点汇总
照片比例校正工具:DxO ViewPoint 3 直装版
简历竟然敢写精通并发编程,那你说说AQS为什么要用双向链表?
13_ UE4 advanced_ Montage animation realizes attack while walking
Shell script summary
【C】 Array
Multiline text omission
STC MCU drive 1.8 'TFT SPI screen demonstration example (including data package)
单例模式(饿汉式 懒汉式)
Redis configuration cache expiration listening event trigger
Apache文件管理自学笔记——映射文件夹和基于单ip多域名配置apache虚拟机
腾讯云使用pem登录
2022-07-28 study notes of group 4 self-cultivation class (every day)
基于单片机烟雾温湿度甲醛监测设计
反脆弱·从不确定性中获益---管理?
C language programming | exchange binary odd and even bits (macro Implementation)