LeelaChessZero / lc0

The rewritten engine, originally for tensorflow. Now all other backends have been ported here.
GNU General Public License v3.0
2.44k stars 528 forks source link

ONNX node names should not have leading slash #1735

Open mooskagh opened 2 years ago

mooskagh commented 2 years ago

Apparently, Keras doesn't like such onnx files, giving the error:

ValueError: '/inputconv_pad/' is not a valid root scope name. A root scope name has to match the following pattern: ^[A-Za-z0-9.][A-Za-z0-9_.\\/>-]*$

Fix is this: Remove trailing slashes in this file https://github.com/LeelaChessZero/lc0/blob/master/src/neural/onnx/converter.cc (basically, replace all "/ which are not part of + "/ with ").

mooskagh commented 2 years ago

Code to repro keras error:

from onnx2keras import onnx_to_keras
import onnx
onnx_model = onnx.load("generated_network.onnx")
onnx_to_keras(onnx_model, ['/input/planes'])
mooskagh commented 2 years ago

After removing leading slashes, next error is

ValueError: Layer block0/conv2/se/matmul1 weight shape (1, 32) is not compatible with provided weight shape (384, 32).

It seems that onnx2keras just doesn't understand onnx well, I'm inclined not to push the slash removal (https://github.com/mooskagh/lc0/tree/onnx_slash) either.

mooskagh commented 2 years ago

I considered filing bugs in the onnx2keras repo, but the projects doesn't look alive, last commit was a year ago, probably not worth it.

https://github.com/gmalivenko/onnx2keras