[DOCS] Port optimization doc changes to release docs (#21366)
* [DOCS] Update reference in quantization_w_accuracy_control.md (#21337) * Update quantization_w_accuracy_control.md avoid 404 * Update quantization_w_accuracy_control.md * migrate to new convert API (#21323) --------- Co-authored-by: Maksim Proshin <maksim.proshin@intel.com> Co-authored-by: Alexander Suslov <alexander.suslov@intel.com>
This commit is contained in:
5 files changed
+17
-20
No files matched your search
+1
-1
@@ -91,7 +91,7 @@ If the accuracy or performance of the quantized model is not satisfactory, you c
|
||||
Examples of NNCF post-training quantization with control of accuracy metric:
|
||||
#############################################################################
|
||||
|
||||
* `Post-Training Quantization of Anomaly Classification OpenVINO model with control of accuracy metric <https://github.com/openvinotoolkit/nncf/blob/develop/examples/post_training_quantization/openvino/quantize_with_accuracy_control>`__
|
||||
* `Post-Training Quantization of Anomaly Classification OpenVINO model with control of accuracy metric <https://github.com/openvinotoolkit/nncf/blob/develop/examples/post_training_quantization/openvino/anomaly_stfpm_quantize_with_accuracy_control>`__
|
||||
* `Post-Training Quantization of YOLOv8 OpenVINO Model with control of accuracy metric <https://github.com/openvinotoolkit/nncf/blob/develop/examples/post_training_quantization/openvino/yolov8_quantize_with_accuracy_control>`__
|
||||
|
||||
See also
|
||||
|
||||
@@ -18,9 +18,11 @@ validation_dataset = nncf.Dataset(calibration_loader, transform_fn)
|
||||
#! [validation]
|
||||
import numpy as np
|
||||
import torch
|
||||
import openvino
|
||||
from sklearn.metrics import accuracy_score
|
||||
|
||||
import openvino
|
||||
|
||||
|
||||
def validate(model: openvino.CompiledModel,
|
||||
validation_loader: torch.utils.data.DataLoader) -> float:
|
||||
predictions = []
|
||||
@@ -34,19 +36,21 @@ def validate(model: openvino.CompiledModel,
|
||||
references.append(target)
|
||||
|
||||
predictions = np.concatenate(predictions, axis=0)
|
||||
references = np.concatenate(references, axis=0)
|
||||
references = np.concatenate(references, axis=0)
|
||||
return accuracy_score(predictions, references)
|
||||
#! [validation]
|
||||
|
||||
#! [quantization]
|
||||
model = ... # openvino.Model object
|
||||
|
||||
quantized_model = nncf.quantize_with_accuracy_control(model,
|
||||
calibration_dataset=calibration_dataset,
|
||||
validation_dataset=validation_dataset,
|
||||
validation_fn=validate,
|
||||
max_drop=0.01,
|
||||
drop_type=nncf.DropType.ABSOLUTE)
|
||||
quantized_model = nncf.quantize_with_accuracy_control(
|
||||
model,
|
||||
calibration_dataset=calibration_dataset,
|
||||
validation_dataset=validation_dataset,
|
||||
validation_fn=validate,
|
||||
max_drop=0.01,
|
||||
drop_type=nncf.DropType.ABSOLUTE,
|
||||
)
|
||||
#! [quantization]
|
||||
|
||||
#! [inference]
|
||||
|
||||
@@ -24,10 +24,9 @@ quantized_model = nncf.quantize(model, calibration_dataset)
|
||||
|
||||
#! [inference]
|
||||
import openvino as ov
|
||||
from openvino.tools.mo import convert_model
|
||||
|
||||
# convert ONNX model to OpenVINO model
|
||||
ov_quantized_model = convert_model(quantized_model)
|
||||
ov_quantized_model = ov.convert_model(quantized_model)
|
||||
|
||||
# compile the model to transform quantized operations to int8
|
||||
model_int8 = ov.compile_model(ov_quantized_model)
|
||||
|
||||
@@ -23,10 +23,9 @@ quantized_model = nncf.quantize(model, calibration_dataset)
|
||||
|
||||
#! [inference]
|
||||
import openvino as ov
|
||||
from openvino.tools.mo import convert_model
|
||||
|
||||
# convert TensorFlow model to OpenVINO model
|
||||
ov_quantized_model = convert_model(quantized_model)
|
||||
ov_quantized_model = ov.convert_model(quantized_model)
|
||||
|
||||
# compile the model to transform quantized operations to int8
|
||||
model_int8 = ov.compile_model(ov_quantized_model)
|
||||
|
||||
@@ -23,16 +23,11 @@ quantized_model = nncf.quantize(model, calibration_dataset)
|
||||
|
||||
#! [inference]
|
||||
import openvino as ov
|
||||
from openvino.tools.mo import convert_model
|
||||
|
||||
input_fp32 = ... # FP32 model input
|
||||
|
||||
# export PyTorch model to ONNX model
|
||||
onnx_model_path = "model.onnx"
|
||||
torch.onnx.export(quantized_model, input_fp32, onnx_model_path)
|
||||
|
||||
# convert ONNX model to OpenVINO model
|
||||
ov_quantized_model = convert_model(onnx_model_path)
|
||||
# convert PyTorch model to OpenVINO model
|
||||
ov_quantized_model = ov.convert_model(quantized_model, example_input=input_fp32)
|
||||
|
||||
# compile the model to transform quantized operations to int8
|
||||
model_int8 = ov.compile_model(ov_quantized_model)
|
||||
|
||||
Reference in new issue
Block a user