{
  "id": 205041,
  "title": "Need help: seresnet50 - Inference failed",
  "url": "/competitions/ranzcr-clip-catheter-line-classification/discussion/205041",
  "author_name": "",
  "post_date": "2020-12-18T07:53:50.258325700Z",
  "votes": null,
  "comment_count": 2,
  "views": 0,
  "content": "<p>Hi everyone,</p>\n<p>I've tried seresnet50, and the results seem promising. The inference is running fine within the notebook. However, when I try to save and commit, the problem occurs, saying that: 'SENet' object has no attribute 'fc'. The 'fc' comes from:</p>\n<pre><code>class CustomSeResnet(nn.Module):\n    def __init__(self, model_name='seresnet50', pretrained=False):\n        super().__init__()\n        self.model = timm.create_model(model_name, pretrained=pretrained)\n        n_features = self.model.fc.in_features\n        self.model.fc = nn.Linear(n_features, CFG.target_size)\n\n    def forward(self, x):\n        x = self.model(x)\n        return x\n</code></pre>\n<p>If anyone has any ideas, I would highly appreciate.<br>\nThank you.</p>",
  "messages": [
    {
      "id": "1117565",
      "postDate": "12/18/2020 07:53:50",
      "content": "<p>Hi everyone,</p>\n<p>I've tried seresnet50, and the results seem promising. The inference is running fine within the notebook. However, when I try to save and commit, the problem occurs, saying that: 'SENet' object has no attribute 'fc'. The 'fc' comes from:</p>\n<pre><code>class CustomSeResnet(nn.Module):\n    def __init__(self, model_name='seresnet50', pretrained=False):\n        super().__init__()\n        self.model = timm.create_model(model_name, pretrained=pretrained)\n        n_features = self.model.fc.in_features\n        self.model.fc = nn.Linear(n_features, CFG.target_size)\n\n    def forward(self, x):\n        x = self.model(x)\n        return x\n</code></pre>\n<p>If anyone has any ideas, I would highly appreciate.<br>\nThank you.</p>",
      "rawMarkdown": "Hi everyone,\n\nI've tried seresnet50, and the results seem promising. The inference is running fine within the notebook. However, when I try to save and commit, the problem occurs, saying that: 'SENet' object has no attribute 'fc'. The 'fc' comes from:\n```\n\nclass CustomSeResnet(nn.Module):\n    def __init__(self, model_name='seresnet50', pretrained=False):\n        super().__init__()\n        self.model = timm.create_model(model_name, pretrained=pretrained)\n        n_features = self.model.fc.in_features\n        self.model.fc = nn.Linear(n_features, CFG.target_size)\n\n    def forward(self, x):\n        x = self.model(x)\n        return x\n\n```\nIf anyone has any ideas, I would highly appreciate.\nThank you.",
      "votes": null
    },
    {
      "id": "1117655",
      "postDate": "12/18/2020 09:57:27",
      "content": "<p>In the init, are you using <code>model.fc</code> before it is defined when you go <code>n_features = self.model.fc.in_features</code>? Should that be <code>n_features = self.model.classifier.in_features</code>?</p>",
      "rawMarkdown": "In the init, are you using `model.fc` before it is defined when you go `n_features = self.model.fc.in_features`? Should that be `n_features = self.model.classifier.in_features`?",
      "votes": null
    },
    {
      "id": "1118020",
      "postDate": "12/18/2020 17:01:06",
      "content": "<p>Hi, thank you for your response. Models like resnets actually have the \"model.fc.in_features\", that's why my inference pipeline runs just fine within the notebook. The problem just appears when I try to save and commit. It's kind of weird.</p>",
      "rawMarkdown": "Hi, thank you for your response. Models like resnets actually have the \"model.fc.in_features\", that's why my inference pipeline runs just fine within the notebook. The problem just appears when I try to save and commit. It's kind of weird.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1117655,
      "author_name": "bjoernholzhauer",
      "author_url": "",
      "post_date": "12/18/2020 09:57:27",
      "content": "<p>In the init, are you using <code>model.fc</code> before it is defined when you go <code>n_features = self.model.fc.in_features</code>? Should that be <code>n_features = self.model.classifier.in_features</code>?</p>",
      "votes": null,
      "replies": [
        {
          "id": 1118020,
          "author_name": "trungn2015",
          "author_url": "",
          "post_date": "12/18/2020 17:01:06",
          "content": "<p>Hi, thank you for your response. Models like resnets actually have the \"model.fc.in_features\", that's why my inference pipeline runs just fine within the notebook. The problem just appears when I try to save and commit. It's kind of weird.</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1117565": "Hi everyone,\n\nI've tried seresnet50, and the results seem promising. The inference is running fine within the notebook. However, when I try to save and commit, the problem occurs, saying that: 'SENet' object has no attribute 'fc'. The 'fc' comes from:\n```\n\nclass CustomSeResnet(nn.Module):\n    def __init__(self, model_name='seresnet50', pretrained=False):\n        super().__init__()\n        self.model = timm.create_model(model_name, pretrained=pretrained)\n        n_features = self.model.fc.in_features\n        self.model.fc = nn.Linear(n_features, CFG.target_size)\n\n    def forward(self, x):\n        x = self.model(x)\n        return x\n\n```\nIf anyone has any ideas, I would highly appreciate.\nThank you.",
    "1117655": "In the init, are you using `model.fc` before it is defined when you go `n_features = self.model.fc.in_features`? Should that be `n_features = self.model.classifier.in_features`?",
    "1118020": "Hi, thank you for your response. Models like resnets actually have the \"model.fc.in_features\", that's why my inference pipeline runs just fine within the notebook. The problem just appears when I try to save and commit. It's kind of weird."
  },
  "source": "meta"
}