It is generally believed that the industrial structure of artificial intelligence is divided into three major aspects:the basic layer(including software and hardware facilities and data services),the technical layer(basic framework,algorithm model,the latter including deep learning,knowledge atlas,computer vision,natural language processing,and intelligent speech recognition),and the application layer(intelligent solutions and application scenarios)
empty_ppq_cache
def quantize_caffe_model(
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,
)->BaseGraph:
if do_quantize:
if calib_dataloader is None or calib_steps is None:
raise TypeError('Quantization needs a valid calib_dataloader and calib_steps setting.')
if setting is None:
setting=QuantizationSettingFactory.default_setting()
ppq_ir=load_graph(file_path=caffe_proto_file,
caffemodel_path=caffe_model_file,
from_framework=NetworkFramework.CAFFE)
ppq_ir=format_graph(ppq_ir)
ppq_ir=dispatch_graph(ppq_ir,platform,
dispatcher=setting.dispatcher,
dispatching_table=setting.dispatching_table)
if inputs is None:
dummy_input=torch.zeros(size=input_shape,device=device,dtype=input_dtype)
else:dummy_input=inputs
quantizer=PFL.Quantizer(platform=platform,graph=ppq_ir)
executor=TorchExecutor(graph=quantizer._graph,device=device)
executor.tracing_operation_meta(inputs=dummy_input)
if do_quantize:
quantizer.quantize(
inputs=dummy_input,
calib_dataloader=calib_dataloader,
executor=executor,
setting=setting,
calib_steps=calib_steps,
collate_fn=collate_fn
)
if verbose:quantizer.report()
return quantizer._graph
else:
return quantizer._graph