Skip to contents

model_to_int8() converts installed or custom ONNX neural network models to 8-bit integer (INT8) precision. Dynamic quantization reduces model disk size by up to 75% and accelerates CPU inference by 2–3x with virtually no loss in detection or segmentation accuracy.

When model = NULL (default), model_to_int8() scans the pliman model directory (pliman_model_dir()) and converts all installed FP32 .onnx models into _int8.onnx models. Existing INT8 models are skipped unless overwrite = TRUE.

Usage

model_to_int8(
  model = NULL,
  dir = pliman_model_dir(),
  weight_type = c("QUInt8", "QInt8"),
  overwrite = FALSE,
  verbose = TRUE
)

models_to_int8(
  model = NULL,
  dir = pliman_model_dir(),
  weight_type = c("QUInt8", "QInt8"),
  overwrite = FALSE,
  verbose = TRUE
)

Arguments

model

Optional character vector of model name(s) or file path(s) to quantize. If NULL (default), all unquantized .onnx models in dir are converted.

dir

Directory where installed models are located. Defaults to pliman_model_dir().

weight_type

Precision type: "QUInt8" (unsigned 8-bit, default) or "QInt8" (signed 8-bit).

overwrite

Logical. If TRUE, re-quantizes models even if an _int8.onnx version already exists. Defaults to FALSE.

verbose

Logical. Show progress messages and compression summary. Defaults to TRUE.

Value

A data.frame of class pliman_quantize_summary listing each model, original size, INT8 size, reduction percentage, and conversion status.

Examples

if (FALSE) { # interactive()
library(pliman)

# Convert a specific installed model
model_to_int8("capsulas_det.onnx")

# Convert all installed models in pliman_model_dir()
summary <- model_to_int8()
print(summary)
}