Skip to content

Conversation

ID6109
Copy link
Contributor

@ID6109 ID6109 commented Mar 9, 2023

What does this PR do?

Fixes #1427

Colab

Who can review?

@ianstenbit @LukeWood @tanzhenyu

@ID6109 ID6109 changed the title Make MobileNetV3 a Functional subclass model & remove closures Makes MobileNetV3 a Functional subclass model & removes closures Mar 9, 2023
@ID6109 ID6109 marked this pull request as ready for review March 11, 2023 10:50
Copy link
Contributor

@ianstenbit ianstenbit 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!
Just a few small changes, otherwise looks good!

@@ -112,48 +112,44 @@ def depth(x, divisor=8, min_value=None):
return new_x


def HardSigmoid(name=None):
def HardSigmoid(x, name=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

let's rename these activation functions (and the InvertedResBlock) to use the apply_xyz convention

(e.g. apply_hard_sigmoid, apply_inverted_res_block)

"""Instantiates the MobileNetV3 architecture.

References:
- [Searching for MobileNetV3](https://arxiv.org/pdf/1905.02244.pdf) (ICCV 2019)
- [Based on the Original keras.applications MobileNetv3](https://github.com/keras-team/keras/blob/master/keras/applications/mobilenet_v3.py)

This function returns a Keras MobileNetV3 model.
This class returns a Keras MobileNetV3 model.
Copy link
Contributor

Choose a reason for hiding this comment

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

While you're editing this, would you mind also adding type indications to these docstrings?

(See, for example, docstring updates to VGG19 in #1471)

@ID6109
Copy link
Contributor Author

ID6109 commented Mar 14, 2023

The changes have been made. I'll implement the same in my other PRs. Do let me know if there are further corrections needed. Thanks.

Copy link
Contributor

@ianstenbit ianstenbit left a comment

Choose a reason for hiding this comment

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

Thanks for the changes!

Just a few more small changes, and then we can merge.


Returns:
A `keras.Model` instance.
"""


def depth(x, divisor=8, min_value=None):
"""Ensure that all layers have a channel number that is divisble by the `divisor`.
def apply_depth(x, divisor=8, min_value=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this isn't a function on a Tensor, but a helper method to get the number of channels for a convolutional layer, so it should just be depth instead of apply_depth


Args:
x: input value.
divisor: integer, the value by which a channel number should be divisble,
x: input tensor.
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't expected to be a tensor -- it should be an integer scalar

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems I skimmed past this method in a hurry. I'll be more mindful in the future. Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

No worries at all -- thank you for the contributions!

name: string, layer label.

Returns:
a function that takes an input Tensor representing a HardSigmoid layer.
the updated input tensor.
Copy link
Contributor

Choose a reason for hiding this comment

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

(throughout) - it would be more accurate to say that this returns "the result of applying hard sigmoid to the input tensor"

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, this looks consistent with the docs in other models, so feel free to ignore this for now and we can address it in all the models at once in #1500

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll take this up directly while solving #1500 then.

@ID6109
Copy link
Contributor Author

ID6109 commented Mar 14, 2023

Updated

@ianstenbit
Copy link
Contributor

/gcbrun

Copy link
Contributor

@ianstenbit ianstenbit left a comment

Choose a reason for hiding this comment

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

Looks good -- thank you!

@ianstenbit ianstenbit merged commit d7a3732 into keras-team:master Mar 14, 2023
ghost pushed a commit to y-vectorfield/keras-cv that referenced this pull request Nov 16, 2023
…as-team#1475)

* Generates Error

* Reformat

* num_classes change

* reformatted

* Final

* Brush

* Brush

* Changed function names and added type indications

* Minor changes
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.

Make MobileNetV3 a Functional subclass model & remove closures
2 participants