Apologies if this is the wrong place to ask. Also, the method I’m trying to use may be completely wrong, please let me know if it is.
I made a custom ItemList for a segmentation task where the masks are run length encoded. All the data are in a pandas dataframe with columns: image id, rle encoded pixels, image height, image width, class.
The ItemList correctly returns a list of tuples of types (Image, ImageSegment) but it seems that since the itemlist.items are tuples I get an error when I try to split into training and validation that my index is not scaler.
sl = (SegRleList.from_df(train_df, path, cols=[0,1,2,3], folder='train'))
SegRleList (333415 items)
(Image (3, 5214, 3676), ImageSegment (1, 5214, 3676)),(Image (3, 5214, 3676), ImageSegment (1, 5214, 3676)),(Image (3, 5214, 3676), ImageSegment (1, 5214, 3676)),(Image (3, 5214, 3676), ImageSegment (1, 5214, 3676)),(Image (3, 5214, 3676), ImageSegment (1, 5214, 3676))
Path: .
code below
@classmethod
def from_df(cls, df:DataFrame, path:PathOrStr, cols:IntsOrStrs=0,
folder:PathOrStr=None, suffix:str='', **kwargs)->'ItemList':
"Get the filenames in `cols` of `df` with `folder` in front of them, `suffix` at the end."
suffix = suffix or ''
res = super().from_df(df, path=path, cols=cols[0], **kwargs)
msk = ItemList.from_df(train_df, path, cols=[1,2,3])
pref = f'{res.path}{os.path.sep}'
if folder is not None: pref += f'{folder}{os.path.sep}'
res.items = np.char.add(np.char.add(pref, res.items.astype(str)), suffix)
res.items = [(res.items[i], msk[i]) for i in range(len(res.items))]
return res
def get(self, i):
fn = super().get(i)[0]
mn = super().get(i)[1:]
mask = open_mask_rle(mn[0][0], (mn[0][1], mn[0][2]))
res = self.open(fn)
self.sizes[i] = res.size
return res, mask
and the error:
TypeError: only integer scalar arrays can be converted to a scalar index
Any advice is welcome.