{
  "id": 212275,
  "title": "Model Choices in TensorFlow 2.xxx",
  "url": "/competitions/cassava-leaf-disease-classification/discussion/212275",
  "author_name": "",
  "post_date": "2021-01-18T10:27:45.115962700Z",
  "votes": 16,
  "comment_count": 9,
  "views": 0,
  "content": "<p>You may use this repository to experiment on some tensorflow version model related to computer vision.</p>\n<p><a href=\"https://github.com/osmr/imgclsmob/tree/master/tensorflow2\" target=\"_blank\">https://github.com/osmr/imgclsmob/tree/master/tensorflow2</a></p>\n<p>Note that it is already existing in Kaggle environment.</p>\n<p>Example:<br>\nfrom tf2cv.model_provider import get_model as tf2cv_get_model<br>\nimport tensorflow as tf</p>\n<p>net = tf2cv_get_model(\"resnet18\", pretrained=True, data_format=\"channels_last\")<br>\nx = tf.random.normal((1, 224, 224, 3))<br>\ny_net = net(x)</p>",
  "messages": [
    {
      "id": "1158011",
      "postDate": "01/18/2021 10:27:45",
      "content": "<p>You may use this repository to experiment on some tensorflow version model related to computer vision.</p>\n<p><a href=\"https://github.com/osmr/imgclsmob/tree/master/tensorflow2\" target=\"_blank\">https://github.com/osmr/imgclsmob/tree/master/tensorflow2</a></p>\n<p>Note that it is already existing in Kaggle environment.</p>\n<p>Example:<br>\nfrom tf2cv.model_provider import get_model as tf2cv_get_model<br>\nimport tensorflow as tf</p>\n<p>net = tf2cv_get_model(\"resnet18\", pretrained=True, data_format=\"channels_last\")<br>\nx = tf.random.normal((1, 224, 224, 3))<br>\ny_net = net(x)</p>",
      "rawMarkdown": "You may use this repository to experiment on some tensorflow version model related to computer vision.\n\nhttps://github.com/osmr/imgclsmob/tree/master/tensorflow2\n\nNote that it is already existing in Kaggle environment.\n\nExample:\nfrom tf2cv.model_provider import get_model as tf2cv_get_model\nimport tensorflow as tf\n\nnet = tf2cv_get_model(\"resnet18\", pretrained=True, data_format=\"channels_last\")\nx = tf.random.normal((1, 224, 224, 3))\ny_net = net(x)",
      "votes": null
    },
    {
      "id": "1158060",
      "postDate": "01/18/2021 11:04:43",
      "content": "<p>thanks! Tomorrow I'm going to try</p>",
      "rawMarkdown": "thanks! Tomorrow I'm going to try",
      "votes": null
    },
    {
      "id": "1158493",
      "postDate": "01/18/2021 15:39:38",
      "content": "<p>Thanks for sharing the repo.<br>\nI was trying to implement ResNeXt but rain into an error</p>\n<blockquote>\n  <p>ValueError: Input 0 of layer output1 is incompatible with the layer: expected axis -1 of input shape to have value 2048 but received input with shape [None, 204800]</p>\n</blockquote>\n<pre><code>def get_resnext(cfg):\n    model_input = tf.keras.Input(shape=(CFG['net_size'], CFG['net_size'], 3), name='ResNeXtInput') \n\n    x = get_model('resnext50_32x4d', pretrained=True, data_format=\"channels_last\")(model_input)\n    x = tf.keras.layers.Dropout(0.25)(x)\n    outputs = tf.keras.layers.Dense(len(classes), activation='softmax')(x) \n\n    model = tf.keras.Model(model_input, outputs, name='ResNeXt')\n    model.summary()\n    return model\n\ndef compile_resnext(cfg):    \n    with strategy.scope():\n        model = get_resnext(cfg)\n        model.compile(\n            optimizer = cfg['optimizer'],\n            loss      = tf.keras.losses.CategoricalCrossentropy(label_smoothing = cfg['label_smooth_fac']),\n            metrics   = tf.keras.metrics.CategoricalAccuracy(name='categorical_accuracy'))\n    return model\n</code></pre>",
      "rawMarkdown": "Thanks for sharing the repo.\nI was trying to implement ResNeXt but rain into an error\n> ValueError: Input 0 of layer output1 is incompatible with the layer: expected axis -1 of input shape to have value 2048 but received input with shape [None, 204800]\n\n```\ndef get_resnext(cfg):\n    model_input = tf.keras.Input(shape=(CFG['net_size'], CFG['net_size'], 3), name='ResNeXtInput') \n    \n    x = get_model('resnext50_32x4d', pretrained=True, data_format=\"channels_last\")(model_input)\n    x = tf.keras.layers.Dropout(0.25)(x)\n    outputs = tf.keras.layers.Dense(len(classes), activation='softmax')(x) \n    \n    model = tf.keras.Model(model_input, outputs, name='ResNeXt')\n    model.summary()\n    return model\n\ndef compile_resnext(cfg):    \n    with strategy.scope():\n        model = get_resnext(cfg)\n        model.compile(\n            optimizer = cfg['optimizer'],\n            loss      = tf.keras.losses.CategoricalCrossentropy(label_smoothing = cfg['label_smooth_fac']),\n            metrics   = tf.keras.metrics.CategoricalAccuracy(name='categorical_accuracy'))\n    return model\n```",
      "votes": null
    },
    {
      "id": "1163280",
      "postDate": "01/21/2021 16:04:54",
      "content": "<p><a href=\"https://www.kaggle.com/thakurudit\" target=\"_blank\">@thakurudit</a>  I have used this with 'in_size' parameter in get_model method. Here how I use this model</p>\n<pre><code>backbon = tf2cv_get_model(\"resnext50_32x4d\",\n                                  pretrained=True, \n                                  data_format=\"channels_last\",\n                                  in_size=(HEIGHT, WIDTH)\n                                  )\n\nbackbon.trainable = True\nmodel = tf.keras.Sequential([\n            backbon.features,\n            tf.keras.layers.GlobalAveragePooling2D(),\n            tf.keras.layers.Dense(5, activation='softmax')\n        ])\n</code></pre>\n<p>You would try with your code just to add 'in_size' extra parameter. </p>",
      "rawMarkdown": "thakurudit  I have used this with 'in_size' parameter in get_model method. Here how I use this model\n\n```\nbackbon = tf2cv_get_model(\"resnext50_32x4d\",\n                                  pretrained=True, \n                                  data_format=\"channels_last\",\n                                  in_size=(HEIGHT, WIDTH)\n                                  )\n\nbackbon.trainable = True\nmodel = tf.keras.Sequential([\n            backbon.features,\n            tf.keras.layers.GlobalAveragePooling2D(),\n            tf.keras.layers.Dense(5, activation='softmax')\n        ])\n```\n\nYou would try with your code just to add 'in_size' extra parameter.",
      "votes": null
    },
    {
      "id": "1163501",
      "postDate": "01/21/2021 17:46:26",
      "content": "<p>Thank You, I'll try this and report back the results.<br>\nEDIT: It works.</p>",
      "rawMarkdown": "Thank You, I'll try this and report back the results.\nEDIT: It works.",
      "votes": null
    },
    {
      "id": "1165087",
      "postDate": "01/22/2021 17:25:46",
      "content": "<p>It runs fine in my training notebook when I use<br>\n!pip install tf2cv<br>\nbut in my inference notebook, because there is no internet, I have to comment out<br>\n!pip install tf2cv<br>\nso when I run<br>\nfrom tf2cv.model_provider import get_model as tf2cv_get_model<br>\nI get this error:<br>\n----&gt; 4 net = tf2cv_get_model(model_name, pretrained=pretrained, data_format=\"channels_last\")<br>\nNameError: name 'tf2cv_get_model' is not defined</p>\n<p>If it already exists in the Kaggle environment, shouldn't it automatically work?</p>",
      "rawMarkdown": "It runs fine in my training notebook when I use\n!pip install tf2cv\nbut in my inference notebook, because there is no internet, I have to comment out\n!pip install tf2cv\nso when I run\nfrom tf2cv.model_provider import get_model as tf2cv_get_model\nI get this error:\n----> 4 net = tf2cv_get_model(model_name, pretrained=pretrained, data_format=\"channels_last\")\nNameError: name 'tf2cv_get_model' is not defined\n\nIf it already exists in the Kaggle environment, shouldn't it automatically work?",
      "votes": null
    },
    {
      "id": "1173222",
      "postDate": "01/27/2021 18:28:37",
      "content": "<p>Hey , can you please share your notebook also.<br>\nI am having some difficulties using it , that would be really helpful.<br>\nThank You</p>",
      "rawMarkdown": "Hey , can you please share your notebook also.\nI am having some difficulties using it , that would be really helpful.\nThank You",
      "votes": null
    },
    {
      "id": "1173679",
      "postDate": "01/28/2021 03:56:29",
      "content": "<p>you need to add tf2cv as dataset in your inference notebook and install it and import it. </p>",
      "rawMarkdown": "you need to add tf2cv as dataset in your inference notebook and install it and import it.",
      "votes": null
    },
    {
      "id": "1173931",
      "postDate": "01/28/2021 07:19:29",
      "content": "<p>while setting pre trained as True , <br>\nit is giving me error about shape input , </p>\n<p>Is it something like this like it needs to be runned with pre trained weights using image of size 224x224 only ?</p>",
      "rawMarkdown": "while setting pre trained as True , \nit is giving me error about shape input , \n\nIs it something like this like it needs to be runned with pre trained weights using image of size 224x224 only ?",
      "votes": null
    },
    {
      "id": "1191766",
      "postDate": "02/08/2021 16:51:43",
      "content": "<p>Is there any documentation for this library? I cant seem to find any at all except these 3 lines in their github page</p>",
      "rawMarkdown": "Is there any documentation for this library? I cant seem to find any at all except these 3 lines in their github page",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1158060,
      "author_name": "zhangeng",
      "author_url": "",
      "post_date": "01/18/2021 11:04:43",
      "content": "<p>thanks! Tomorrow I'm going to try</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1158493,
      "author_name": "thakurudit",
      "author_url": "",
      "post_date": "01/18/2021 15:39:38",
      "content": "<p>Thanks for sharing the repo.<br>\nI was trying to implement ResNeXt but rain into an error</p>\n<blockquote>\n  <p>ValueError: Input 0 of layer output1 is incompatible with the layer: expected axis -1 of input shape to have value 2048 but received input with shape [None, 204800]</p>\n</blockquote>\n<pre><code>def get_resnext(cfg):\n    model_input = tf.keras.Input(shape=(CFG['net_size'], CFG['net_size'], 3), name='ResNeXtInput') \n\n    x = get_model('resnext50_32x4d', pretrained=True, data_format=\"channels_last\")(model_input)\n    x = tf.keras.layers.Dropout(0.25)(x)\n    outputs = tf.keras.layers.Dense(len(classes), activation='softmax')(x) \n\n    model = tf.keras.Model(model_input, outputs, name='ResNeXt')\n    model.summary()\n    return model\n\ndef compile_resnext(cfg):    \n    with strategy.scope():\n        model = get_resnext(cfg)\n        model.compile(\n            optimizer = cfg['optimizer'],\n            loss      = tf.keras.losses.CategoricalCrossentropy(label_smoothing = cfg['label_smooth_fac']),\n            metrics   = tf.keras.metrics.CategoricalAccuracy(name='categorical_accuracy'))\n    return model\n</code></pre>",
      "votes": null,
      "replies": [
        {
          "id": 1163280,
          "author_name": "durbin164",
          "author_url": "",
          "post_date": "01/21/2021 16:04:54",
          "content": "<p><a href=\"https://www.kaggle.com/thakurudit\" target=\"_blank\">@thakurudit</a>  I have used this with 'in_size' parameter in get_model method. Here how I use this model</p>\n<pre><code>backbon = tf2cv_get_model(\"resnext50_32x4d\",\n                                  pretrained=True, \n                                  data_format=\"channels_last\",\n                                  in_size=(HEIGHT, WIDTH)\n                                  )\n\nbackbon.trainable = True\nmodel = tf.keras.Sequential([\n            backbon.features,\n            tf.keras.layers.GlobalAveragePooling2D(),\n            tf.keras.layers.Dense(5, activation='softmax')\n        ])\n</code></pre>\n<p>You would try with your code just to add 'in_size' extra parameter. </p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1163501,
          "author_name": "thakurudit",
          "author_url": "",
          "post_date": "01/21/2021 17:46:26",
          "content": "<p>Thank You, I'll try this and report back the results.<br>\nEDIT: It works.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1173931,
          "author_name": "prashantarorat",
          "author_url": "",
          "post_date": "01/28/2021 07:19:29",
          "content": "<p>while setting pre trained as True , <br>\nit is giving me error about shape input , </p>\n<p>Is it something like this like it needs to be runned with pre trained weights using image of size 224x224 only ?</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1165087,
      "author_name": "impulsecorp",
      "author_url": "",
      "post_date": "01/22/2021 17:25:46",
      "content": "<p>It runs fine in my training notebook when I use<br>\n!pip install tf2cv<br>\nbut in my inference notebook, because there is no internet, I have to comment out<br>\n!pip install tf2cv<br>\nso when I run<br>\nfrom tf2cv.model_provider import get_model as tf2cv_get_model<br>\nI get this error:<br>\n----&gt; 4 net = tf2cv_get_model(model_name, pretrained=pretrained, data_format=\"channels_last\")<br>\nNameError: name 'tf2cv_get_model' is not defined</p>\n<p>If it already exists in the Kaggle environment, shouldn't it automatically work?</p>",
      "votes": null,
      "replies": [
        {
          "id": 1173679,
          "author_name": "durbin164",
          "author_url": "",
          "post_date": "01/28/2021 03:56:29",
          "content": "<p>you need to add tf2cv as dataset in your inference notebook and install it and import it. </p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1173222,
      "author_name": "prashantarorat",
      "author_url": "",
      "post_date": "01/27/2021 18:28:37",
      "content": "<p>Hey , can you please share your notebook also.<br>\nI am having some difficulties using it , that would be really helpful.<br>\nThank You</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1191766,
      "author_name": "omeram",
      "author_url": "",
      "post_date": "02/08/2021 16:51:43",
      "content": "<p>Is there any documentation for this library? I cant seem to find any at all except these 3 lines in their github page</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1158011": "You may use this repository to experiment on some tensorflow version model related to computer vision.\n\nhttps://github.com/osmr/imgclsmob/tree/master/tensorflow2\n\nNote that it is already existing in Kaggle environment.\n\nExample:\nfrom tf2cv.model_provider import get_model as tf2cv_get_model\nimport tensorflow as tf\n\nnet = tf2cv_get_model(\"resnet18\", pretrained=True, data_format=\"channels_last\")\nx = tf.random.normal((1, 224, 224, 3))\ny_net = net(x)",
    "1158060": "thanks! Tomorrow I'm going to try",
    "1158493": "Thanks for sharing the repo.\nI was trying to implement ResNeXt but rain into an error\n> ValueError: Input 0 of layer output1 is incompatible with the layer: expected axis -1 of input shape to have value 2048 but received input with shape [None, 204800]\n\n```\ndef get_resnext(cfg):\n    model_input = tf.keras.Input(shape=(CFG['net_size'], CFG['net_size'], 3), name='ResNeXtInput') \n    \n    x = get_model('resnext50_32x4d', pretrained=True, data_format=\"channels_last\")(model_input)\n    x = tf.keras.layers.Dropout(0.25)(x)\n    outputs = tf.keras.layers.Dense(len(classes), activation='softmax')(x) \n    \n    model = tf.keras.Model(model_input, outputs, name='ResNeXt')\n    model.summary()\n    return model\n\ndef compile_resnext(cfg):    \n    with strategy.scope():\n        model = get_resnext(cfg)\n        model.compile(\n            optimizer = cfg['optimizer'],\n            loss      = tf.keras.losses.CategoricalCrossentropy(label_smoothing = cfg['label_smooth_fac']),\n            metrics   = tf.keras.metrics.CategoricalAccuracy(name='categorical_accuracy'))\n    return model\n```",
    "1163280": "thakurudit  I have used this with 'in_size' parameter in get_model method. Here how I use this model\n\n```\nbackbon = tf2cv_get_model(\"resnext50_32x4d\",\n                                  pretrained=True, \n                                  data_format=\"channels_last\",\n                                  in_size=(HEIGHT, WIDTH)\n                                  )\n\nbackbon.trainable = True\nmodel = tf.keras.Sequential([\n            backbon.features,\n            tf.keras.layers.GlobalAveragePooling2D(),\n            tf.keras.layers.Dense(5, activation='softmax')\n        ])\n```\n\nYou would try with your code just to add 'in_size' extra parameter.",
    "1163501": "Thank You, I'll try this and report back the results.\nEDIT: It works.",
    "1165087": "It runs fine in my training notebook when I use\n!pip install tf2cv\nbut in my inference notebook, because there is no internet, I have to comment out\n!pip install tf2cv\nso when I run\nfrom tf2cv.model_provider import get_model as tf2cv_get_model\nI get this error:\n----> 4 net = tf2cv_get_model(model_name, pretrained=pretrained, data_format=\"channels_last\")\nNameError: name 'tf2cv_get_model' is not defined\n\nIf it already exists in the Kaggle environment, shouldn't it automatically work?",
    "1173222": "Hey , can you please share your notebook also.\nI am having some difficulties using it , that would be really helpful.\nThank You",
    "1173679": "you need to add tf2cv as dataset in your inference notebook and install it and import it.",
    "1173931": "while setting pre trained as True , \nit is giving me error about shape input , \n\nIs it something like this like it needs to be runned with pre trained weights using image of size 224x224 only ?",
    "1191766": "Is there any documentation for this library? I cant seem to find any at all except these 3 lines in their github page"
  },
  "source": "meta"
}