Helper function for quantize your model within working directory, This function will do some check and redirect your requirement to: ppq.api.quantize_onnx_model ppq.api.quantize_caffe_model. see them for more information. Args: working_directory (str): A path that indicates
(working_directory: str, setting: QuantizationSetting, model_type: NetworkFramework,
executing_device: str, input_shape: List[int], target_platform: TargetPlatform,
dataloader: DataLoader, calib_steps: int = 32)
| 803 | |
| 804 | |
| 805 | def quantize(working_directory: str, setting: QuantizationSetting, model_type: NetworkFramework, |
| 806 | executing_device: str, input_shape: List[int], target_platform: TargetPlatform, |
| 807 | dataloader: DataLoader, calib_steps: int = 32) -> BaseGraph: |
| 808 | """Helper function for quantize your model within working directory, This |
| 809 | function will do some check and redirect your requirement to: |
| 810 | ppq.api.quantize_onnx_model ppq.api.quantize_caffe_model. |
| 811 | |
| 812 | see them for more information. |
| 813 | |
| 814 | Args: |
| 815 | working_directory (str): A path that indicates working directory. |
| 816 | setting (QuantizationSetting): Quantization setting |
| 817 | model_type (NetworkFramework): Onnx or Caffe |
| 818 | executing_device (str): 'cuda' or 'cpu' |
| 819 | input_shape (List[int]): sample input's shape |
| 820 | target_platform (TargetPlatform): Target deploy platform |
| 821 | dataloader (DataLoader): calibraiton dataloader |
| 822 | calib_steps (int, optional): Defaults to 32. |
| 823 | |
| 824 | Raises: |
| 825 | FileNotFoundError: _description_ |
| 826 | FileNotFoundError: _description_ |
| 827 | |
| 828 | Returns: |
| 829 | BaseGraph: _description_ |
| 830 | """ |
| 831 | if model_type == NetworkFramework.ONNX: |
| 832 | if not os.path.exists(os.path.join(working_directory, 'model.onnx')): |
| 833 | raise FileNotFoundError(f'无法找到你的模型: {os.path.join(working_directory, "model.onnx")},' |
| 834 | '如果你使用caffe的模型, 请设置MODEL_TYPE为CAFFE') |
| 835 | return quantize_onnx_model( |
| 836 | onnx_import_file=os.path.join(working_directory, 'model.onnx'), |
| 837 | calib_dataloader=dataloader, calib_steps=calib_steps, input_shape=input_shape, setting=setting, |
| 838 | platform=target_platform, device=executing_device, collate_fn=lambda x: x.to(executing_device) |
| 839 | ) |
| 840 | if model_type == NetworkFramework.CAFFE: |
| 841 | if not os.path.exists(os.path.join(working_directory, 'model.caffemodel')): |
| 842 | raise FileNotFoundError(f'无法找到你的模型: {os.path.join(working_directory, "model.caffemodel")},' |
| 843 | '如果你使用ONNX的模型, 请设置MODEL_TYPE为ONNX') |
| 844 | return quantize_caffe_model( |
| 845 | caffe_proto_file=os.path.join(working_directory, 'model.prototxt'), |
| 846 | caffe_model_file=os.path.join(working_directory, 'model.caffemodel'), |
| 847 | calib_dataloader=dataloader, calib_steps=calib_steps, input_shape=input_shape, setting=setting, |
| 848 | platform=target_platform, device=executing_device, collate_fn=lambda x: x.to(executing_device) |
| 849 | ) |
| 850 | |
| 851 | |
| 852 | def export(working_directory: str, quantized: BaseGraph, platform: TargetPlatform, **kwargs): |
nothing calls this directly
no test coverage detected