{
  "id": 134952,
  "title": "ValueError: Unknown activation function:swish",
  "url": "/competitions/bengaliai-cv19/discussion/134952",
  "author_name": "",
  "post_date": "2020-03-11T10:04:23.297092700Z",
  "votes": null,
  "comment_count": 5,
  "views": 0,
  "content": "<p>when i try to implement model = load_model('/kaggle/input/efficientnetb6-30/efficientnetb6_30.h5') on my kaggle kernel, i get the error message below.</p>\n\n<p>ValueError: Unknown activation function:swish</p>\n\n<p>It works well in my private computer jupyter notebook.</p>\n\n<p>Please help me on this issue.</p>",
  "messages": [
    {
      "id": "768889",
      "postDate": "03/11/2020 10:04:23",
      "content": "<p>when i try to implement model = load_model('/kaggle/input/efficientnetb6-30/efficientnetb6_30.h5') on my kaggle kernel, i get the error message below.</p>\n\n<p>ValueError: Unknown activation function:swish</p>\n\n<p>It works well in my private computer jupyter notebook.</p>\n\n<p>Please help me on this issue.</p>",
      "rawMarkdown": "when i try to implement model = load_model('/kaggle/input/efficientnetb6-30/efficientnetb6_30.h5') on my kaggle kernel, i get the error message below.\n\nValueError: Unknown activation function:swish\n\nIt works well in my private computer jupyter notebook.\n\nPlease help me on this issue.",
      "votes": null
    },
    {
      "id": "768923",
      "postDate": "03/11/2020 11:02:44",
      "content": "<p>Look where swish is defined/imported in your local notebook then do the same in the kernel.</p>",
      "rawMarkdown": "Look where swish is defined/imported in your local notebook then do the same in the kernel.",
      "votes": null
    },
    {
      "id": "768972",
      "postDate": "03/11/2020 11:53:12",
      "content": "<p>For Keras with Tensorflow use this code.</p>\n\n<p>from tensorflow.keras.utils import get_custom_objects\nget_custom_objects().update({'swish': keras.layers.Activation(tf.nn.swish)})</p>",
      "rawMarkdown": "For Keras with Tensorflow use this code.\n\nfrom tensorflow.keras.utils import get_custom_objects\nget_custom_objects().update({'swish': keras.layers.Activation(tf.nn.swish)})",
      "votes": null
    },
    {
      "id": "769677",
      "postDate": "03/12/2020 06:22:53",
      "content": "<p>if swish is defined in your local private notebook, then import those custom objects for keras\nrom tensorflow.keras.utils import getcustomobjects\ngetcustomobjects().update({'swish': keras.layers.Activation(tf.nn.swish)})</p>",
      "rawMarkdown": "if swish is defined in your local private notebook, then import those custom objects for keras\nrom tensorflow.keras.utils import getcustomobjects\ngetcustomobjects().update({'swish': keras.layers.Activation(tf.nn.swish)})",
      "votes": null
    },
    {
      "id": "770048",
      "postDate": "03/12/2020 14:24:44",
      "content": "<p>You probably need to import efficientnet to get swish and FixedDropout.</p>",
      "rawMarkdown": "You probably need to import efficientnet to get swish and FixedDropout.",
      "votes": null
    },
    {
      "id": "833023",
      "postDate": "05/04/2020 14:57:02",
      "content": "<p><code>from keras.models import load_model</code>\n<code>reloaded_model = tf.keras.models.load_model(path)</code>\nValueError: Unknown layer: FixedDropout\nHow to solve this issue. I want to load the model to re-train it.</p>\n\n<p><strong>issue solved:</strong>\n<code>class FixedDropout(tf.keras.layers.Dropout):</code>\n    <code>def _get_noise_shape(self, inputs):</code>\n        <code>if self.noise_shape is None:</code>\n            <code>return self.noise_shape</code>\n        <code>symbolic_shape = K.shape(inputs)</code>\n       <code>noise_shape = [symbolic_shape[axis] if shape is None else shape</code>\n                       <code>for axis, shape in enumerate(self.noise_shape)]</code>\n        <code>return tuple(noise_shape)</code></p>\n\n<p><code>model = tf.keras.models.load_model(path,compile=False,custom_objects{</code>\n                                                                         <code>#'swish':tf.compat.v2.nn.swish,</code>\n                                                                        <code>'FixedDropout':FixedDropout})</code></p>",
      "rawMarkdown": "`from keras.models import load_model`\n`reloaded_model = tf.keras.models.load_model(path)`\nValueError: Unknown layer: FixedDropout\nHow to solve this issue. I want to load the model to re-train it.\n\n**issue solved:**\n`class FixedDropout(tf.keras.layers.Dropout):`\n    `def _get_noise_shape(self, inputs):`\n        `if self.noise_shape is None:`\n            `return self.noise_shape`\n        `symbolic_shape = K.shape(inputs)`\n       ` noise_shape = [symbolic_shape[axis] if shape is None else shape`\n                       `for axis, shape in enumerate(self.noise_shape)]`\n        `return tuple(noise_shape)`\n\n`model = tf.keras.models.load_model(path,compile=False,custom_objects{`\n                                                                         `#'swish':tf.compat.v2.nn.swish,`\n                                                                        `'FixedDropout':FixedDropout})`",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 768923,
      "author_name": "cpmpml",
      "author_url": "",
      "post_date": "03/11/2020 11:02:44",
      "content": "<p>Look where swish is defined/imported in your local notebook then do the same in the kernel.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 768972,
      "author_name": "dipamc77",
      "author_url": "",
      "post_date": "03/11/2020 11:53:12",
      "content": "<p>For Keras with Tensorflow use this code.</p>\n\n<p>from tensorflow.keras.utils import get_custom_objects\nget_custom_objects().update({'swish': keras.layers.Activation(tf.nn.swish)})</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 769677,
      "author_name": "anushakarthik1991",
      "author_url": "",
      "post_date": "03/12/2020 06:22:53",
      "content": "<p>if swish is defined in your local private notebook, then import those custom objects for keras\nrom tensorflow.keras.utils import getcustomobjects\ngetcustomobjects().update({'swish': keras.layers.Activation(tf.nn.swish)})</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 770048,
      "author_name": "n2718281",
      "author_url": "",
      "post_date": "03/12/2020 14:24:44",
      "content": "<p>You probably need to import efficientnet to get swish and FixedDropout.</p>",
      "votes": null,
      "replies": [
        {
          "id": 833023,
          "author_name": "jimitshah777",
          "author_url": "",
          "post_date": "05/04/2020 14:57:02",
          "content": "<p><code>from keras.models import load_model</code>\n<code>reloaded_model = tf.keras.models.load_model(path)</code>\nValueError: Unknown layer: FixedDropout\nHow to solve this issue. I want to load the model to re-train it.</p>\n\n<p><strong>issue solved:</strong>\n<code>class FixedDropout(tf.keras.layers.Dropout):</code>\n    <code>def _get_noise_shape(self, inputs):</code>\n        <code>if self.noise_shape is None:</code>\n            <code>return self.noise_shape</code>\n        <code>symbolic_shape = K.shape(inputs)</code>\n       <code>noise_shape = [symbolic_shape[axis] if shape is None else shape</code>\n                       <code>for axis, shape in enumerate(self.noise_shape)]</code>\n        <code>return tuple(noise_shape)</code></p>\n\n<p><code>model = tf.keras.models.load_model(path,compile=False,custom_objects{</code>\n                                                                         <code>#'swish':tf.compat.v2.nn.swish,</code>\n                                                                        <code>'FixedDropout':FixedDropout})</code></p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "768889": "when i try to implement model = load_model('/kaggle/input/efficientnetb6-30/efficientnetb6_30.h5') on my kaggle kernel, i get the error message below.\n\nValueError: Unknown activation function:swish\n\nIt works well in my private computer jupyter notebook.\n\nPlease help me on this issue.",
    "768923": "Look where swish is defined/imported in your local notebook then do the same in the kernel.",
    "768972": "For Keras with Tensorflow use this code.\n\nfrom tensorflow.keras.utils import get_custom_objects\nget_custom_objects().update({'swish': keras.layers.Activation(tf.nn.swish)})",
    "769677": "if swish is defined in your local private notebook, then import those custom objects for keras\nrom tensorflow.keras.utils import getcustomobjects\ngetcustomobjects().update({'swish': keras.layers.Activation(tf.nn.swish)})",
    "770048": "You probably need to import efficientnet to get swish and FixedDropout.",
    "833023": "`from keras.models import load_model`\n`reloaded_model = tf.keras.models.load_model(path)`\nValueError: Unknown layer: FixedDropout\nHow to solve this issue. I want to load the model to re-train it.\n\n**issue solved:**\n`class FixedDropout(tf.keras.layers.Dropout):`\n    `def _get_noise_shape(self, inputs):`\n        `if self.noise_shape is None:`\n            `return self.noise_shape`\n        `symbolic_shape = K.shape(inputs)`\n       ` noise_shape = [symbolic_shape[axis] if shape is None else shape`\n                       `for axis, shape in enumerate(self.noise_shape)]`\n        `return tuple(noise_shape)`\n\n`model = tf.keras.models.load_model(path,compile=False,custom_objects{`\n                                                                         `#'swish':tf.compat.v2.nn.swish,`\n                                                                        `'FixedDropout':FixedDropout})`"
  },
  "source": "meta"
}