A walk with fastai2 - Vision - Study Group and Online Lectures Megathread

Do note that this thread is for the Walk with fastai2 notebooks, not Jeremy’s dev walkthroughs :slight_smile: (those actually have their own threads if you search for them)

1 Like

Hi.
When I try running the notebook 1 of lesson 1 on colab it runs fine but when I try running it on my local computer, it gives me the following error-

AssertionError: Failed to find “re.compile(’/([^/]+)_\d+.*’)” in “D:\DLLibLocation.fastai\data\oxford-iiit-pet\images\British_Shorthair_40.jpg”

the cell was -
pets = DataBlock(blocks=(ImageBlock, CategoryBlock),
get_items=get_image_files,
splitter=RandomSplitter(),
get_y=RegexLabeller(pat = r’/([^/]+)_\d+.*’),
item_tfms=item_tfms,
batch_tfms=batch_tfms)

I am not familiar with RegEx and would appreciate some help as to why the error is absent on colab but I get one when I run it locally.(I have regex library installed too)

This specific regex expression is designed specifically for a linux-based system. It seems as though you are running this on windows. You’d need to adapt your selection based on this new URL/directory structure. This is a good website I use for playing around with regex: https://regex101.com/

2 Likes

Thank you for the website…I busted my brains at first trying to figure out the answer but now I finally got it. Feels good when you solve a problem something by yourself. Also, I learned a lot about regex. Thanks @muellerzr . :grin: :grin:

When I try to create a custom dataset, On running the following code, I get the error-

for i , n in enumerate(classes):
print(n)
path_f=Path(files[i])
download_images(path/n,path_f,max_pics=10)

I get the error-

BrokenProcessPool: A process in the process pool was terminated abruptly while the future was running or pending.

It works fine when I decrease the max_pics to 5 but anything greater than 5 gives me the error. Any idea what might cause this ? I have 8GB ram and 6 GB of VRAM

1 Like

Hi @Legnica1241,
Try changing the max_workers in download_images.
For more details check this forum thread:

Has anyone tried rapidsai yet ? Do you know of any resources (books, videos) to help get started with rapids?

I am trying to run 04_Segmentation.ipynb but i get the following error during training

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-25-27d5ab94b4fb> in <module>()
----> 1 learn.fit_one_cycle(10, slice(lr), pct_start=0.9, wd=wd)

22 frames
/usr/local/lib/python3.6/dist-packages/fastai/callback/schedule.py in fit_one_cycle(self, n_epoch, lr_max, div, div_final, pct_start, wd, moms, cbs, reset_opt)
    110     scheds = {'lr': combined_cos(pct_start, lr_max/div, lr_max, lr_max/div_final),
    111               'mom': combined_cos(pct_start, *(self.moms if moms is None else moms))}
--> 112     self.fit(n_epoch, cbs=ParamScheduler(scheds)+L(cbs), reset_opt=reset_opt, wd=wd)
    113 
    114 # Cell

/usr/local/lib/python3.6/dist-packages/fastai/learner.py in fit(self, n_epoch, lr, wd, cbs, reset_opt)
    203             self.opt.set_hypers(lr=self.lr if lr is None else lr)
    204             self.n_epoch = n_epoch
--> 205             self._with_events(self._do_fit, 'fit', CancelFitException, self._end_cleanup)
    206 
    207     def _end_cleanup(self): self.dl,self.xb,self.yb,self.pred,self.loss = None,(None,),(None,),None,None

/usr/local/lib/python3.6/dist-packages/fastai/learner.py in _with_events(self, f, event_type, ex, final)
    152 
    153     def _with_events(self, f, event_type, ex, final=noop):
--> 154         try:       self(f'before_{event_type}')       ;f()
    155         except ex: self(f'after_cancel_{event_type}')
    156         finally:   self(f'after_{event_type}')        ;final()

/usr/local/lib/python3.6/dist-packages/fastai/learner.py in _do_fit(self)
    194         for epoch in range(self.n_epoch):
    195             self.epoch=epoch
--> 196             self._with_events(self._do_epoch, 'epoch', CancelEpochException)
    197 
    198     def fit(self, n_epoch, lr=None, wd=None, cbs=None, reset_opt=False):

/usr/local/lib/python3.6/dist-packages/fastai/learner.py in _with_events(self, f, event_type, ex, final)
    152 
    153     def _with_events(self, f, event_type, ex, final=noop):
--> 154         try:       self(f'before_{event_type}')       ;f()
    155         except ex: self(f'after_cancel_{event_type}')
    156         finally:   self(f'after_{event_type}')        ;final()

/usr/local/lib/python3.6/dist-packages/fastai/learner.py in _do_epoch(self)
    189     def _do_epoch(self):
    190         self._do_epoch_train()
--> 191         self._do_epoch_validate()
    192 
    193     def _do_fit(self):

/usr/local/lib/python3.6/dist-packages/fastai/learner.py in _do_epoch_validate(self, ds_idx, dl)
    185         if dl is None: dl = self.dls[ds_idx]
    186         self.dl = dl
--> 187         with torch.no_grad(): self._with_events(self.all_batches, 'validate', CancelValidException)
    188 
    189     def _do_epoch(self):

/usr/local/lib/python3.6/dist-packages/fastai/learner.py in _with_events(self, f, event_type, ex, final)
    152 
    153     def _with_events(self, f, event_type, ex, final=noop):
--> 154         try:       self(f'before_{event_type}')       ;f()
    155         except ex: self(f'after_cancel_{event_type}')
    156         finally:   self(f'after_{event_type}')        ;final()

/usr/local/lib/python3.6/dist-packages/fastai/learner.py in all_batches(self)
    158     def all_batches(self):
    159         self.n_iter = len(self.dl)
--> 160         for o in enumerate(self.dl): self.one_batch(*o)
    161 
    162     def _do_one_batch(self):

/usr/local/lib/python3.6/dist-packages/fastai/learner.py in one_batch(self, i, b)
    176         self.iter = i
    177         self._split(b)
--> 178         self._with_events(self._do_one_batch, 'batch', CancelBatchException)
    179 
    180     def _do_epoch_train(self):

/usr/local/lib/python3.6/dist-packages/fastai/learner.py in _with_events(self, f, event_type, ex, final)
    154         try:       self(f'before_{event_type}')       ;f()
    155         except ex: self(f'after_cancel_{event_type}')
--> 156         finally:   self(f'after_{event_type}')        ;final()
    157 
    158     def all_batches(self):

/usr/local/lib/python3.6/dist-packages/fastai/learner.py in __call__(self, event_name)
    130     def ordered_cbs(self, event): return [cb for cb in sort_by_run(self.cbs) if hasattr(cb, event)]
    131 
--> 132     def __call__(self, event_name): L(event_name).map(self._call_one)
    133 
    134     def _call_one(self, event_name):

/usr/local/lib/python3.6/dist-packages/fastcore/foundation.py in map(self, f, gen, *args, **kwargs)
    177     def range(cls, a, b=None, step=None): return cls(range_of(a, b=b, step=step))
    178 
--> 179     def map(self, f, *args, gen=False, **kwargs): return self._new(map_ex(self, f, *args, gen=gen, **kwargs))
    180     def argwhere(self, f, negate=False, **kwargs): return self._new(argwhere(self, f, negate, **kwargs))
    181     def filter(self, f=noop, negate=False, gen=False, **kwargs):

/usr/local/lib/python3.6/dist-packages/fastcore/basics.py in map_ex(iterable, f, gen, *args, **kwargs)
    604     res = map(g, iterable)
    605     if gen: return res
--> 606     return list(res)
    607 
    608 # Cell

/usr/local/lib/python3.6/dist-packages/fastcore/basics.py in __call__(self, *args, **kwargs)
    594             if isinstance(v,_Arg): kwargs[k] = args.pop(v.i)
    595         fargs = [args[x.i] if isinstance(x, _Arg) else x for x in self.pargs] + args[self.maxi+1:]
--> 596         return self.func(*fargs, **kwargs)
    597 
    598 # Cell

/usr/local/lib/python3.6/dist-packages/fastai/learner.py in _call_one(self, event_name)
    134     def _call_one(self, event_name):
    135         assert hasattr(event, event_name), event_name
--> 136         [cb(event_name) for cb in sort_by_run(self.cbs)]
    137 
    138     def _bn_bias_state(self, with_bias): return norm_bias_params(self.model, with_bias).map(self.opt.state)

/usr/local/lib/python3.6/dist-packages/fastai/learner.py in <listcomp>(.0)
    134     def _call_one(self, event_name):
    135         assert hasattr(event, event_name), event_name
--> 136         [cb(event_name) for cb in sort_by_run(self.cbs)]
    137 
    138     def _bn_bias_state(self, with_bias): return norm_bias_params(self.model, with_bias).map(self.opt.state)

/usr/local/lib/python3.6/dist-packages/fastai/callback/core.py in __call__(self, event_name)
     42                (self.run_valid and not getattr(self, 'training', False)))
     43         res = None
---> 44         if self.run and _run: res = getattr(self, event_name, noop)()
     45         if event_name=='after_fit': self.run=True #Reset self.run to True at each end of fit
     46         return res

/usr/local/lib/python3.6/dist-packages/fastai/learner.py in after_batch(self)
    455         if len(self.yb) == 0: return
    456         mets = self._train_mets if self.training else self._valid_mets
--> 457         for met in mets: met.accumulate(self.learn)
    458         if not self.training: return
    459         self.lrs.append(self.opt.hypers[-1]['lr'])

/usr/local/lib/python3.6/dist-packages/fastai/learner.py in accumulate(self, learn)
    377     def accumulate(self, learn):
    378         bs = find_bs(learn.yb)
--> 379         self.total += learn.to_detach(self.func(learn.pred, *learn.yb))*bs
    380         self.count += bs
    381     @property

<ipython-input-19-0f1db32b8c82> in acc_camvid(input, target)
      5     target = target.squeeze(1)
      6     mask = target != void_code
----> 7     return (input.argmax(dim=1)[mask]==target[mask]).float().mean()

/usr/local/lib/python3.6/dist-packages/torch/tensor.py in wrapped(*args, **kwargs)
     23         from torch.overrides import has_torch_function, handle_torch_function
     24         if not all(type(t) is Tensor for t in args) and has_torch_function(args):
---> 25             return handle_torch_function(wrapped, args, *args, **kwargs)
     26         try:
     27             return f(*args, **kwargs)

/usr/local/lib/python3.6/dist-packages/torch/overrides.py in handle_torch_function(public_api, relevant_args, *args, **kwargs)
   1069     raise TypeError("no implementation found for '{}' on types that implement "
   1070                     '__torch_function__: {}'
-> 1071                     .format(func_name, list(map(type, overloaded_args))))
   1072 
   1073 def has_torch_function(relevant_args: Iterable[Any]) -> bool:

TypeError: no implementation found for 'torch.tensor.eq' on types that implement __torch_function__: [<class 'fastai.torch_core.TensorImage'>, <class 'fastai.torch_core.TensorMask'>]

So it looks like lesson3-camvid.ipynb also has the same issue. I remember Jeremy tweeting that with the new Pytorch release segmentation doesn’t work, but i’m not sure how to fix this(in terms of going back to an older version and trying to run it). How to i find what the corresponding fastai install with the fastcore and other dependencies ? Thanks for your help in advance :slight_smile:

Have you installed the latest version? This should have been fixed in the latest release :slight_smile:

Also nice to see you again @barnacl :slight_smile:

Thanks @muellerzr for the quick response :slight_smile:
i’m using !pip install fastai -q --upgrade and i’m on 2.1.7 which is the latest.
Great to be back :slight_smile:

1 Like

I had another question- if i were to install a previous fastai version how do i install the correct dependencies, i think you posted about that but i just can’t find it.
Btw i’m on colab.

You’d want to pick your version and then if things start breaking that would come from fastcore. You should check the date (on pip) the fastai version was released and use the fastcore that was released around that time

1 Like

Oh dear! Let me try real quick and see too :cry:

1 Like

Cool thanks

@barnacl looks like the solution is to do:

 valid_fnames = (path/'valid.txt').read_text().split('\n')

If you feel up to it a PR would be most welcome :slight_smile:

1 Like

Oh wow, I had used a RandomSplitter. Thanks will do that :+1:

Oh shoot wait @barnacl that fixed half the problem, sorry :sweat_smile: I was running my course notebook and hit another issue first. Let me get to yours :upside_down_face:

How old is your version? 04_Segmentation trains for me and we use ranger rather than adam. I can’t recreate the issue. If possible could you recreate it in google colab and save it as a gist for me to look at? :slight_smile:

Hmm weird, let me check again give me a sec

So this is where i’m cloning from - https://github.com/muellerzr/Practical-Deep-Learning-for-Coders-2.0, just did a new clone to my Drive. The current 04_Segmentation has a config too - config = unet_config(self_attention=True, act_cls=Mish) which i guess has changed?
To make things simple I just used learn = unet_learner(dls, resnet34, metrics=acc_camvid), so i removed ranger and mish.
here is the gist

1 Like