Issue creating a dataset in head-pose notebook

Hello, running the head-pose notebook, without any modification, in the part of the data object creation:

data = (ImageItemList.from_folder(path)
    .split_by_valid_func(lambda o: o.parent.name=='13')
    .label_from_func(get_ctr, label_cls=PointsItemList)
    .transform(get_transforms(), tfm_y=True, size=(120,160))
    .databunch().normalize(imagenet_stats)
   )

I got the following error:

ValueError                                Traceback (most recent call last)
<ipython-input-12-7a03611beb5d> in <module>
      1 data = (ImageItemList.from_folder(path)
      2         .split_by_valid_func(lambda o: o.parent.name=='13')
----> 3         .label_from_func(get_ctr, label_cls=PointsItemList)
      4         .transform(get_transforms(), tfm_y=True, size=(120,160))
      5         .databunch().normalize(imagenet_stats)

/opt/anaconda3/lib/python3.6/site-packages/fastai/data_block.py in _inner(*args, **kwargs)
294             self.valid = fv(*args, **kwargs)
295             self.__class__ = LabelLists
--> 296             self.process()
297             return self
298         return _inner

/opt/anaconda3/lib/python3.6/site-packages/fastai/data_block.py in process(self)
330     def process(self):
331         xp,yp = self.get_processors()
--> 332         for i,ds in enumerate(self.lists): ds.process(xp, yp, filter_missing_y=i==0)
333         return self
334 

/opt/anaconda3/lib/python3.6/site-packages/fastai/data_block.py in process(self, xp, yp, filter_missing_y)
392     def process(self, xp=None, yp=None, filter_missing_y:bool=False):
393         "Launch the preprocessing on `xp` and `yp`."
--> 394         self.y.process(yp)
395         if filter_missing_y and (getattr(self.x, 'filter_missing_y', None)):
396             filt = array([o is None for o in self.y])

/opt/anaconda3/lib/python3.6/site-packages/fastai/data_block.py in process(self, processor)
 46         if processor is not None: self.processor = processor
 47         self.processor = listify(self.processor)
---> 48         for p in self.processor: p.process(self)
 49         return self
 50 

/opt/anaconda3/lib/python3.6/site-packages/fastai/data_block.py in process(self, ds)
 20     def __init__(self, ds:Collection=None):  self.ref_ds = ds
 21     def process_one(self, item:Any):         return item
---> 22     def process(self, ds:Collection):        ds.items = array([self.process_one(item) for item in ds.items])
 23 
 24 class ItemList():

/opt/anaconda3/lib/python3.6/site-packages/fastai/core.py in array(a, *args, **kwargs)
218     "Same as `np.array` but also handles generators"
219     if not isinstance(a, collections.Sized): a = list(a)
--> 220     return np.array(a, *args, **kwargs)
221 
222 class Category(ItemBase):

`ValueError: only one element tensors can be converted to Python scalars`

I guess is due to the get_ctr function which returns a tensor with 2 components. How could could be managed? Or should I update any library?

3 Likes

Same issue here. Recently did git pull, conda update conda, and grabbed latest nightlies of all packages.

2 Likes

Getting the same error on the headpose notebook using fastai 1.27.0

Looks like the error arises from the split_by_valid_func. If I comment that line out and the databunch line, it does not error atleaset. So that is the line causing the error. Not entirely sure how to fix.

data = (ImageItemList.from_folder(path)
#         .split_by_valid_func(lambda o: o.parent.name=='13')
        .label_from_func(get_ctr, label_cls=PointsItemList)
        .transform(get_transforms(), tfm_y=True, size=(120,160))
#         .databunch().normalize(imagenet_stats)
       )
=== Software ===
python version  : 3.6.6
fastai version  : 1.0.27
torch version   : 1.0.0.dev20181024
nvidia driver   : 367.106
torch cuda ver  : 8.0.61
torch cuda is   : available
torch cudnn ver : 7102
torch cudnn is  : enabled

=== Hardware ===
nvidia gpus     : 1
torch available : 1
  - gpu0        : 11439MB | Tesla K80

=== Environment ===
platform        : Linux-4.4.82-x86_64-with-debian-8.11
distro          : #1 SMP Mon Aug 14 08:14:48 UTC 2017
conda env       : fastai-super
python          : /home/akomma/anaconda3/envs/fastai-super/bin/python
sys.path        :
/home/akomma/anaconda3/envs/fastai-super/bin
/home/akomma/anaconda3/envs/fastai-super/lib/python36.zip
/home/akomma/anaconda3/envs/fastai-super/lib/python3.6
/home/akomma/anaconda3/envs/fastai-super/lib/python3.6/lib-dynload
/home/akomma/anaconda3/envs/fastai-super/lib/python3.6/site-packages
/home/akomma/anaconda3/envs/fastai-super/lib/python3.6/site-packages/IPython/extensions
/home/akomma/.ipython

issue solved with fastai version ‘1.0.28’ :slight_smile:

1 Like