(self, op_name: str, platform: TargetPlatform=None)
| 78 | print('Network Quantization Finished.') |
| 79 | |
| 80 | def quantize_operation(self, op_name: str, platform: TargetPlatform=None) -> QuantableOperation: |
| 81 | if op_name not in self._graph.operations: |
| 82 | raise KeyError(f'Can not find op {op_name} in your graph, chech operation name again.') |
| 83 | converting_operation = self._graph.operations[op_name] |
| 84 | if isinstance(converting_operation, QuantableOperation): |
| 85 | ppq_warning(f'Operation {op_name} has been quantized, can not to quantize it twice.') |
| 86 | return converting_operation |
| 87 | |
| 88 | # override platform with calling parameter. |
| 89 | if platform is not None: converting_operation.platform = platform |
| 90 | else: platform = converting_operation.platform |
| 91 | |
| 92 | if platform in {TargetPlatform.FP32, TargetPlatform.SOI}: |
| 93 | return self._graph.operations[op_name] |
| 94 | |
| 95 | # if platform == TargetPlatform.UNSPECIFIED we can skip its quantization when type is not supported. |
| 96 | if platform == TargetPlatform.UNSPECIFIED and converting_operation.type not in self.quant_operation_types: |
| 97 | return self._graph.operations[op_name] |
| 98 | |
| 99 | # create quantize config and convert operation. |
| 100 | self._processor(QuantizeOperationCommand( |
| 101 | op_name=op_name, target_platform=platform, |
| 102 | config=self.init_quantize_config(operation=converting_operation) |
| 103 | )) |
| 104 | return self._graph.operations[op_name] |
| 105 | |
| 106 | @ staticmethod |
| 107 | def create_default_quant_config( |
no test coverage detected