{
  "id": 40249,
  "title": "How to modify ResNet?",
  "url": "/competitions/cdiscount-image-classification-challenge/discussion/40249",
  "author_name": "",
  "post_date": "2017-09-30T02:58:30.763599900Z",
  "votes": null,
  "comment_count": 3,
  "views": 0,
  "content": "<p>I am trying to use ResNet 34 but got the following error</p>\n\n<pre><code>RuntimeError: Given input size: (512x4x4). Calculated output size: (512x0x0).\n</code></pre>\n\n<p>It seems like it's because at the average pooling later, torchvision use an average pooling layer nn.AvgPool2d(7) with kernal size 7 which is large than 4. So I am wondering how to modify it (Or there may be other reason to cause the problme)</p>\n\n<p>My idea is just change the kernel size to 4 or less but I want to know what's the best solution?</p>",
  "messages": [
    {
      "id": "225817",
      "postDate": "09/30/2017 02:58:30",
      "content": "<p>I am trying to use ResNet 34 but got the following error</p>\n\n<pre><code>RuntimeError: Given input size: (512x4x4). Calculated output size: (512x0x0).\n</code></pre>\n\n<p>It seems like it's because at the average pooling later, torchvision use an average pooling layer nn.AvgPool2d(7) with kernal size 7 which is large than 4. So I am wondering how to modify it (Or there may be other reason to cause the problme)</p>\n\n<p>My idea is just change the kernel size to 4 or less but I want to know what's the best solution?</p>",
      "rawMarkdown": "I am trying to use ResNet 34 but got the following error\n\n    RuntimeError: Given input size: (512x4x4). Calculated output size: (512x0x0).\nIt seems like it's because at the average pooling later, torchvision use an average pooling layer nn.AvgPool2d(7) with kernal size 7 which is large than 4. So I am wondering how to modify it (Or there may be other reason to cause the problme)\n\nMy idea is just change the kernel size to 4 or less but I want to know what's the best solution?",
      "votes": null
    },
    {
      "id": "225881",
      "postDate": "09/30/2017 08:40:30",
      "content": "<p>Use the functional interface, and modify the forward method. y = F.avg_pool2d(x, (x.size(2), x.size(3)))</p>",
      "rawMarkdown": "Use the functional interface, and modify the forward method. y = F.avg_pool2d(x, (x.size(2), x.size(3)))",
      "votes": null
    },
    {
      "id": "225891",
      "postDate": "09/30/2017 08:57:01",
      "content": "<p>ResNet was built with 244x244 images in mind. If you're using smaller Images you will get a smaller output (HxW). Changing the pooling layer like ajmooch suggested or with another method should be fine.</p>",
      "rawMarkdown": "ResNet was built with 244x244 images in mind. If you're using smaller Images you will get a smaller output (HxW). Changing the pooling layer like ajmooch suggested or with another method should be fine.",
      "votes": null
    },
    {
      "id": "225947",
      "postDate": "09/30/2017 13:58:44",
      "content": "<p>I am just wondering what's the impact if I change the pooling layer</p>",
      "rawMarkdown": "I am just wondering what's the impact if I change the pooling layer",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 225881,
      "author_name": "ajmooch",
      "author_url": "",
      "post_date": "09/30/2017 08:40:30",
      "content": "<p>Use the functional interface, and modify the forward method. y = F.avg_pool2d(x, (x.size(2), x.size(3)))</p>",
      "votes": null,
      "replies": [
        {
          "id": 225947,
          "author_name": "strideradu",
          "author_url": "",
          "post_date": "09/30/2017 13:58:44",
          "content": "<p>I am just wondering what's the impact if I change the pooling layer</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 225891,
      "author_name": "nanigans",
      "author_url": "",
      "post_date": "09/30/2017 08:57:01",
      "content": "<p>ResNet was built with 244x244 images in mind. If you're using smaller Images you will get a smaller output (HxW). Changing the pooling layer like ajmooch suggested or with another method should be fine.</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "225817": "I am trying to use ResNet 34 but got the following error\n\n    RuntimeError: Given input size: (512x4x4). Calculated output size: (512x0x0).\nIt seems like it's because at the average pooling later, torchvision use an average pooling layer nn.AvgPool2d(7) with kernal size 7 which is large than 4. So I am wondering how to modify it (Or there may be other reason to cause the problme)\n\nMy idea is just change the kernel size to 4 or less but I want to know what's the best solution?",
    "225881": "Use the functional interface, and modify the forward method. y = F.avg_pool2d(x, (x.size(2), x.size(3)))",
    "225891": "ResNet was built with 244x244 images in mind. If you're using smaller Images you will get a smaller output (HxW). Changing the pooling layer like ajmooch suggested or with another method should be fine.",
    "225947": "I am just wondering what's the impact if I change the pooling layer"
  },
  "source": "meta"
}