量化一个 caffe 原生的模型 输入一个 caffe 模型的文件路径和权重路径 返回一个量化后的 PPQ.IR.BaseGraph quantize caffe model, input caffe prototxt and weight path, return a quantized ppq graph Args: caffe_proto_file (str): 被量化的 caffe 模型文件 .prototxt 路径
(
caffe_proto_file: str,
caffe_model_file: str,
calib_dataloader: DataLoader,
calib_steps: int,
input_shape: List[int],
platform: TargetPlatform,
input_dtype: torch.dtype = torch.float,
setting: QuantizationSetting = None,
collate_fn: Callable = None,
inputs: List[Any] = None,
do_quantize: bool = True,
device: str = 'cuda',
verbose: int = 0,
)
| 347 | |
| 348 | @ empty_ppq_cache |
| 349 | def quantize_caffe_model( |
| 350 | caffe_proto_file: str, |
| 351 | caffe_model_file: str, |
| 352 | calib_dataloader: DataLoader, |
| 353 | calib_steps: int, |
| 354 | input_shape: List[int], |
| 355 | platform: TargetPlatform, |
| 356 | input_dtype: torch.dtype = torch.float, |
| 357 | setting: QuantizationSetting = None, |
| 358 | collate_fn: Callable = None, |
| 359 | inputs: List[Any] = None, |
| 360 | do_quantize: bool = True, |
| 361 | device: str = 'cuda', |
| 362 | verbose: int = 0, |
| 363 | ) -> BaseGraph: |
| 364 | """ |
| 365 | 量化一个 caffe 原生的模型 |
| 366 | 输入一个 caffe 模型的文件路径和权重路径 |
| 367 | 返回一个量化后的 PPQ.IR.BaseGraph |
| 368 | quantize caffe model, input caffe prototxt and weight path, return a quantized ppq graph |
| 369 | Args: |
| 370 | caffe_proto_file (str): 被量化的 caffe 模型文件 .prototxt 路径 |
| 371 | caffe prototxt location |
| 372 | |
| 373 | caffe_model_file (str): 被量化的 caffe 模型文件 .caffemodel 路径 |
| 374 | caffe weight location |
| 375 | |
| 376 | calib_dataloader (DataLoader): 校准数据集 calibration data loader |
| 377 | |
| 378 | calib_steps (int): 校准步数 calibration steps |
| 379 | |
| 380 | collate_fn (Callable): 校准数据的预处理函数 batch collate func for preprocessing |
| 381 | |
| 382 | input_shape (List[int]): 模型输入尺寸,用于执行 jit.trace,对于动态尺寸的模型,输入一个模型可接受的尺寸即可。 |
| 383 | 如果模型存在多个输入,则需要使用 inputs 变量进行传参,此项设置为 None |
| 384 | a list of ints indicating size of input, for multiple inputs, please use |
| 385 | keyword arg inputs for direct parameter passing and this should be set to None |
| 386 | |
| 387 | input_dtype (torch.dtype): 模型输入数据类型,如果模型存在多个输入,则需要使用 inputs 变量进行传参,此项设置为 None |
| 388 | the torch datatype of input, for multiple inputs, please use keyword arg inputs |
| 389 | for direct parameter passing and this should be set to None |
| 390 | |
| 391 | setting (OptimSetting): 量化配置信息,用于配置量化的各项参数,设置为 None 时加载默认参数。 |
| 392 | Quantization setting, default setting will be used when set None |
| 393 | |
| 394 | inputs (List[Any], optional): 对于存在多个输入的模型,在Inputs中直接指定一个输入List,从而完成模型的tracing。 |
| 395 | for multiple inputs, please give the specified inputs directly in the form of |
| 396 | a list of arrays |
| 397 | |
| 398 | do_quantize (Bool, optional): 是否执行量化 whether to quantize the model, defaults to True, defaults to True. |
| 399 | |
| 400 | platform (TargetPlatform, optional): 量化的目标平台 target backend platform, defaults to TargetPlatform.DSP_INT8. |
| 401 | |
| 402 | device (str, optional): 量化过程的执行设备 execution device, defaults to 'cuda'. |
| 403 | |
| 404 | verbose (int, optional): 是否打印详细信息 whether to print details, defaults to 0. |
| 405 | |
| 406 | Raises: |
no test coverage detected