当前位置:网站首页>[pytoch] quantification

[pytoch] quantification

2022-06-24 14:18:00 . Yun Zhe


#-*- coding:utf-8 -*-
import torch
 
# Quantification is only available cpu
model = ResNet().cpu()
model = torch.load_state_dict(torch.load(weights))
 
#Specify quantization configuration
# In this step, symmetric quantization or asymmetric quantization is declared , And quantification bit Count 
# The following code uses the default asymmetric quantization , And 8bit
model.qconfig = torch.quantization.default_qconfig
model = torch.quantization.prepare(model)
 
#Convert to quantized model
model = torch.quantization.convert(model)
 
#Save model,  After saving the model size Significantly reduce , But the performance loss is relatively large 
# so , It is suggested to consider quantitative perception training 
torch.save(model.state_dict(), "path.pt")
原网站

版权声明
本文为[. Yun Zhe]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/175/202206241200153876.html

随机推荐