[TVM] Error importing keras model

Hi,

I want to use tvm as a compiler for a CNN built with Keras 2.1.6 (and tensorflow 1.9.0). But I have this error when importing the keras model to relay with the latest version of TVM:

Traceback (most recent call last):
  File "/home/julien/recherche/pose_estimation/ursonet/keras_tvm_example.py", line 39, in <module>
    mod, params = relay.frontend.from_keras(keras_resnet50, shape_dict)
  File "/home/julien/outils/tvm/python/tvm/relay/frontend/keras.py", line 1130, in from_keras
    and not model._node_key(keras_layer, node_idx) in model._network_nodes
AttributeError: 'Model' object has no attribute '_network_nodes'

Which version of TVM should I use with Keras 2.1.6? Knowing that I will not be able to update the model to the latest version of Keras.

It looks like CI is using TF 2.1 and Keras 2.3.1

I’m not super familiar with the keras api, I’m not sure when this might have changed.

thank you for your answer @mbrookhart. But I may not have been clear enough.

For the purpose of my research, I got a Keras (2.1.6) / TensorFlow (1.9.0) code on GitHub. I want to bring this network to TVM. But I don’t want to spend time on bringing the code to Keras 2.3.1 (or more recent version).

So do someone have a table or anything that says: for this particular version of TensorFlow/Keras, you should use that version of TVM.

Looking at the commit history, I’m not sure we had robust tracking for TF/Keras versions back in 2018 :frowning: I’m not sure I can recommend a version that will definitely support this combination.

It looks like this element was added in keras 2.2.0, is it possible to ugrade that far and give it try? TVM’s Keras support wasn’t implemented until after 2.2.0 https://github.com/keras-team/keras/blob/632560d91286bf278228de72e7ce64f6c5aa530c/keras/engine/network.py#L236

One possible workaround is to export the model to ONNX with keras2onnx and try the ONNX importer.