emedvedev/attention-ocr

ONNX conversion error

Opened this issue · 4 comments

I am attempting to convert this model to ONNX using the tf2onnx tool. The tool can take a frozen graph or saved model as input and produce an ONNX file. Unfortunately, it fails on aocr, apparently to due the graph being invalid.

I am filing the issue here and not against tf2onnx because the error occurred in Tensorflow while attempting to import the graph that aocr export produced. Here is the error:

tensorflow.python.framework.errors_impl.InvalidArgumentError: Node 'cond/ExpandDims' has an _output_shapes attribute inconsistent with the GraphDef for output #0: Shapes must be equal rank, but are 1 and 0

To reproduce:

aocr export --format=frozengraph ./exported-model
python -m tf2onnx.convert --input=exported-model/frozen_graph.pb --outputs prediction:0 --inputs input_image_as_bytes:0

alternatively,

aocr export ./exported-model
python -m tf2onnx.convert --saved-model=exported-model

What you could try to do is remove the conditional statement on L117-121 of model.py and using self.img_pl directly in the map argument on L122: the cond statement is responsible for converting the input to the same shape no matter if it's a single image or an array of images. Removing the statement will only make the model accept an array, but on the flip side, the conversion to ONNX might work.

I have done the steps as you mentioned but now I'm getting another error

ValueError: slice index 0 of dimension 0 out of bounds. for 'map/strided_slice' (op: 'StridedSlice') with input shapes: [0], [1], [1], [1] and with computed input tensors: input[1] = <0>, input[2] = <1>, input[3] = <1>.

@mialo-tech I meet the same question. Do you fix the problem?

@mialo-tech I meet the same question. Do you fix the problem?

No