onnx2tflite icon indicating copy to clipboard operation
onnx2tflite copied to clipboard

ValueError: Unrecognized keyword arguments passed to Conv2D: {'weights': [array([[[[-0.16197614,

Open yunsong1 opened this issue 1 year ago • 6 comments

Hello, I would like to ask you about the code of the “From torchvision to tensorflow-lite” example in the readme file. When running, an error will be reported. When running your own onnx conversion, an error will also be reported. How to solve this problem?

model = torchvision.models.mobilenet_v2(True)

use default settings is ok

torch.onnx.export(model, _input, './mobilenetV2.onnx', opset_version=11) # or opset_version=13

from converter import onnx_converter

onnx_converter( onnx_model_path="./mnist.onnx", need_simplify=True, output_path="./", target_formats=['tflite'], # or ['keras'], ['keras', 'tflite'] weight_quant=False, int8_model=False, int8_mean=None, int8_std=None, image_root=None )

Checking 0/1... Traceback (most recent call last): File "E:\pycharm\minist\minist\onnx2tflite.py", line 3, in onnx_converter( File "E:\pycharm\minist\minist\converter.py", line 21, in onnx_converter keras_model = keras_builder(model_proto, native_groupconv) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\pycharm\minist\minist\utils\builder.py", line 82, in keras_builder tf_tensor[node_outputs[index]] = tf_operator(tf_tensor, onnx_weights, node_inputs, op_attr, index=index)(_inputs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\pycharm\minist\minist\layers\conv_layers.py", line 75, in init self.conv = TFConv(in_channel, out_channel, kernel_shape, strides, dilations, pads, weights, bias) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\pycharm\minist\minist\layers\conv_layers.py", line 98, in init self.conv2d_init(in_channel_num, out_channel_num, kernel_size, strides, dilations, pads, weights, bias, group) File "E:\pycharm\minist\minist\layers\conv_layers.py", line 136, in conv2d_init self.conv = keras.layers.Conv2D( ^^^^^^^^^^^^^^^^^^^^ File "D:\Anaconda3\envs\yolov8\Lib\site-packages\keras\src\layers\convolutional\conv2d.py", line 107, in init super().init( File "D:\Anaconda3\envs\yolov8\Lib\site-packages\keras\src\layers\convolutional\base_conv.py", line 107, in init super().init(activity_regularizer=activity_regularizer, **kwargs) File "D:\Anaconda3\envs\yolov8\Lib\site-packages\keras\src\layers\layer.py", line 264, in init raise ValueError( ValueError: Unrecognized keyword arguments passed to Conv2D: {'weights': [array([[[[-0.16197614, 0.15870397, -0.32785565, 0.06910464]],

    [[-0.21044524, -0.01345028,  0.17069656, -0.15660217]],

yunsong1 avatar May 10 '24 06:05 yunsong1

hello, it's seems onnx_model_path args of onnx_converter function is not same to torch.onnx.export. more, can you share mnist.onnx?

MPolaris avatar May 12 '24 09:05 MPolaris

I lowered the tensorflow version to 12.0 and the error disappeared.

yunsong1 avatar May 12 '24 12:05 yunsong1

I lowered the tensorflow version to 12.0 and the error disappeared.

hi,but tensorflow do not have 12.0 version . Can you share what you did? thank you.

WEI9957 avatar Jun 30 '24 17:06 WEI9957

I lowered the tensorflow version to 12.0 and the error disappeared.

hi,but tensorflow do not have 12.0 version . Can you share what you did? thank you.

In pycharm->settings->project->python interpreter, I deleted the keras package and lowered tensorflow to 2.12.0

yunsong1 avatar Jun 30 '24 17:06 yunsong1

I lowered the tensorflow version to 12.0 and the error disappeared.

hi,but tensorflow do not have 12.0 version . Can you share what you did? thank you.

In pycharm->settings->project->python interpreter, I deleted the keras package and lowered tensorflow to 2.12.0

您好,我无法在我的pycharm的python interpreter中看到keras包和相关的tensorflow包,但是我在终端删除了keras,并将tensorflow降级为2.13.0(没有2.12.0),然而系统显示错误信息:ImportError: cannot import name 'keras' from 'tensorflow' (unknown location),这应该如何解决?

hedong5-tal avatar Jul 18 '24 09:07 hedong5-tal

ERROR: Could not find a version that satisfies the requirement tensorflow==2.12.0 (from versions: 2.13.0rc0, 2.13.0rc1, 2.13.0rc2, 2.13.0, 2.13.1, 2.14.0rc0, 2.14.0rc1, 2.14.0, 2.14.1, 2.15.0rc0, 2.15.0rc1, 2.15.0, 2.15.1, 2.16.0rc0, 2.16.1, 2.16.2, 2.17.0rc0, 2.17.0rc1, 2.17.0) ERROR: No matching distribution found for tensorflow==2.12.0

hedong5-tal avatar Jul 18 '24 09:07 hedong5-tal