MCPcopy
hub / github.com/PaddlePaddle/PaddleOCR / main

Function main

deploy/ios_demo/scripts/quantize_onnx_model.py:213–381  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

211
212
213def main() -> None:
214 p = argparse.ArgumentParser(description="Quantize PaddleOCR ONNX model.")
215 p.add_argument(
216 "--input-model-dir",
217 required=True,
218 type=Path,
219 help="Input model directory",
220 )
221 p.add_argument(
222 "--output-model-dir",
223 required=True,
224 type=Path,
225 help="Output model directory",
226 )
227 p.add_argument(
228 "--mode",
229 required=True,
230 choices=("dynamic", "static"),
231 help="dynamic: weight-only (quantize_dynamic). static: QDQ (quantize_static, needs --calib-data-dir).",
232 )
233 p.add_argument(
234 "--calib-data-dir",
235 type=Path,
236 default=None,
237 help="Directory of float32 .npy calibration samples (static mode only; one tensor per file).",
238 )
239 p.add_argument(
240 "--per-channel",
241 action=argparse.BooleanOptionalAction,
242 default=True,
243 help="Per-channel weight quantization (default: true).",
244 )
245 p.add_argument(
246 "--calibration-method",
247 default="MinMax",
248 help="ORT CalibrationMethod name (e.g. MinMax, Entropy, Percentile).",
249 )
250 p.add_argument(
251 "--no-verify",
252 action="store_true",
253 help="Skip ONNX checker validation of the output model after quantization.",
254 )
255 p.add_argument(
256 "--ort-preprocess",
257 action=argparse.BooleanOptionalAction,
258 default=True,
259 help=(
260 "Before quantize_static / quantize_dynamic, run ORT quant_pre_process (shape infer + "
261 "optional graph optimization) and attach onnx.quant metadata."
262 ),
263 )
264 p.add_argument(
265 "--onnx-opset-convert",
266 action=argparse.BooleanOptionalAction,
267 default=True,
268 help=(
269 "After ORT writes the output, run onnx.version_converter when the graph's declared "
270 "default-domain opset is below --onnx-target-opset. Use --no-onnx-opset-convert to keep "

Callers 1

Calls 10

dieFunction · 0.90
_same_fileFunction · 0.85
_quantize_dynamicFunction · 0.85
_quantize_staticFunction · 0.85
_atomic_replaceFunction · 0.85
_verify_onnx_fileFunction · 0.85
parse_argsMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…