{
  "id": 407196,
  "title": "Make Resnet accept single channel spectograms:",
  "url": "/competitions/birdclef-2023/discussion/407196",
  "author_name": "JEANMPIA",
  "post_date": "2023-05-05T12:56:28.022000",
  "votes": 1,
  "comment_count": 5,
  "views": 0,
  "content": "<p><strong>I struggled with this for some time but finally found a solution that wouldn't feel like I'm doing something wrong</strong> <em>(maybe I am idk)</em></p>\n<p>(Pytorch)</p>\n<pre><code>model = models.resnet18(weights=ResNet18_Weights.DEFAULT)\nmodel.fc = nn.Linear(, num_classes)\n\n\nmodel.conv1 = nn.Conv2d(, , kernel_size=(, ), stride=(, ), padding=(, ), bias=) \n</code></pre>\n<p>I know this won't help many people since the competiton is already coming to an end, but I would have appreciated it since I'm getting started doing computer vision. Hope it helps !<br>\n<a href=\"https://forums.fast.ai/t/how-to-make-a-resnet-do-black-and-white-images/63625\" target=\"_blank\">credit</a></p>",
  "messages": [
    {
      "id": 2246769,
      "postDate": "2023-05-05T12:56:28.023Z",
      "content": "<p><strong>I struggled with this for some time but finally found a solution that wouldn't feel like I'm doing something wrong</strong> <em>(maybe I am idk)</em></p>\n<p>(Pytorch)</p>\n<pre><code>model = models.resnet18(weights=ResNet18_Weights.DEFAULT)\nmodel.fc = nn.Linear(, num_classes)\n\n\nmodel.conv1 = nn.Conv2d(, , kernel_size=(, ), stride=(, ), padding=(, ), bias=) \n</code></pre>\n<p>I know this won't help many people since the competiton is already coming to an end, but I would have appreciated it since I'm getting started doing computer vision. Hope it helps !<br>\n<a href=\"https://forums.fast.ai/t/how-to-make-a-resnet-do-black-and-white-images/63625\" target=\"_blank\">credit</a></p>",
      "rawMarkdown": "**I struggled with this for some time but finally found a solution that wouldn't feel like I'm doing something wrong** *(maybe I am idk)*\n\n(Pytorch)\n```python\nmodel = models.resnet18(weights=ResNet18_Weights.DEFAULT)\nmodel.fc = nn.Linear(512, num_classes)\n\n#change the first layer so that it accepts single channel input\nmodel.conv1 = nn.Conv2d(1, 64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False) \n```\n\nI know this won't help many people since the competiton is already coming to an end, but I would have appreciated it since I'm getting started doing computer vision. Hope it helps !\n[credit](https://forums.fast.ai/t/how-to-make-a-resnet-do-black-and-white-images/63625)",
      "votes": 1
    },
    {
      "id": 2248280,
      "postDate": "2023-05-06T17:00:11.190Z",
      "content": "<p>How about using <a href=\"https://github.com/huggingface/pytorch-image-models\" target=\"_blank\">timm</a> library? It has <code>in_chans</code> param that allows you to configure the number of input channels.</p>\n<pre><code> timm\nmodel = timm.create_model(, in_chans=)\n</code></pre>",
      "rawMarkdown": "How about using [timm](https://github.com/huggingface/pytorch-image-models) library? It has `in_chans` param that allows you to configure the number of input channels.\n\n```python\n\nimport timm\nmodel = timm.create_model('{{ model_name }}', in_chans=1)\n```\n",
      "votes": 2,
      "replies": [
        {
          "id": 2248716,
          "postDate": "2023-05-07T06:08:47.793Z",
          "content": "<p>I learned about timm yesterday ! Good catch, nice to know thx</p>",
          "rawMarkdown": "I learned about timm yesterday ! Good catch, nice to know thx",
          "votes": 1
        }
      ]
    },
    {
      "id": 2246879,
      "postDate": "2023-05-05T14:27:57.707Z",
      "content": "<p>Great suggestion <a href=\"https://www.kaggle.com/janmpia\" target=\"_blank\">@janmpia</a> <br>\nThanx it is helpful</p>",
      "rawMarkdown": "Great suggestion @janmpia \nThanx it is helpful",
      "replies": [
        {
          "id": 2247131,
          "postDate": "2023-05-05T18:26:45.507Z",
          "content": "<p>glad I could help !</p>",
          "rawMarkdown": "glad I could help !"
        }
      ]
    },
    {
      "id": 2246878,
      "postDate": "2023-05-05T14:27:15.433Z",
      "rawMarkdown": "",
      "isDeleted": true
    }
  ],
  "comments": [
    {
      "id": 2248280,
      "author_name": "Sinan Calisir",
      "author_url": "",
      "post_date": "2023-05-06T17:00:11.190000",
      "content": "<p>How about using <a href=\"https://github.com/huggingface/pytorch-image-models\" target=\"_blank\">timm</a> library? It has <code>in_chans</code> param that allows you to configure the number of input channels.</p>\n<pre><code> timm\nmodel = timm.create_model(, in_chans=)\n</code></pre>",
      "votes": 2,
      "replies": [
        {
          "id": 2248716,
          "author_name": "JEANMPIA",
          "author_url": "",
          "post_date": "2023-05-07T06:08:47.793000",
          "content": "<p>I learned about timm yesterday ! Good catch, nice to know thx</p>",
          "votes": 1,
          "replies": []
        }
      ]
    },
    {
      "id": 2246879,
      "author_name": "Allena Venkata Sai Abhishek",
      "author_url": "",
      "post_date": "2023-05-05T14:27:57.707000",
      "content": "<p>Great suggestion <a href=\"https://www.kaggle.com/janmpia\" target=\"_blank\">@janmpia</a> <br>\nThanx it is helpful</p>",
      "votes": 0,
      "replies": [
        {
          "id": 2247131,
          "author_name": "JEANMPIA",
          "author_url": "",
          "post_date": "2023-05-05T18:26:45.507000",
          "content": "<p>glad I could help !</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 2246878,
      "author_name": "",
      "author_url": "",
      "post_date": "2023-05-05T14:27:15.433000",
      "content": "",
      "votes": 0,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "2246769": "**I struggled with this for some time but finally found a solution that wouldn't feel like I'm doing something wrong** *(maybe I am idk)*\n\n(Pytorch)\n```python\nmodel = models.resnet18(weights=ResNet18_Weights.DEFAULT)\nmodel.fc = nn.Linear(512, num_classes)\n\n#change the first layer so that it accepts single channel input\nmodel.conv1 = nn.Conv2d(1, 64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False) \n```\n\nI know this won't help many people since the competiton is already coming to an end, but I would have appreciated it since I'm getting started doing computer vision. Hope it helps !\n[credit](https://forums.fast.ai/t/how-to-make-a-resnet-do-black-and-white-images/63625)",
    "2248280": "How about using [timm](https://github.com/huggingface/pytorch-image-models) library? It has `in_chans` param that allows you to configure the number of input channels.\n\n```python\n\nimport timm\nmodel = timm.create_model('{{ model_name }}', in_chans=1)\n```\n",
    "2246879": "Great suggestion @janmpia \nThanx it is helpful",
    "2246878": ""
  }
}