Skip to content

Conversation

@haoyang9804
Copy link
Contributor

I met this problem when I try to fix this issue, and here is the bug-triggered script:

import tvm
import tvm.relay as relay
import numpy as np
from tensorflow import keras
from tensorflow.keras import layers, models

input_shape = (1, 5, 7, 6, 2)

input_data = np.random.random(size=input_shape)
x = layers.Input(shape=input_shape[1:], dtype='float64')

layer = keras.layers.Conv3D(filters=1, kernel_size=3)
layer.set_weights(layer.get_weights())

y = layer(x)
model = models.Model(x, y)
model.summary()
res_keras = model(input_data)

shape_dict = {'input_1': input_shape}
mod, params = relay.frontend.from_keras(model, shape_dict,layout='NDHWC')
with tvm.transform.PassContext(opt_level=3):
    model = relay.build_module.create_executor("graph", mod, tvm.cpu(0), 'llvm', params).evaluate()

test_x_tvm = input_data
res_tvm = model(tvm.nd.array(test_x_tvm.astype('float64'))).numpy()

relay.frontend.from_keras invokes the following error:

Traceback (most recent call last):
  File "/Users/mahaoyang/repo/tests/python/test.py", line 21, in <module>
    mod, params = relay.frontend.from_keras(model, shape_dict,layout='NDHWC')
  File "/Users/mahaoyang/repo/tvm/python/tvm/relay/frontend/keras.py", line 1530, in from_keras
    import keras.engine as E
ModuleNotFoundError: No module named 'keras.engine

The reason for this error is that keras.engine has been changed into keras.src.engine in my installed tensorflow(2.13.0), in which keras's version is 2.13.1.

So I add a if to judge the version of keras and fix this compatibility issue.

@tvm-bot
Copy link
Collaborator

tvm-bot commented Jul 8, 2023

Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment.

  • No users to auto-tag found, no teams are specified in PR title See #10317 for details

Generated by tvm-bot

@haoyang9804
Copy link
Contributor Author

@echuraev

Copy link
Contributor

@echuraev echuraev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR. LGTM!

@echuraev echuraev merged commit b6502f4 into apache:main Jul 14, 2023
junrushao pushed a commit to junrushao/tvm that referenced this pull request Jul 24, 2023
* Fix keras version problem

* Fix keras version problem

* Fix keras version problem

* Fix keras version problem

* Fix keras version problem

* Fix keras version problem

* Fix keras version problem
junrushao pushed a commit to junrushao/tvm that referenced this pull request Jul 27, 2023
* Fix keras version problem

* Fix keras version problem

* Fix keras version problem

* Fix keras version problem

* Fix keras version problem

* Fix keras version problem

* Fix keras version problem
junrushao pushed a commit to junrushao/tvm that referenced this pull request Jul 30, 2023
* Fix keras version problem

* Fix keras version problem

* Fix keras version problem

* Fix keras version problem

* Fix keras version problem

* Fix keras version problem

* Fix keras version problem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants