openvino
openvino copied to clipboard
[Bug]: openvino.tools.ovc.error.Error: Unknown model type: <class 'onnx.onnx_ml_pb2.ModelProto'>
OpenVINO Version
openvino 2024.3.0 + onnx 1.14.0
Operating System
Ubuntu 20.04 (LTS)
Device used for inference
CPU
Framework
ONNX
Model used
resnet18
Issue description
Model has been converted to ONNX format and saved as mobilenet_v2.onnx
WARNING:nncf:ONNX models with 10 < opset version < 13 do not support per-channel quantization. Per-tensor quantization will be applied.
Statistics collection ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 1/1 • 0:00:00 • 0:00:00
Applying Fast Bias correction ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 21/21 • 0:00:01 • 0:00:00
Traceback (most recent call last):
File "nncf_tool.py", line 145, in
Step-by-step reproduction
if name == 'main': #onnx_quantization() import torch import torch.nn as nn import torchvision.models as models import onnx
# 1. 创建 MobileNetV2 模型
model = models.resnet18(pretrained=True) # 使用预训练的 MobileNetV2 模型
# 2. 设置模型为评估模式
model.eval()
# 3. 创建一个虚拟输入张量
# 假设输入图像的大小为 224x224,批量大小为 1
dummy_input = torch.randn(1, 3, 224, 224)
# 4. 定义 ONNX 导出路径
onnx_file_path = "mobilenet_v2.onnx"
# 5. 导出模型到 ONNX 格式
torch.onnx.export(
model, # 要导出的模型
dummy_input, # 输入张量
onnx_file_path, # 导出的 ONNX 文件路径
verbose=True, # 是否打印导出过程的信息
input_names=['input'],# 输入张量的名称
output_names=['output'], # 输出张量的名称
opset_version=12 # ONNX 操作集版本
)
print(f"Model has been converted to ONNX format and saved as {onnx_file_path}")
from torchvision import datasets, transforms
# Instantiate your uncompressed model
onnx_model = onnx.load_model(onnx_file_path)
# Provide validation part of the dataset to collect statistics needed for the compression algorithm
val_dataset = datasets.ImageFolder("/home/huangq/nfs/common_train_tools/qunat/", transform=transforms.Compose([transforms.Resize((224, 224)), transforms.ToTensor()]))
dataset_loader = torch.utils.data.DataLoader(val_dataset, batch_size=1)
# Step 1: Initialize transformation function
input_name = onnx_model.graph.input[0].name
def transform_fn(data_item):
images, _ = data_item
return {input_name: images.numpy()}
# Step 2: Initialize NNCF Dataset
calibration_dataset = nncf.Dataset(dataset_loader, transform_fn)
# Step 3: Run the quantization pipeline
quantized_model = nncf.quantize(onnx_model, calibration_dataset)
ov_quantized_model = ov.convert_model(quantized_model)
Relevant log output
No response
Issue submission checklist
- [X] I'm reporting an issue. It's not a question.
- [X] I checked the problem with the documentation, FAQ, open issues, Stack Overflow, etc., and have not found a solution.
- [X] There is reproducer code and related data files such as images, videos, models, etc.