Hi, I found several errors when I running 005_dogs_cats.ipynb.
When I run into this cell:
(x,y) = next(iter(data.valid_dl))
_,axs = plt.subplots(4,4,figsize=(12,12))
for i,ax in enumerate(axs.flatten()): show_image(data_denorm(x[i].cpu()), ax)
I got the following error messages:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-79-5de730d345ff> in <module>()
----> 1 (x,y) = next(iter(data.valid_dl))
2
3 _,axs = plt.subplots(4,4,figsize=(12,12))
4 for i,ax in enumerate(axs.flatten()): show_image(data_denorm(x[i].cpu()), ax)
/.../Anaconda3-5.1/lib/python3.6/site-packages/torch/utils/data/dataloader.py in __next__(self)
334 self.reorder_dict[idx] = batch
335 continue
--> 336 return self._process_next_batch(batch)
337
338 next = __next__ # Python 2 compatibility
/.../Anaconda3-5.1/lib/python3.6/site-packages/torch/utils/data/dataloader.py in _process_next_batch(self, batch)
355 self._put_indices()
356 if isinstance(batch, ExceptionWrapper):
--> 357 raise batch.exc_type(batch.exc_msg)
358 return batch
359
ValueError: Traceback (most recent call last):
File "/.../Anaconda3-5.1/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 106, in _worker_loop
samples = collate_fn([dataset[i] for i in batch_indices])
File "/.../Anaconda3-5.1/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 106, in <listcomp>
samples = collate_fn([dataset[i] for i in batch_indices])
File "/.../fastai_v1/dev_nb/nb_002.py", line 294, in __getitem__
return apply_tfms(self.tfms, x, **self.kwargs), y
File "/.../fastai_v1/dev_nb/nb_002.py", line 418, in apply_tfms
else: x = tfm(x)
File "/.../fastai_v1/dev_nb/nb_002.py", line 267, in __call__
return self.tfm(x, *args, **{**self.resolved, **kwargs}) if self.do_run else x
File "/.../fastai_v1/dev_nb/nb_002.py", line 222, in __call__
if args: return self.calc(*args, **kwargs)
File "/.../fastai_v1/dev_nb/nb_002.py", line 226, in calc
if tfm._wrap: return getattr(x, tfm._wrap)(tfm.func, *args, **kwargs)
File "/.../fastai_v1/dev_nb/nb_002.py", line 147, in pixel
self.px = func(self.px, *args, **kwargs)
File "/.../fastai_v1/dev_nb/nb_002.py", line 126, in px
self.refresh()
File "/.../fastai_v1/dev_nb/nb_002.py", line 119, in refresh
self._px = grid_sample(self._px, self.flow, **self.sample_kwargs)
File "/.../fastai_v1/dev_nb/nb_002.py", line 358, in grid_sample
return F.grid_sample(x[None], coords, mode=mode, padding_mode=padding_mode)[0]
File "/.../Anaconda3-5.1/lib/python3.6/site-packages/torch/nn/functional.py", line 2092, in grid_sample
raise ValueError("padding_mode needs to be 'zeros' or 'border', but got {}".format(padding_mode))
ValueError: padding_mode needs to be 'zeros' or 'border', but got reflection
I found this error is because function F.grid_sample
doesn’t support argument option padding_mode='reflect'
, so I replaced the argument of function grid_sample
in file nb_002.py to `padding_mode=‘zeros’.
But after that, the same cell got the following error messages:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-98-5de730d345ff> in <module>()
----> 1 (x,y) = next(iter(data.valid_dl))
2
3 _,axs = plt.subplots(4,4,figsize=(12,12))
4 for i,ax in enumerate(axs.flatten()): show_image(data_denorm(x[i].cpu()), ax)
/.../Anaconda3-5.1/lib/python3.6/site-packages/torch/utils/data/dataloader.py in __next__(self)
334 self.reorder_dict[idx] = batch
335 continue
--> 336 return self._process_next_batch(batch)
337
338 next = __next__ # Python 2 compatibility
/.../Anaconda3-5.1/lib/python3.6/site-packages/torch/utils/data/dataloader.py in _process_next_batch(self, batch)
355 self._put_indices()
356 if isinstance(batch, ExceptionWrapper):
--> 357 raise batch.exc_type(batch.exc_msg)
358 return batch
359
TypeError: Traceback (most recent call last):
File "/.../Anaconda3-5.1/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 106, in _worker_loop
samples = collate_fn([dataset[i] for i in batch_indices])
File "/.../Anaconda3-5.1/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 106, in <listcomp>
samples = collate_fn([dataset[i] for i in batch_indices])
File "/.../fastai_v1/dev_nb/nb_002.py", line 294, in __getitem__
return apply_tfms(self.tfms, x, **self.kwargs), y
File "/.../fastai_v1/dev_nb/nb_002.py", line 418, in apply_tfms
else: x = tfm(x)
File "/.../fastai_v1/dev_nb/nb_002.py", line 267, in __call__
return self.tfm(x, *args, **{**self.resolved, **kwargs}) if self.do_run else x
File "/.../fastai_v1/dev_nb/nb_002.py", line 222, in __call__
if args: return self.calc(*args, **kwargs)
File "/.../fastai_v1/dev_nb/nb_002.py", line 226, in calc
if tfm._wrap: return getattr(x, tfm._wrap)(tfm.func, *args, **kwargs)
File "/.../fastai_v1/dev_nb/nb_002.py", line 147, in pixel
self.px = func(self.px, *args, **kwargs)
TypeError: crop_pad() missing 1 required positional argument: 'size'
So I changed the following function:
#export
def get_transforms(do_flip=False, flip_vert=False, max_rotate=0., max_zoom=1., max_lighting=0., max_warp=0.,
p_affine=0.75, p_lighting=0.5, xtra_tfms=None):
res = [rand_crop()]
if do_flip: res.append(dihedral() if flip_vert else flip_lr(p=0.5))
if max_warp: res.append(symmetric_warp(magnitude=(-max_warp,max_warp), p=p_affine))
if max_rotate: res.append(rotate(degrees=(-max_rotate,max_rotate), p=p_affine))
if max_zoom>1: res.append(rand_zoom(scale=(1.,max_zoom), p=p_affine))
if max_lighting:
res.append(brightness(change=(0.5*(1-max_lighting), 0.5*(1+max_lighting)), p=p_lighting))
res.append(contrast(scale=(1-max_lighting, 1/(1-max_lighting)), p=p_lighting))
# train , valid
return (res + listify(xtra_tfms), [crop_pad()])
to:
#export
def get_transforms(size, do_flip=False, flip_vert=False, max_rotate=0., max_zoom=1., max_lighting=0., max_warp=0.,
p_affine=0.75, p_lighting=0.5, xtra_tfms=None):
res = [rand_crop(size=size)]
if do_flip: res.append(dihedral() if flip_vert else flip_lr(p=0.5))
if max_warp: res.append(symmetric_warp(magnitude=(-max_warp,max_warp), p=p_affine))
if max_rotate: res.append(rotate(degrees=(-max_rotate,max_rotate), p=p_affine))
if max_zoom>1: res.append(rand_zoom(scale=(1.,max_zoom), p=p_affine))
if max_lighting:
res.append(brightness(change=(0.5*(1-max_lighting), 0.5*(1+max_lighting)), p=p_lighting))
res.append(contrast(scale=(1-max_lighting, 1/(1-max_lighting)), p=p_lighting))
# train , valid
return (res + listify(xtra_tfms), [crop_pad(size=size)])
And changed the following cell:
size=224
tfms = get_transforms(do_flip=True, max_rotate=10, max_zoom=1.2, max_lighting=0.3, max_warp=0.15)
tds = transform_datasets(train_ds, valid_ds, tfms, size=size)
data = DataBunch.create(*tds, bs=64, num_workers=8, tfms=data_norm)
TO:
size=224
tfms = get_transforms(size, do_flip=True, max_rotate=10, max_zoom=1.2, max_lighting=0.3, max_warp=0.15)
tds = transform_datasets(train_ds, valid_ds, tfms) #, size=size
data = DataBunch.create(*tds, bs=64, num_workers=8, tfms=data_norm)
After all of them, I got the following seemingly correct result: