I want to use Image Regression for Bounding Boxes. I thought the objects ImageBBox were supposed to be the labels of images, when creating a PointsItemList, calling a BBox creating function create_bbox
:
def np_from_img(img_file):
t = np.atleast_2d(np.genfromtxt(img2txt_name(file_exmpl))[...,:-1])
# Reordering coordinates to fit fastai standard
t[:,0],t[:,1] = t[:,1],t[:,0].copy()
t[:,2],t[:,3] = t[:,3],t[:,2].copy()
return t
def create_bbox(item, show=False):
img = open_image(item)
bbox = ImageBBox.create(*img.size, np_from_img(item))
if show:
img.show(y=bbox)
return bbox
items = PointsItemList.from_folder(data_folder).split_by_folder(valid='test')
items.label_from_func(create_bbox)
I get the error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-12-fb422eb58eeb> in <module>
----> 1 items.label_from_func(create_bbox)
~/miniconda3/envs/fastai/lib/python3.7/site-packages/fastai/data_block.py in _inner(*args, **kwargs)
391 self.valid = fv(*args, **kwargs)
392 self.__class__ = LabelLists
--> 393 self.process()
394 return self
395 return _inner
~/miniconda3/envs/fastai/lib/python3.7/site-packages/fastai/data_block.py in process(self)
437 def process(self):
438 "Process the inner datasets."
--> 439 xp,yp = self.get_processors()
440 for i,ds in enumerate(self.lists): ds.process(xp, yp, filter_missing_y=i==0)
441 return self
~/miniconda3/envs/fastai/lib/python3.7/site-packages/fastai/data_block.py in get_processors(self)
432 procs_x,procs_y = listify(self.train.x._processor),listify(self.train.y._processor)
433 xp = ifnone(self.train.x.processor, [p(ds=self.train.x) for p in procs_x])
--> 434 yp = ifnone(self.train.y.processor, [p(ds=self.train.y) for p in procs_y])
435 return xp,yp
436
~/miniconda3/envs/fastai/lib/python3.7/site-packages/fastai/data_block.py in <listcomp>(.0)
432 procs_x,procs_y = listify(self.train.x._processor),listify(self.train.y._processor)
433 xp = ifnone(self.train.x.processor, [p(ds=self.train.x) for p in procs_x])
--> 434 yp = ifnone(self.train.y.processor, [p(ds=self.train.y) for p in procs_y])
435 return xp,yp
436
~/miniconda3/envs/fastai/lib/python3.7/site-packages/fastai/vision/data.py in __init__(self, ds)
385 class PointsProcessor(PreProcessor):
386 "`PreProcessor` that stores the number of targets for point regression."
--> 387 def __init__(self, ds:ItemList): self.c = len(ds.items[0].reshape(-1))
388 def process(self, ds:ItemList): ds.c = self.c
389
AttributeError: 'ImageBBox' object has no attribute 'reshape'
I guess this means, it accepts numpy arrays instead of ImageBBox objects, and I am not understanding how to use them.
I saw here that @sgugger was mentioning PointsItemList
should be subclassed, but I am not sure if he refers to the same.
I am Using:
python : 3.7.1
fastai : 1.0.38