Help on SegmentationItemList

(Gokul) #1

Hi Guys,

I was working on replicating the Image Segmention task on the TGS Salt segmentation challenge on kaggle. (https://www.kaggle.com/c/tgs-salt-identification-challenge)
When trying to get the databunch, I ran into an error in getting the src right.

src = (SegmentationItemList.from_folder(train_images, extensions=".png")
        .random_split_by_pct()
        .label_from_func(get_y_path)
      )

where train_images is the path for the train images and
get_y_fn provides the labels (the segmented images)

The above code segment generates the following error:

/opt/anaconda3/lib/python3.7/site-packages/fastai/vision/data.py in process(self, ds)![41%20AM|558x500]
    355     "`PreProcessor` that stores the classes for segmentation."
    356     def __init__(self, ds:ItemList): self.classes = ds.classes
--> 357     def process(self, ds:ItemList):  ds.classes,ds.c = self.classes,len(self.classes)
    358 

359 class SegmentationLabelList(ImageItemList):

TypeError: object of type ‘NoneType’ has no len().

I tried to trace out the hierarchy of the objects and was not able to understand what went wrong. The same piece of code works well for ImageItemList class.

Any direction would be a great help!

Thanks,
Gokul

1 Like

(Renato Hermoza) #2

I think you need to add classes in label_from_func

your_classes = # should be a list with your class names eg:  ['cat', 'dog', 'pig'...]
.label_from_func(get_y_path, classes=your_clases)
3 Likes

(Gokul) #3

Thanks so much Renato! Adding classes fixed the problem.

0 Likes

#4

Yes, add a “background” class is OK

0 Likes