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

Add Mish class inheriting from Lamda layer #57

Closed
wants to merge 3 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion tf2_yolov4/layers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Common layer architecture such as Conv->BN->Mish or Conv->BN->LeakyReLU"""
import tensorflow as tf
import tensorflow_addons as tfa
from tensorflow.python.keras.layers import Lambda


def conv_bn(
Expand Down Expand Up @@ -41,6 +42,18 @@ def conv_bn(
if activation == "leaky_relu":
x = tf.keras.layers.LeakyReLU(alpha=0.1)(x)
elif activation == "mish":
x = tfa.activations.mish(x)
x = Mish()(x)

return x


class Mish(Lambda):
Copy link
Collaborator

Choose a reason for hiding this comment

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

@lmontier je comprends pas à quoi sert cette classe: c'est la même chose que Lambda(function=tfa.activations.mish) et elle ne sert qu'une seule fois.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@AntoineToubhans je crois que c'est pour qu'elle apparaisse de manière plus friendly dans le plot_model de Keras, mais je suis pas hyper chaud pour merger non plus

Copy link
Contributor Author

@lmontier lmontier Jun 30, 2020

Choose a reason for hiding this comment

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

@AntoineToubhans @RaphaelMeudec , ça fait deux choses :

  • On mélange des keras.layer et des keras.functions dans nos models, ce qui fait que notamment la function plot_model de keras crash (mais je me dis que peut être d'autres utilis peuvent péter également...). Il me semble que Clément nous avais également indiqué ce genre de retour. D'où le Lambda(function=tfa.activations.mish) ou le Mish()
  • Utiliser Lambda(function=tfa.activations.mish) fait que quand tu examines ton modèle (ou que tu le plot), le nom de tes layers s'appellent "Lambda_x" , alors que si tu redéfinis une classe "Mish", ils s'appelleront "Mish_x"... C'est assez chiant car on utilise ailleurs d'autre Lambda... J'ai essayé de faire autrement, genre forcer le name=... mais pour ça il faut avoir accès à ton index du layer et je n'ai pas réussi. Si vous savez comment faire ça par contre je suis chaud!

"""
Layer applying the Mish activation (see paper https://arxiv.org/abs/1908.08681).
"""

def __init__(self):
"""
Applies the mish function (from tensorflow-addons).
"""
super(Mish, self).__init__(function=tfa.activations.mish)