nngen
nngen copied to clipboard
Error Generating model from ONNX
Given this Onnx file and the following code:
https://drive.google.com/file/d/1h9qmRRbryAZydOmIKnp0HpXJ2PbzyNDB/view?usp=sharing
from __future__ import absolute_import
from __future__ import print_function
import os
import sys
import numpy as np
import nngen as ng
# the next line can be removed after installation
sys.path.insert(0, os.path.dirname(os.path.dirname(
os.path.dirname(os.path.abspath(__file__)))))
def run(act_dtype=ng.int8, weight_dtype=ng.int8,
bias_dtype=ng.int32, scale_dtype=ng.int8,
with_batchnorm=True, disable_fusion=False,
conv2d_par_ich=1, conv2d_par_och=1, conv2d_par_col=1, conv2d_par_row=1,
conv2d_concur_och=None, conv2d_stationary='filter',
pool_par=1, elem_par=1,
chunk_size=64, axi_datawidth=32, silent=False,
onnx_filename='model_final-2.onnx',
weight_filename='vgg11_imagenet.npz',
verilog_filename=None,
sim_filename=None,
simtype=None, # no RTL simulation
# simtype='iverilog',
# simtype='verilator'
):
# input mean and standard deviation
imagenet_mean = np.array([0.485, 0.456, 0.406]).astype(np.float32)
imagenet_std = np.array([0.229, 0.224, 0.225]).astype(np.float32)
act_shape = (1, 62, 12, 1)
# ONNX to NNgen
dtypes = {}
(outputs, placeholders, variables,
constants, operators) = ng.from_onnx(onnx_filename,
value_dtypes=dtypes,
default_placeholder_dtype=act_dtype,
default_variable_dtype=weight_dtype,
default_constant_dtype=weight_dtype,
default_operator_dtype=act_dtype,
default_scale_dtype=scale_dtype,
default_bias_dtype=bias_dtype,
disable_fusion=disable_fusion)
# --------------------
# (2) Assign quantized weights to the NNgen operators
# --------------------
if act_dtype.width > 8:
act_scale_factor = 128
else:
act_scale_factor = int(round(2 ** (act_dtype.width - 1) * 0.5))
input_scale_factors = {'act': act_scale_factor}
input_means = {'act': imagenet_mean * act_scale_factor}
input_stds = {'act': imagenet_std * act_scale_factor}
ng.quantize(outputs, input_scale_factors, input_means, input_stds)
if __name__ == '__main__':
rslt = run(silent=False, verilog_filename='tmp.v')
print(rslt)
I get the following error
Youssefs-MacBook-Pro-9:nngen youssef$ python3 kws_onnx_nngen.py
Traceback (most recent call last):
File "/Users/youssef/Documents/Work/AUC_Open_Hardware_Lab/nngen/kws_onnx_nngen.py", line 392, in <module>
rslt = run(silent=False, verilog_filename='tmp.v')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/youssef/Documents/Work/AUC_Open_Hardware_Lab/nngen/kws_onnx_nngen.py", line 72, in run
constants, operators) = ng.from_onnx(onnx_filename,
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/youssef/Documents/Work/AUC_Open_Hardware_Lab/nngen/nngen/onnx/__init__.py", line 329, in from_onnx
visitor.visit(name)
File "/Users/youssef/Documents/Work/AUC_Open_Hardware_Lab/nngen/nngen/onnx/__init__.py", line 147, in visit
node_op = node_func(self, node)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/youssef/Documents/Work/AUC_Open_Hardware_Lab/nngen/nngen/onnx/gemm.py", line 63, in Gemm
reshape_value = filter.value.reshape(shape)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
Here is the architecture of the used model.