- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm using OpenVINO for the first time.
I would like to convert an ONNX model to an OpenVINO model quantized in INT8. However, when I run "nncf.quantize", the following message appears and the conversion fails.
How can I solve this?
module 'openvino' has no attribute 'Node'
File "/media/shino/KIOXIA/mobilenetv2_cat_and_dog/openvino/3.5_test.py", line 38, in <module>
quantized_model = nncf.quantize(
AttributeError: module 'openvino' has no attribute 'Node'
import os
import nncf
from PIL import Image
import numpy as np
from openvino.runtime import Core, serialize
ONNX_MODEL_PATH = "../cat_and_dog_mobilenetv2.onnx"
cats_dir = "../test_dir/cats"
dogs_dir = "../test_dir/dogs"
def preprocess_image(image_path, input_size=(224, 224)):
image = Image.open(image_path).convert("RGB")
image = image.resize(input_size)
image = np.array(image).astype(np.float32) / 255.0
image = np.transpose(image, (2, 0, 1))
image = np.expand_dims(image, axis=0)
return image
def get_calibration_data():
image_paths = []
for folder in [cats_dir, dogs_dir]:
for fname in os.listdir(folder):
if fname.endswith((".jpg", ".jpeg", ".png")):
image_paths.append(os.path.join(folder, fname))
for image_path in image_paths:
yield [preprocess_image(image_path)]
calibration_dataset = nncf.Dataset(get_calibration_data())
onnx_model_path = ONNX_MODEL_PATH
core = Core()
ov_model = core.read_model(onnx_model_path)
quantized_model = nncf.quantize(
model=ov_model,
calibration_dataset=calibration_dataset,
preset=nncf.QuantizationPreset.MIXED,
target_device=nncf.TargetDevice.CPU
)
serialize(quantized_model, "model_int8.xml", "model_int8.bin")
The following versions of Python, OpenVINO, nncf, and other Python packages are used:
$ python3.12 -m venv ~/env/openvino_new
$ . ~/env/openvino_new/bin/activate
$ pip install --upgrade pip
$ pip install openvino==2024.4.0 openvino-dev==2024.4.0 nncf==2.17.0 numpy==1.26.4 opencv-python==4.8.0.76 onnx==1.16.2 onnxruntime==1.18.0 matplotlib==3.9.2 scikit-learn==1.5.2 pillow==10.4.0 seaborn==0.13.2
Link Copied
0 Replies

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page