{
  "id": 309280,
  "title": "gem pooling",
  "url": "/competitions/happy-whale-and-dolphin/discussion/309280",
  "author_name": "",
  "post_date": "2022-02-22T17:19:35.613562300Z",
  "votes": 6,
  "comment_count": 2,
  "views": 0,
  "content": "<p>How to implement gem pooling in that notebook <a href=\"https://www.kaggle.com/lextoumbourou/happywhale-effnet-b6-fork-with-detic-crop\" target=\"_blank\">https://www.kaggle.com/lextoumbourou/happywhale-effnet-b6-fork-with-detic-crop</a> ?</p>",
  "messages": [
    {
      "id": "1701336",
      "postDate": "02/22/2022 17:19:35",
      "content": "<p>How to implement gem pooling in that notebook <a href=\"https://www.kaggle.com/lextoumbourou/happywhale-effnet-b6-fork-with-detic-crop\" target=\"_blank\">https://www.kaggle.com/lextoumbourou/happywhale-effnet-b6-fork-with-detic-crop</a> ?</p>",
      "rawMarkdown": "How to implement gem pooling in that notebook https://www.kaggle.com/lextoumbourou/happywhale-effnet-b6-fork-with-detic-crop ?",
      "votes": null
    },
    {
      "id": "1706264",
      "postDate": "02/27/2022 10:49:29",
      "content": "<p>This is the implementation for GEM. You just have to integrate it into the notebook</p>\n<pre><code>class GeMPoolingLayer(tf.keras.layers.Layer):\n    def __init__(self, p=1., train_p=False):\n        super().__init__()\n        if train_p:\n            self.p = tf.Variable(p, dtype=tf.float32)\n        else:\n            self.p = p\n        self.eps = 1e-6\n    def call(self, inputs: tf.Tensor, **kwargs):\n        inputs = tf.clip_by_value(inputs, clip_value_min=1e-6, clip_value_max=tf.reduce_max(inputs))\n        inputs = tf.pow(inputs, self.p)\n        inputs = tf.reduce_mean(inputs, axis=[1, 2], keepdims=False)\n        inputs = tf.pow(inputs, 1./self.p)\n        return inputs\n</code></pre>",
      "rawMarkdown": "This is the implementation for GEM. You just have to integrate it into the notebook\n```\n\nclass GeMPoolingLayer(tf.keras.layers.Layer):\n    def __init__(self, p=1., train_p=False):\n        super().__init__()\n        if train_p:\n            self.p = tf.Variable(p, dtype=tf.float32)\n        else:\n            self.p = p\n        self.eps = 1e-6\n    def call(self, inputs: tf.Tensor, **kwargs):\n        inputs = tf.clip_by_value(inputs, clip_value_min=1e-6, clip_value_max=tf.reduce_max(inputs))\n        inputs = tf.pow(inputs, self.p)\n        inputs = tf.reduce_mean(inputs, axis=[1, 2], keepdims=False)\n        inputs = tf.pow(inputs, 1./self.p)\n        return inputs\n\n```",
      "votes": null
    },
    {
      "id": "1736861",
      "postDate": "03/27/2022 19:55:40",
      "content": "<p>thx. I will try it out </p>",
      "rawMarkdown": "thx. I will try it out",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1706264,
      "author_name": "vladvdv",
      "author_url": "",
      "post_date": "02/27/2022 10:49:29",
      "content": "<p>This is the implementation for GEM. You just have to integrate it into the notebook</p>\n<pre><code>class GeMPoolingLayer(tf.keras.layers.Layer):\n    def __init__(self, p=1., train_p=False):\n        super().__init__()\n        if train_p:\n            self.p = tf.Variable(p, dtype=tf.float32)\n        else:\n            self.p = p\n        self.eps = 1e-6\n    def call(self, inputs: tf.Tensor, **kwargs):\n        inputs = tf.clip_by_value(inputs, clip_value_min=1e-6, clip_value_max=tf.reduce_max(inputs))\n        inputs = tf.pow(inputs, self.p)\n        inputs = tf.reduce_mean(inputs, axis=[1, 2], keepdims=False)\n        inputs = tf.pow(inputs, 1./self.p)\n        return inputs\n</code></pre>",
      "votes": null,
      "replies": [
        {
          "id": 1736861,
          "author_name": "dername",
          "author_url": "",
          "post_date": "03/27/2022 19:55:40",
          "content": "<p>thx. I will try it out </p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1701336": "How to implement gem pooling in that notebook https://www.kaggle.com/lextoumbourou/happywhale-effnet-b6-fork-with-detic-crop ?",
    "1706264": "This is the implementation for GEM. You just have to integrate it into the notebook\n```\n\nclass GeMPoolingLayer(tf.keras.layers.Layer):\n    def __init__(self, p=1., train_p=False):\n        super().__init__()\n        if train_p:\n            self.p = tf.Variable(p, dtype=tf.float32)\n        else:\n            self.p = p\n        self.eps = 1e-6\n    def call(self, inputs: tf.Tensor, **kwargs):\n        inputs = tf.clip_by_value(inputs, clip_value_min=1e-6, clip_value_max=tf.reduce_max(inputs))\n        inputs = tf.pow(inputs, self.p)\n        inputs = tf.reduce_mean(inputs, axis=[1, 2], keepdims=False)\n        inputs = tf.pow(inputs, 1./self.p)\n        return inputs\n\n```",
    "1736861": "thx. I will try it out"
  },
  "source": "meta"
}