int8量化的resnet50在ImageNet数据集上的推断结果

本文介绍了将ResNet50模型(除全连接层外)量化到8位精度后,在ImageNet数据集上进行推断的结果。在1个和3个CPU核心上运行,量化模型的fps相比于全精度模型提升了1.x倍,平均延迟减少了30%-50%。尽管量化模型的fps波动和某些batch_size处出现异常fps值,但其性能提升明显。推断代码采用单线程,官方还提供了多线程方法。量化方法为Post-Training Optimization,对权重和激活层进行校准。
摘要由CSDN通过智能技术生成

将resnet50除全连接层外的所有层均量化为8bit。

结果如图:
在这里插入图片描述
这是使用1个cpu核心的结果。
在这里插入图片描述
这是使用3个cpu核心的结果。

作为对比,这是全精度模型的结果。
在这里插入图片描述
1个cpu核心
在这里插入图片描述
3个cpu核心

从结果对比可以看出,量化模型的fps较全精度模型提升了1.x倍,而平均延迟则分别减少了30%和50%。

将转换后的IR模型在Ubuntu上使用cpu做了推断,fps结果和DL Workbench一致,延迟因为不会测试就没有测。

推断python代码如下:

#!/usr/bin/env python
"""
 Copyright (C) 2018-2020 Intel Corporation

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
"""
from __future__ import print_function
import sys
import os
from argparse import ArgumentParser, SUPPRESS
import cv2
import numpy as np
import logging as log
from openvino.inference_engine import IECore
import time

def build_argparser():
    parser = ArgumentParser(add_help=False)
    args = parser.add_argument_group('Options')
    args.add_argument('-h', '--help', action='help', default=SUPPRESS, help='Show this help message and exit.')
    args.add_argument("-m", "--model", help="Required. Path to an .xml file with a trained model.", required=True,
                      type=str)
    args.add_argument("-i", "--input", help="Required. Path to a folder with images or path to an image files",
                      required=True,
                      type=str, nargs="+")
    args.add_argument("-l", "--cpu_extension",
                      help="Optional. Required for CPU custom layers. "
                           "MKLDNN (CPU)-targeted custom layers. Absolute path to a shared library with the"
                           " kernels implementations.", type=str, default=None)
    args.add_argument("-d", "--device"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值