Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Frontend][Keras] Support nested layers recursively in keras frontend #7949

Merged
merged 5 commits into from
May 6, 2021

Conversation

trevor-m
Copy link
Contributor

@trevor-m trevor-m commented Apr 29, 2021

Keras models can have nested layers, where one layer in the model is actually another Keras model with its own layers. With this PR, we will now support these types of models in TVM.

Example Keras model with nested model "mobilenetv2_1.00_224".

Layer (type)                 Output Shape              Param #   
=================================================================
mobilenetv2_1.00_224 (Functi (None, 7, 7, 1280)        2257984   
_________________________________________________________________
global_average_pooling2d_1 ( (None, 1280)              0         
_________________________________________________________________
dense_2 (Dense)              (None, 1024)              1311744   
_________________________________________________________________
dense_3 (Dense)              (None, 2)                 2050      
=================================================================
Total params: 3,571,778
Trainable params: 3,537,666
Non-trainable params: 34,112
_________________________________________________________________

It can be created using the following Keras code, which is commonly used when using pretained models.

sub_model = keras.applications.MobileNetV2(input_shape=(224, 224, 3), include_top=False)
keras_model = keras.Sequential(
  [
    sub_model,
    keras.layers.GlobalAveragePooling2D(),
    keras.layers.Dense(1024),
    keras.layers.Dense(2),
  ]
)

@trevor-m
Copy link
Contributor Author

trevor-m commented May 3, 2021

@siju-samuel @jwfromm @mbrookhart @leandron Could you please review?

Copy link
Contributor

@leandron leandron left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@mbrookhart mbrookhart left a comment

Choose a reason for hiding this comment

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

LGTM

@trevor-m
Copy link
Contributor Author

trevor-m commented May 5, 2021

Thanks for reviewing @mbrookhart @leandron !
Tests are passing

@mbrookhart mbrookhart merged commit d181867 into apache:main May 6, 2021
@mbrookhart
Copy link
Contributor

Thanks @trevor-m @leandron

trevor-m pushed a commit to trevor-m/tvm that referenced this pull request May 6, 2021
…apache#7949)

* Support nested layers recursively in keras frontend

* Fix lint

* Fix issue

* Fix formatting

* Fix unit test
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request May 6, 2021
…apache#7949)

* Support nested layers recursively in keras frontend

* Fix lint

* Fix issue

* Fix formatting

* Fix unit test
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request May 6, 2021
…apache#7949)

* Support nested layers recursively in keras frontend

* Fix lint

* Fix issue

* Fix formatting

* Fix unit test
trevor-m pushed a commit to neo-ai/tvm that referenced this pull request May 11, 2021
…apache#7949)

* Support nested layers recursively in keras frontend

* Fix lint

* Fix issue

* Fix formatting

* Fix unit test
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