当前位置: 首页 > 工具软件 > QAT > 使用案例 >

pytorch量化感知训练(QAT)示例---ResNet

严宏朗
2023-12-01

  1. 训练浮点模型,测试浮点模式在CPU和GPU上的时间;
  2. BN层融合,测试融合前后精度和结果比对;
  3. 加入torch的量化感知API,训练一个QAT模型;
  4. 保存定点INT8模型, 测试速度和精度;
  5. 完成一致性对其,并保存int8模型。

完整代码下载地址:下载地址
代码流程图下:
`
def main():

random_seed = 0
num_classes = 10
cuda_device = torch.device("cuda:0")
cpu_device = torch.device("cpu:0")

model_dir = "saved_models"
model_filename = "resnet18_cifar10.pt"
quantized_model_filename = "resnet18_quantized_cifar10.pt"
model_filepath = os.path.join(model_dir, model_filename)
quantized_model_filepath = os.path.join(
    model_dir, quantized_model_filename)

set_random_seeds(random_seed=random_seed)

# Create an untrained model.
model = create_mode
 类似资料: