05_pet_breeds Error at dls.show_batch in Checking and Debugging DataBlock

Also affects 06_multicat

Signature: dls.show_batch(b=None, max_n=9, ctxs=None, show=True, **kwargs)
Docstring:
File: ~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastai2/data/core.py
Type: method

dls.show_batch(rows=1, cols=3)


AttributeError Traceback (most recent call last)
in
----> 1 dls.show_batch(rows=1, cols=3)

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastai2/data/core.py in show_batch(self, b, max_n, ctxs, show, **kwargs)
90 if b is None: b = self.one_batch()
91 if not show: return self._pre_show_batch(b, max_n=max_n)
—> 92 show_batch(*self._pre_show_batch(b, max_n=max_n), ctxs=ctxs, max_n=max_n, **kwargs)
93
94 def show_results(self, b, out, max_n=9, ctxs=None, show=True, **kwargs):

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastcore/dispatch.py in call(self, *args, **kwargs)
96 if not f: return args[0]
97 if self.inst is not None: f = MethodType(f, self.inst)
—> 98 return f(*args, **kwargs)
99
100 def get(self, inst, owner):

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastai2/vision/data.py in show_batch(x, y, samples, ctxs, max_n, nrows, ncols, figsize, **kwargs)
43 def show_batch(x:TensorImage, y, samples, ctxs=None, max_n=10, nrows=None, ncols=None, figsize=None, **kwargs):
44 if ctxs is None: ctxs = get_grid(min(len(samples), max_n), nrows=nrows, ncols=ncols, figsize=figsize)
—> 45 ctxs = show_batch[object](x, y, samples, ctxs=ctxs, max_n=max_n, **kwargs)
46 return ctxs
47

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastai2/data/core.py in show_batch(x, y, samples, ctxs, max_n, **kwargs)
13 if ctxs is None: ctxs = Inf.nones
14 for i in range_of(samples[0]):
—> 15 ctxs = [b.show(ctx=c, **kwargs) for b,c,_ in zip(samples.itemgot(i),ctxs,range(max_n))]
16 return ctxs
17

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastai2/data/core.py in (.0)
13 if ctxs is None: ctxs = Inf.nones
14 for i in range_of(samples[0]):
—> 15 ctxs = [b.show(ctx=c, **kwargs) for b,c,_ in zip(samples.itemgot(i),ctxs,range(max_n))]
16 return ctxs
17

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastai2/torch_core.py in show(self, ctx, **kwargs)
296 _show_args = ArrayImageBase._show_args
297 def show(self, ctx=None, **kwargs):
–> 298 return show_image(self, ctx=ctx, **{**self._show_args, **kwargs})
299
300 # Cell

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastai2/torch_core.py in show_image(im, ax, figsize, title, ctx, **kwargs)
52 if figsize is None: figsize = (_fig_bounds(im.shape[0]), _fig_bounds(im.shape[1]))
53 if ax is None: _,ax = plt.subplots(figsize=figsize)
—> 54 ax.imshow(im, **kwargs)
55 if title is not None: ax.set_title(title)
56 ax.axis(‘off’)

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/matplotlib/init.py in inner(ax, data, *args, **kwargs)
1597 def inner(ax, *args, data=None, **kwargs):
1598 if data is None:
-> 1599 return func(ax, *map(sanitize_sequence, args), **kwargs)
1600
1601 bound = new_sig.bind(ax, *args, **kwargs)

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/matplotlib/cbook/deprecation.py in wrapper(*args, **kwargs)
367 f"%(removal)s. If any parameter follows {name!r}, they "
368 f"should be pass as keyword, not positionally.")
–> 369 return func(*args, **kwargs)
370
371 return wrapper

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/matplotlib/cbook/deprecation.py in wrapper(*args, **kwargs)
367 f"%(removal)s. If any parameter follows {name!r}, they "
368 f"should be pass as keyword, not positionally.")
–> 369 return func(*args, **kwargs)
370
371 return wrapper

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/matplotlib/axes/_axes.py in imshow(self, X, cmap, norm, aspect, interpolation, alpha, vmin, vmax, origin, extent, shape, filternorm, filterrad, imlim, resample, url, **kwargs)
5675 im = mimage.AxesImage(self, cmap, norm, interpolation, origin, extent,
5676 filternorm=filternorm, filterrad=filterrad,
-> 5677 resample=resample, **kwargs)
5678
5679 im.set_data(X)

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/matplotlib/image.py in init(self, ax, cmap, norm, interpolation, origin, extent, filternorm, filterrad, resample, **kwargs)
862 filterrad=filterrad,
863 resample=resample,
–> 864 **kwargs
865 )
866

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/matplotlib/image.py in init(self, ax, cmap, norm, interpolation, origin, filternorm, filterrad, resample, **kwargs)
218 self._imcache = None
219
–> 220 self.update(kwargs)
221
222 def getstate(self):

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/matplotlib/artist.py in update(self, props)
972
973 with cbook._setattr_cm(self, eventson=False):
–> 974 ret = [_update_property(self, k, v) for k, v in props.items()]
975
976 if len(ret):

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/matplotlib/artist.py in (.0)
972
973 with cbook._setattr_cm(self, eventson=False):
–> 974 ret = [_update_property(self, k, v) for k, v in props.items()]
975
976 if len(ret):

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/matplotlib/artist.py in _update_property(self, k, v)
968 if not callable(func):
969 raise AttributeError(’{!r} object has no property {!r}’
–> 970 .format(type(self).name, k))
971 return func(v)
972

AttributeError: ‘AxesImage’ object has no property ‘rows’

You can just call dls.show_batch() without Parameters. Don‘t know if rows and cols is depreached in v2.

Florian

1 Like

It’s part of the notebooks 05 and 06 from GitHub. So a bug in the code base. It’s trying to pass an attribute 'rows' to a matplotlib.artist.Artist class which has no notion of the attribute 'rows' so returns a none value as it’s not callable.

It’s down to the coders as I am not sure what they want to do with 'rows' or whether I have a duff environment, so I posted here for some help. It must have worked for fastai2 as I am sure it would be noticed, so don’t think it’s a deprecated issue. It may be to do with the version of matplotlib, from the default fastai2 installation guide if you follow that the version is 3.1.3
Cheers

1 Like

Change to dls.show_batch(nrows=1, ncols=3), an update now follows this formatting.

1 Like

Hi amrita

I guess you mean fastai2-0.0.13. This reminds me of the first ever releases of fastai, then we used the clone code as the installation rather than pip or conda, as all you do then is a git pull . Alas though I tried to remember how to actually get the clone idea to work I can’t remember exactly how it was done and searching these forums did not get info on how it was done. Since then I have gone from a 2009 Mac on which I worked through the first courses to a 2012 Mac so the info is not readily available. Note I now run fastai on linux and have for the last couple courses.

If you can help with any pointers to that please do. Thanks.

Sorry but fastai2-0.0.13 did not change the fault going to move to fastai2-0.0.11.

! conda list | grep fast
packages in environment at /home/dl/anaconda3/envs/fastai2:
cymem 2.0.2 py37he1b5a44_0 fastai
cython-blis 0.2.4 py37h516909a_1 fastai
fastai2 0.0.11 pypi_0 pypi
fastcore 0.1.15 pypi_0 pypi
fastprogress 0.2.2 py_0 fastai
fastscript 0.1.4 pypi_0 pypi
spacy 2.1.8 py37hc9558a2_0 fastai
srsly 0.1.0 py37he1b5a44_0 fastai
thinc 7.0.8 py37hc9558a2_0 fastai
wasabi 0.2.2 py_0 fastai

This changed the fault to an AssertionError but still a fault at the same line in the notebook 05_pet_breeds. This time in fastcore/dispatch.py line 157


AssertionError Traceback (most recent call last)
in
----> 1 dls.show_batch(rows=1, cols=3)

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastai2/data/core.py in show_batch(self, b, max_n, ctxs, show, **kwargs)
90 if b is None: b = self.one_batch()
91 if not show: return self._pre_show_batch(b, max_n=max_n)
—> 92 show_batch(*self._pre_show_batch(b, max_n=max_n), ctxs=ctxs, max_n=max_n, **kwargs)
93
94 def show_results(self, b, out, max_n=9, ctxs=None, show=True, **kwargs):

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastai2/data/core.py in _pre_show_batch(self, b, max_n)
81 def _pre_show_batch(self, b, max_n=9):
82 "Decode b to be ready for show_batch"
—> 83 b = self.decode(b)
84 if hasattr(b, ‘show’): return b,None,None
85 its = self._decode_batch(b, max_n, full=False)

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastai2/data/core.py in decode(self, b)
71 if isinstance(f,Pipeline): f.split_idx=split_idx
72
—> 73 def decode(self, b): return self.before_batch.decode(to_cpu(self.after_batch.decode(self._retain_dl(b))))
74 def decode_batch(self, b, max_n=9, full=True): return self._decode_batch(self.decode(b), max_n, full)
75

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastai2/data/core.py in _retain_dl(self, b)
51 def _retain_dl(self,b):
52 if not getattr(self, ‘_types’, None): self._one_pass()
—> 53 return retain_types(b, typs=self._types)
54
55 @delegates(DataLoader.new)

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastcore/dispatch.py in retain_types(new, old, typs)
173 else: t,typs = typs,None
174 else: t = type(old) if old is not None and isinstance(old,type(new)) else type(new)
–> 175 return t(L(new, old, typs).map_zip(retain_types, cycled=True))
176
177 # Cell

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastcore/foundation.py in map_zip(self, f, cycled, *args, **kwargs)
386 def zip(self, cycled=False): return self._new((zip_cycle if cycled else zip)(*self))
387 def zipwith(self, *rest, cycled=False): return self._new([self, *rest]).zip(cycled=cycled)
–> 388 def map_zip(self, f, *args, cycled=False, **kwargs): return self.zip(cycled=cycled).starmap(f, *args, **kwargs)
389 def map_zipwith(self, f, *rest, cycled=False, **kwargs): return self.zipwith(*rest, cycled=cycled).starmap(f, **kwargs)
390 def concat(self): return self._new(itertools.chain.from_iterable(self.map(L)))

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastcore/foundation.py in starmap(self, f, *args, **kwargs)
383 def cycle(self): return cycle(self)
384 def map_dict(self, f=noop, *args, **kwargs): return {k:f(k, *args,**kwargs) for k in self}
–> 385 def starmap(self, f, *args, **kwargs): return self._new(itertools.starmap(partial(f,*args,**kwargs), self))
386 def zip(self, cycled=False): return self._new((zip_cycle if cycled else zip)(*self))
387 def zipwith(self, *rest, cycled=False): return self._new([self, *rest]).zip(cycled=cycled)

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastcore/foundation.py in _new(self, items, *args, **kwargs)
313 @property
314 def _xtra(self): return None
–> 315 def _new(self, items, *args, **kwargs): return type(self)(items, *args, use_list=None, **kwargs)
316 def getitem(self, idx): return self._get(idx) if is_indexer(idx) else L(self._get(idx), use_list=None)
317 def copy(self): return self._new(self.items.copy())

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastcore/foundation.py in call(cls, x, args, **kwargs)
39 return x
40
—> 41 res = super().call(
((x,) + args), **kwargs)
42 res._newchk = 0
43 return res

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastcore/foundation.py in init(self, items, use_list, match, *rest)
304 if items is None: items = []
305 if (use_list is not None) or not _is_array(items):
–> 306 items = list(items) if use_list else _listify(items)
307 if match is not None:
308 if is_coll(match): match = len(match)

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastcore/foundation.py in _listify(o)
240 if isinstance(o, list): return o
241 if isinstance(o, str) or _is_array(o): return [o]
–> 242 if is_iter(o): return list(o)
243 return [o]
244

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastcore/dispatch.py in retain_types(new, old, typs)
166 def retain_types(new, old=None, typs=None):
167 “Cast each item of new to type of matching item in old if it’s a superclass”
–> 168 if not is_listy(new): return retain_type(new, old, typs)
169 if typs is not None:
170 if isinstance(typs, dict):

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastcore/dispatch.py in retain_type(new, old, typ)
155 # e.g. old is TensorImage, new is Tensor - if not subclass then do nothing
156 if new is None: return
–> 157 assert old is not None or typ is not None
158 if typ is None:
159 if not isinstance(old, type(new)): return new

AssertionError:

Further as each notebook here mirrors the notebook of the book edition without the digest I looked to see if this was the intended behaviour; it turns out this line of code displays a single row of three images as you would expect.

@RogerS49 like @amritv has mentioned you are missing the letter ‘n’ before rows and cols. :slight_smile: hope that helps

2 Likes

It was before 6 am dooh !!!. Thanks. I did a git pull on the clone of course-v4 and it returns up to date so git hub needs refreshing as nrows and ncols are not there.

Have changed 02, 05, and 06 notebooks to reflect this in my clone. Could someone run me through how to clean them and push them back.

Sorry for the confusion. The arguments used to be rows and cols, but I renamed them to be consistent with matplotlib. Have not updated the boo/notebooks to that change but will do this morning.

5 Likes

No Problem. Is there a link to how you want your process of push requests to operate.
My guess is in the clone

  • do git pull
  • do checkout on files required
  • do changes/or check if changes required

From here my remembrance is a little hazy

  • do something not sure what.
  • do commit
  • make push request.

I have worked with other Version control systems but not so much with Git in a professional environment.

Thanks

This topic as a useful guide that should help. It’s for the fastai2 repo, but can be adapted to course-v4.

1 Like

Just want to further clarify on this (as I think I know but I’m not 100% sure). The major differences is you should still run nbdev_clean_nbs but you don’t need to run nbdev_build_lib as there is no clean_nbs folder etc for us to work with, yes? So the general steps now look like so:

  1. Clone repository
  2. Branching, commiting, etc (step 4-9 but skip step 7)

In it’s place you should include nbdev_clean_nbs especially if you are using a platform such as Google Colaboratory for editing the notebooks.

I’m not even sure you can install the hooks at the moment, since there is no settings.ini

Got it, adjusted the above steps