microsoft / microsoft/onnxruntime-inference-examples

ValueError: Expected InsertedCast_gfpgan.conv_body_first.weight to be an initializer

Open
#363 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

quantization
Dominant language
C++
Stars
1.7k
Forks
414
Avg merge
1d 6h
Merged PRs (30d)
14

Description

Hi, when I try to quantize my onnx model use below code:

import onnx
from onnxruntime.quantization import quantize_dynamic, QuantType

model_fp32 = 'S.onnx'
model_quant = 'quan.onnx'
quantized_model = quantize_dynamic(model_fp32, model_quant)

quantize_dynamic(
    model_input=model_fp32, 
    model_output=model_quant, 
    weight_type=QuantType.QInt8, 
    optimize_model=True 
)

It appeared:

Traceback (most recent call last):
  File "C:\Software\PythonIDE\CodeLib\Project1\export_onnx\onnx_quan.py", line 6, in <module>
    quantized_model = quantize_dynamic(model_fp32, model_quant)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Software\PythonIDE\Anaconda\Lib\site-packages\onnxruntime\quantization\quantize.py", line 508, in quantize_dynamic
    quantizer.quantize_model()
  File "C:\Software\PythonIDE\Anaconda\Lib\site-packages\onnxruntime\quantization\onnx_quantizer.py", line 268, in quantize_model
    op_quantizer.quantize()
  File "C:\Software\PythonIDE\Anaconda\Lib\site-packages\onnxruntime\quantization\operators\conv.py", line 131, in quantize
    self.add_bias(nodes, scaled_output_name)
  File "C:\Software\PythonIDE\Anaconda\Lib\site-packages\onnxruntime\quantization\operators\conv.py", line 36, in add_bias
    raise ValueError(f"Expected {node.input[1]} to be an initializer")
ValueError: Expected InsertedCast_gfpgan.conv_body_first.weight to be an initializer

Process finished with exit code 1

How do I do to solve this problem?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reported quantize_dynamic call in onnx_quan.py and the traceback path in onnxruntime/quantization/operators/conv.py, then reproduce it using S.onnx. Determine why InsertedCast_gfpgan.conv_body_first.weight is not treated as an initializer and document a verified resolution; completion requires a reproducible case and a confirmed successful quantization.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.