sbongo
(bruce)
October 30, 2018, 3:58am
1
Hi,
Why does the SegmentationDataset requires a parameter of “classes” when we are already supplying the “y images”?
@classmethod
def from_folder(cls, path:PathOrStr, folder:PathOrStr, fns:pd.Series, labels:ImgLabels, valid_pct:float=0.2,
classes:Optional[Collection[Any]]=None):
path = Path(path)
folder_path = (path/folder).absolute()
train,valid = random_split(valid_pct, f'{folder_path}/' + fns, labels)
train_ds = cls(*train, classes=classes)
return [train_ds,cls(*valid, classes=train_ds.classes)]
class SegmentationDataset(ImageDataset):
"A dataset for segmentation task."
def __init__(self, x:FilePathList, y:FilePathList, classes:Collection[Any], div=False, convert_mode='L'):
assert len(x)==len(y)
super().__init__(classes)
self.x,self.y,self.div,self.convert_mode = np.array(x),np.array(y),div,convert_mode
self.loss_func = CrossEntropyFlat()
def _get_x(self,i): return open_image(self.x[i])
def _get_y(self,i): return open_mask(self.y[i], self.div, self.convert_mode)
Thanks!
jeremy
(Jeremy Howard)
October 30, 2018, 6:13am
2
So that you can print out the name of a class. Also, getting all the unique values of every pixel would take a long time!
1 Like
sbongo
(bruce)
October 30, 2018, 6:33am
3
hey Jeremy,
thanks for the reply. Let me get this right:
x is the list of path of training files(eg. images of car with background)
y is the list of path of testing files(eg. mask of car only)
in that case, what should be the classes?
Thanks!
gsg
(German Goldszmidt)
October 30, 2018, 9:38am
4
@sbongo The classes are the types of entities, eg car, building, road, tree, etc.
In a single image there can be multiple entities.
1 Like