{
  "id": 155932,
  "title": "Getting nan as model output",
  "url": "/competitions/siim-isic-melanoma-classification/discussion/155932",
  "author_name": "",
  "post_date": "2020-06-03T15:29:14.487269500Z",
  "votes": null,
  "comment_count": 3,
  "views": 0,
  "content": "<p>I am training efficientnetb3 model (pretrained) using Stratified K-fold but getting 'nan' as model output . I have used some basic transformations like Horizontal Flip, Vertical Flip , CentreCrop and Normalization.</p>\n\n<pre><code>class MelanomaDataset(Dataset):\n\n    def __init__(self, dataframe, image_dir, transforms = None):\n        self.dataframe = dataframe\n        self.image_dir = image_dir\n        self.transforms = transforms\n\n    def __len__(self):\n        return self.dataframe.shape[0]\n\n    def __getitem__(self, idx):\n        img_name = '{}.png'.format(self.dataframe.iloc[idx, 0])\n        fullname = self.image_dir + img_name\n        image = cv2.imread(fullname)\n        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n\n        num = self.dataframe.loc[:,'target'].iloc[idx]\n        label = np.asarray(int_to_label[num])\n\n        if self.transforms:\n            image = self.transforms(image = image)['image']\n\n        return image, label\n</code></pre>",
  "messages": [
    {
      "id": "872888",
      "postDate": "06/03/2020 15:29:14",
      "content": "<p>I am training efficientnetb3 model (pretrained) using Stratified K-fold but getting 'nan' as model output . I have used some basic transformations like Horizontal Flip, Vertical Flip , CentreCrop and Normalization.</p>\n\n<pre><code>class MelanomaDataset(Dataset):\n\n    def __init__(self, dataframe, image_dir, transforms = None):\n        self.dataframe = dataframe\n        self.image_dir = image_dir\n        self.transforms = transforms\n\n    def __len__(self):\n        return self.dataframe.shape[0]\n\n    def __getitem__(self, idx):\n        img_name = '{}.png'.format(self.dataframe.iloc[idx, 0])\n        fullname = self.image_dir + img_name\n        image = cv2.imread(fullname)\n        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n\n        num = self.dataframe.loc[:,'target'].iloc[idx]\n        label = np.asarray(int_to_label[num])\n\n        if self.transforms:\n            image = self.transforms(image = image)['image']\n\n        return image, label\n</code></pre>",
      "rawMarkdown": "I am training efficientnetb3 model (pretrained) using Stratified K-fold but getting 'nan' as model output . I have used some basic transformations like Horizontal Flip, Vertical Flip , CentreCrop and Normalization.\n\n\n\n    class MelanomaDataset(Dataset):\n    \n        def __init__(self, dataframe, image_dir, transforms = None):\n            self.dataframe = dataframe\n            self.image_dir = image_dir\n            self.transforms = transforms\n\n        def __len__(self):\n            return self.dataframe.shape[0]\n\n        def __getitem__(self, idx):\n            img_name = '{}.png'.format(self.dataframe.iloc[idx, 0])\n            fullname = self.image_dir + img_name\n            image = cv2.imread(fullname)\n            image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n        \n            num = self.dataframe.loc[:,'target'].iloc[idx]\n            label = np.asarray(int_to_label[num])\n\n            if self.transforms:\n                image = self.transforms(image = image)['image']\n\n            return image, label",
      "votes": null
    },
    {
      "id": "872945",
      "postDate": "06/03/2020 16:11:24",
      "content": "<p>I think you should be returning torch.tensor(label) ? The image mostly gets converted to tensor due to the ToTensor() used in augs , but not the case for labels. Also , can you share the model code?</p>",
      "rawMarkdown": "I think you should be returning torch.tensor(label) ? The image mostly gets converted to tensor due to the ToTensor() used in augs , but not the case for labels. Also , can you share the model code?",
      "votes": null
    },
    {
      "id": "873032",
      "postDate": "06/03/2020 17:54:38",
      "content": "<p>There's no issue with the labels as I have checked it. I am using a pretrained model from timm models </p>",
      "rawMarkdown": "There's no issue with the labels as I have checked it. I am using a pretrained model from timm models",
      "votes": null
    },
    {
      "id": "873049",
      "postDate": "06/03/2020 18:16:49",
      "content": "<p>I cannot really say then , without looking at the rest of the code.. The dataset class seems fine otherwise.</p>",
      "rawMarkdown": "I cannot really say then , without looking at the rest of the code.. The dataset class seems fine otherwise.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 872945,
      "author_name": "p4rallax",
      "author_url": "",
      "post_date": "06/03/2020 16:11:24",
      "content": "<p>I think you should be returning torch.tensor(label) ? The image mostly gets converted to tensor due to the ToTensor() used in augs , but not the case for labels. Also , can you share the model code?</p>",
      "votes": null,
      "replies": [
        {
          "id": 873032,
          "author_name": "chetan06",
          "author_url": "",
          "post_date": "06/03/2020 17:54:38",
          "content": "<p>There's no issue with the labels as I have checked it. I am using a pretrained model from timm models </p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 873049,
          "author_name": "p4rallax",
          "author_url": "",
          "post_date": "06/03/2020 18:16:49",
          "content": "<p>I cannot really say then , without looking at the rest of the code.. The dataset class seems fine otherwise.</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "872888": "I am training efficientnetb3 model (pretrained) using Stratified K-fold but getting 'nan' as model output . I have used some basic transformations like Horizontal Flip, Vertical Flip , CentreCrop and Normalization.\n\n\n\n    class MelanomaDataset(Dataset):\n    \n        def __init__(self, dataframe, image_dir, transforms = None):\n            self.dataframe = dataframe\n            self.image_dir = image_dir\n            self.transforms = transforms\n\n        def __len__(self):\n            return self.dataframe.shape[0]\n\n        def __getitem__(self, idx):\n            img_name = '{}.png'.format(self.dataframe.iloc[idx, 0])\n            fullname = self.image_dir + img_name\n            image = cv2.imread(fullname)\n            image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n        \n            num = self.dataframe.loc[:,'target'].iloc[idx]\n            label = np.asarray(int_to_label[num])\n\n            if self.transforms:\n                image = self.transforms(image = image)['image']\n\n            return image, label",
    "872945": "I think you should be returning torch.tensor(label) ? The image mostly gets converted to tensor due to the ToTensor() used in augs , but not the case for labels. Also , can you share the model code?",
    "873032": "There's no issue with the labels as I have checked it. I am using a pretrained model from timm models",
    "873049": "I cannot really say then , without looking at the rest of the code.. The dataset class seems fine otherwise."
  },
  "source": "meta"
}