keras-onnx
keras-onnx copied to clipboard
"image_shape:01 is disconnected" error on YOLOv3 conversion to ONNX
I am trying to convert the YOLOv3 model from https://github.com/qqwweee/keras-yolo3 to ONNX. The README on https://github.com/onnx/keras-onnx/tree/master/applications/yolov3 states the following:
The original keras model was coming from: https://github.com/qqwweee/keras-yolo3, clone the project and follow the 'Quick Start' to get the pre-trained model. We have converted yolov3 model successfully and uploaded to the model zoo https://github.com/onnx/models/tree/master/yolov3
When I try to run https://github.com/onnx/keras-onnx/blob/master/applications/yolov3/yolov3.py after following the Quick Start section, I get the following error:
Traceback (most recent call last):
File "/Users/semo/keras-yolo3/yolov3_test.py", line 473, in <module>
onnxmodel = convert_model(yolo, target_opset)
File "/Users/semo/keras-yolo3/yolov3_test.py", line 418, in convert_model
onnxmodel_2 = convert_keras(yolo.evaluation_model, target_opset=target_opset)
File "/Users/semo/keras-yolo3/venv/lib/python3.7/site-packages/keras2onnx/main.py", line 105, in convert_keras
return convert_topology(topology, name, doc_string, target_opset, channel_first_inputs)
File "/Users/semo/keras-yolo3/venv/lib/python3.7/site-packages/keras2onnx/topology.py", line 317, in convert_topology
nodes = _remove_unused_nodes(container.nodes, container.inputs + extra_inputs, container.outputs)
File "/Users/semo/keras-yolo3/venv/lib/python3.7/site-packages/keras2onnx/topology.py", line 222, in _remove_unused_nodes
"{} is disconnected, check the parsing log for more details.".format(in_)
AssertionError: image_shape:01 is disconnected, check the parsing log for more details.
I'm using the following relevant package versions: keras2onnx 1.7.1 (latest master) onnx 1.7.0 onnxconverter-common 1.7.0 (latest master) onnxruntime 1.4.0 tensorflow 2.2.0 (I've also tried with 2.0.2, and am using tensorflow.keras with TF_KERAS=1)
I've tried with opsets 10 to 12 along with the respective ONNX versions, but haven't been able to resolve the issue. Any help is much appreciated
Can you try kera==2.2.5
and tensorflow==1.15.0
?
That indeed resolves the issue. I also needed to update line 471 in https://github.com/onnx/keras-onnx/blob/master/applications/yolov3/yolov3.py from onnxmodel = convert_model(yolo, target_opset)
to
onnxmodel = convert_model(yolo, False, target_opset)
as it was missing an argument which resulted in an opset mismatch, as def convert_model(yolo, is_tiny_yolo, target_opset=None):
.
Is there a way to make this work for TensorFlow 2.x and tf.keras, though? This downgrading TF/Keras I assume would be a temporary solution.
@semihcanturk hi, did you manage to get this working for tf 2.3~?
@ch-hristov hey, I gave up on https://github.com/qqwweee/keras-yolo3 and used https://github.com/emadboctorx/yolov3-keras-tf2/ instead - the former is quite outdated and a pain to deal with at this point imo, and there are a few other TF2.X implementations of YOLOv3, which might be safer bets.
@semihcanturk I'm using efficientnet tho so i think that makes the difference