msamogh/nonechucks

With Safedataset and Safedataloader did I should change dataset?

lucasjinreal opened this issue · 3 comments

Hi, Your solution are more wise and resonable, My simple original dataset getitem are:

  def __getitem__(self, index):
        data_file = self.files[self.split][index]
        # load image
        img_file = data_file['img']

        # PIL corrupt sometimes
        img = PIL.Image.open(img_file)
        # img = cv2.cvtColor(cv2.imread(img_file), cv2.COLOR_BGR2RGB)
        img = np.array(img, dtype=np.uint8)

        # load label
        lbl_file = data_file['lbl']
        lbl = PIL.Image.open(lbl_file)
        # lbl = cv2.imread(lbl_file, 0)
        # lbl = np.array(lbl / 255, dtype=np.uint8)
        lbl = np.array(lbl, dtype=np.int32)
        lbl[lbl == 255] = -1
        if self._transform:
            return self.transform(img, lbl)
        else:
            return img, lbl

I wonder, with those wrappers:

   train_dataset = SafeDataset(VOC2012ClassSeg(root=voc_root, transform=True))
    train_loader = SafeDataLoader(train_dataset, batch_size=1, shuffle=True)

    val_dataset = SafeDataset(VOC2011ClassSeg(root=voc_root, split='seg11valid', transform=True))
    val_loader = SafeDataLoader(val_dataset, batch_size=1, shuffle=False)

Should I still need to try....excaption that corrupt image?
I have one corrupt image, and I dont know which one. I can try..except that, but I just can not return None value, or next index

Oh, no... Safedataset wrapper can not inferite my attribute of original dataset. So I can not access my dataset n_classes or anyother field in somewhere else.

I'm not sure I fully understand your first question, but you can either return None or raise an Exception when you encounter a corrupt image, and nonechucks will handle it for you.

As for your second issue, you can still access your original dataset with the .dataset attribute of your SafeDataset instance - so, it would be something like train_dataset.dataset.n_classes.

@msamogh Thanks, seems reasonable