baal: num_samples should be a positive integer value, but got num_samples=0
First, I would like to know if this project works with segmentation problems, namely Unet - this one in particular.
Also, I tried to run a simple pipeline but I am getting this error when creating the dataset. However, if I run that piece of code it works:
from torch.utils.data.dataloader import default_collate
for data, target in DataLoader(train_dataset, batch_size, True, num_workers=4,
                                           collate_fn=None):
    print(data)
My Dataset constructor:
class Dataset(BaseDataset): “”"CamVid Dataset. Read images, apply augmentation and preprocessing transformations.
Args:
    images_dir (str): path to images folder
    masks_dir (str): path to segmentation masks folder
    class_values (list): values of classes to extract from segmentation mask
    augmentation (albumentations.Compose): data transfromation pipeline 
        (e.g. flip, scale, etc.)
    preprocessing (albumentations.Compose): data preprocessing 
        (e.g. noralization, shape manipulation, etc.)
"""
    def __init__(
            self, 
            ids,
            images_dir, 
            masks_dir, 
            classes=None, 
            augmentation=None, 
            preprocessing=None,
            show_original=False
    ):
        self.ids = ids#os.listdir(images_dir)
        self.images_fps = [os.path.join(images_dir, image_id) for image_id in self.ids]
        self.masks_fps = [os.path.join(masks_dir, image_id) for image_id in self.ids]
        
        # convert str names to class values on masks
        self.class_values = [i+1 for i,c in enumerate(classes)]
        
        self.augmentation = augmentation
        self.preprocessing = preprocessing
        self.show_original=show_original
    
    def __getitem__(self, i):
        try:
            # read data
            #print(self.images_fps[i])
            filename=self.images_fps[i]
            if not filename.endswith(".png"):
                # Virtual openslide patch in form filename_col_x_row_y
                slide_name=Path(filename).stem.split("_col_")[0]
                roi_x,roi_y=filename.split("col_")[1].split("_row_")
                roi_xy_large=int(int(roi_x)*patch_size),int(int(roi_y)*patch_size)
            
                slide= openslide.open_slide(slide_paths[slide_name])
                image=slide.read_region(roi_xy_large,0,(patch_size,patch_size))
                #print((roi_xy_large,0,(patch_size,patch_size)))
                #plt.imshow(img)
                #plt.show()
                image=image.convert('RGB')
                if self.show_original:
                    plt.imshow(image)
                    plt.show()
                image = np.asarray(image)
                mask=None
                
            else:
                image = cv2.imread(filename)
                
                image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
                if self.show_original:
                    plt.imshow(image)
                    plt.show()
                #print(self.masks_fps[i])
                mask = cv2.imread(self.masks_fps[i], 0)
            
            # No mask, ex: false positives
            if mask is None:
                mask= PIL.Image.new('RGB', (256, 256), (0, 0, 0))
                mask=np.array(mask.convert("L"))
                
#             if image is None:
#                 image= PIL.Image.new('RGB', (256, 256), (0, 0, 0))
#                 image=np.array(image.convert("L"))
            #print('self.images_fps[i]',self.images_fps[i])
            #print('self.masks_fps[i]',self.masks_fps[i])
            #print('self.class_values:', self.class_values)
            #print('mask.max:', np.max(mask))
            #print('mask.min:', np.min(mask))
            #print('mask.unique:', np.unique(mask))
            # extract certain classes from mask (e.g. cars)
            masks = [(mask == v) for v in self.class_values]
            mask = np.stack(masks, axis=-1).astype('float')
            # apply augmentations
            if self.augmentation:
                sample = self.augmentation(image=image, mask=mask)
                image, mask = sample['image'], sample['mask']
#                 set_trace() if DEBUG else None
                
#                 mask[np.all(image == [0, 0, 0], axis=-1)]=0
            # apply preprocessing
            if self.preprocessing:
                sample = self.preprocessing(image=image, mask=mask)
                image, mask = sample['image'], sample['mask']
                
                
            return image, mask
            
        except Exception as error:
            print("error",error,self.images_fps[i],self.masks_fps[i])
            raise
    def __len__(self):
        return len(self.ids)
Regards
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 17 (8 by maintainers)
You can show the uncertainty per image pretty easily (again if you require better utils for this, we can work on it)
(not tested, but should work)