attention-ocr icon indicating copy to clipboard operation
attention-ocr copied to clipboard

ONNX conversion error

Open benschreiber opened this issue 5 years ago • 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

benschreiber avatar Jun 19 '19 23:06 benschreiber

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.

emedvedev avatar Jul 03 '19 01:07 emedvedev

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 avatar Jan 23 '20 11:01 mialo-tech

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

Nateliu712 avatar Feb 05 '20 08:02 Nateliu712

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

No

mialo-tech avatar Feb 17 '20 11:02 mialo-tech