Fastai v2 chat

Fast progress is the newest 0.2.2?? Now with the following error:

RuntimeError                              Traceback (most recent call last)
<ipython-input-14-495233eaf2b4> in <module>
----> 1 learn.fit_one_cycle(4)

e:\fastcore\fastcore\utils.py in _f(*args, **kwargs)
    428         init_args.update(log)
    429         setattr(inst, 'init_args', init_args)
--> 430         return inst if to_return else f(*args, **kwargs)
    431     return _f
    432 

e:\fastai2\fastai2\callback\schedule.py in fit_one_cycle(self, n_epoch, lr_max, div, div_final, pct_start, wd, moms, cbs, reset_opt)
    111     scheds = {'lr': combined_cos(pct_start, lr_max/div, lr_max, lr_max/div_final),
    112               'mom': combined_cos(pct_start, *(self.moms if moms is None else moms))}
--> 113     self.fit(n_epoch, cbs=ParamScheduler(scheds)+L(cbs), reset_opt=reset_opt, wd=wd)
    114 
    115 # Cell

e:\fastcore\fastcore\utils.py in _f(*args, **kwargs)
    428         init_args.update(log)
    429         setattr(inst, 'init_args', init_args)
--> 430         return inst if to_return else f(*args, **kwargs)
    431     return _f
    432 

e:\fastai2\fastai2\learner.py in fit(self, n_epoch, lr, wd, cbs, reset_opt)
    198                     try:
    199                         self.epoch=epoch;          self('begin_epoch')
--> 200                         self._do_epoch_train()
    201                         self._do_epoch_validate()
    202                     except CancelEpochException:   self('after_cancel_epoch')

e:\fastai2\fastai2\learner.py in _do_epoch_train(self)
    173         try:
    174             self.dl = self.dls.train;                        self('begin_train')
--> 175             self.all_batches()
    176         except CancelTrainException:                         self('after_cancel_train')
    177         finally:                                             self('after_train')

e:\fastai2\fastai2\learner.py in all_batches(self)
    151     def all_batches(self):
    152         self.n_iter = len(self.dl)
--> 153         for o in enumerate(self.dl): self.one_batch(*o)
    154 
    155     def one_batch(self, i, b):

e:\fastai2\fastai2\data\load.py in __iter__(self)
     96         self.randomize()
     97         self.before_iter()
---> 98         for b in _loaders[self.fake_l.num_workers==0](self.fake_l):
     99             if self.device is not None: b = to_device(b, self.device)
    100             yield self.after_batch(b)

E:\Anaconda3\envs\fastai2\lib\site-packages\torch\utils\data\dataloader.py in __init__(self, loader)
    717             #     before it starts, and __del__ tries to join but will get:
    718             #     AssertionError: can only join a started process.
--> 719             w.start()
    720             self._index_queues.append(index_queue)
    721             self._workers.append(w)

E:\Anaconda3\envs\fastai2\lib\multiprocessing\process.py in start(self)
    110                'daemonic processes are not allowed to have children'
    111         _cleanup()
--> 112         self._popen = self._Popen(self)
    113         self._sentinel = self._popen.sentinel
    114         # Avoid a refcycle if the target function holds an indirect

E:\Anaconda3\envs\fastai2\lib\multiprocessing\context.py in _Popen(process_obj)
    221     @staticmethod
    222     def _Popen(process_obj):
--> 223         return _default_context.get_context().Process._Popen(process_obj)
    224 
    225 class DefaultContext(BaseContext):

E:\Anaconda3\envs\fastai2\lib\multiprocessing\context.py in _Popen(process_obj)
    320         def _Popen(process_obj):
    321             from .popen_spawn_win32 import Popen
--> 322             return Popen(process_obj)
    323 
    324     class SpawnContext(BaseContext):

E:\Anaconda3\envs\fastai2\lib\multiprocessing\popen_spawn_win32.py in __init__(self, process_obj)
     87             try:
     88                 reduction.dump(prep_data, to_child)
---> 89                 reduction.dump(process_obj, to_child)
     90             finally:
     91                 set_spawning_popen(None)

E:\Anaconda3\envs\fastai2\lib\multiprocessing\reduction.py in dump(obj, file, protocol)
     58 def dump(obj, file, protocol=None):
     59     '''Replacement for pickle.dump() using ForkingPickler.'''
---> 60     ForkingPickler(file, protocol).dump(obj)
     61 
     62 #

E:\Anaconda3\envs\fastai2\lib\site-packages\torch\multiprocessing\reductions.py in reduce_tensor(tensor)
    240          ref_counter_offset,
    241          event_handle,
--> 242          event_sync_required) = storage._share_cuda_()
    243         tensor_offset = tensor.storage_offset()
    244         shared_cache[handle] = StorageWeakRef(storage)

RuntimeError: cuda runtime error (801) : operation not supported at C:\w\1\s\tmp_conda_3.7_100118\conda\conda-bld\pytorch_1579082551706\work\torch/csrc/generic/StorageSharing.cpp:245

Thank you for your attention.

You had this error previously. Check you have access to the GPU and you may need to remove the call to to_fp16.

torch.cuda.get_device_name() and able to get the name of my device 1050Ti.
After remove to_fp16. I still get the same error.
Opp. Sorry, now I am using Win10 and not Vbox.
After remove to_fp16, the pet.nb fit_one_cycle is working but very slowly. I assume there is issue of my GPU in Ubuntu. The GPU driver gone, and it used to be there with Ubuntu 19 and I tried CUDA in nb before. CUDA 10 is still there. Maybe I should try ubuntu 20 later.

Installing drivers is always a nightmare for me as well.
I would recommend to use Ubuntu and install through pip. This is what typically works the best for me with pytorch based frameworks such as fastai.

With Win 10 and Now the new runtime error is(71). Any suggestion?

 cuda runtime error (71) : operation not supported at C:\w\1\s\tmp_conda_3.7_075911\conda\conda-bld\pytorch_1579075223148\work\torch/csrc/generic/StorageSharing.cpp:245

11 posts were split to a new topic: How to access the raw tensor inputs and outputs passed to the model?

This is definitely a problem from installation. Try to have a working pytorch with gpu

import torch
torch.cuda.is_available()

Maybe run even one of their examples if you still have an issue.

This is bugging me for a day, I don’t understand why L and TfmdLists are giving different results for a DataFrame. Steps:

Load the df:

source = untar_data(URLs.IMDB_SAMPLE)
df = pd.read_csv(source/'texts.csv')

Using TfmdLists gives us the first row of the df:

TfmdLists(df, [])[0]

Using L gives us the entire df:

L(df)[0]

I inspected the MRO TfmdLists and __getitem__ just goes directly to L, I don’t understand why they behave differently.

On your call to L can you try setting as_list=True?

It’s really great to use unique=True with show_batch to examine data augmentations on images of single category, may I do a feature request to show a batch of particular category? :slightly_smiling_face:

I see we’re showing images of id=0 when unique=True , is it possible to look up dictionary and find index of given category?

It just returns the name of a column:
image

1 Like

That’s is certainly possible, and a very cool idea. You just need to be careful on how you handle the case when you’re doing some other form of learning that is not classification, how would this work for regression for example?

I wonder what happens with unique in the said example :thinking:

It shows the same pictures/text/input with various data augmentation and the float target.

1 Like

Looking at GradientAccumulation again I wonder if there should be the following updates:

  • define it by number of batches to run n_batches instead of minimum number of items to accumulate n_acc
  • scale the loss prior to calculating the gradients (and scale it back for logging purposes) so that we don’t have to adjust learning rate

Do you think it would make it more intuitive to use?

Hi! Is there a way to work with imbalanced classes in a tabular dataset in fastai2? I can see references to weighted_dataloaders in the code, but I am not sure of how to use it.

Thank you!

This is the correct one to use!
The idea is to pass weights for each items of your dataset. So for example you could define weights so that the sum of the weights for each class are all equal, ie “1/n_class_samples” for each item of a specific class.

This would give same chances to draw each class. The risk would be if a class has very few samples you could overfit on that class so you may want to check your accuracy per class at the end of your training.

You can see an example here: https://github.com/fastai/fastai2/blob/master/nbs/14a_callback.data.ipynb

1 Like

Thank you! For some reason, from the two methods of that notebook, the only one that I can use from a TabularPandas object is partial_dataloaders. weighted_dataloaders does not seem to be recognized.

Any idea of why? If your think this is more suitable for the tabular forum, I will move it there.

Thanks!

Would anyone know if there is anything similar but for text? And… for multi label text?

I’m trying to run fastai2 training and tracking with weights and biases (wandb). I’m using the datablocks api for image classification, and instantiating the dataloaders using pandas dataframe. Got the following error:

/usr/local/lib/python3.6/dist-packages/fastai2/learner.py in fit(self, n_epoch, lr, wd, cbs, reset_opt)
    187             try:
--> 188                 self._do_begin_fit(n_epoch)
    189                 for epoch in range(n_epoch):

/usr/local/lib/python3.6/dist-packages/fastai2/learner.py in _do_begin_fit(self, n_epoch)
    159     def _do_begin_fit(self, n_epoch):
--> 160         self.n_epoch,self.loss = n_epoch,tensor(0.);         self('begin_fit')
    161 

/usr/local/lib/python3.6/dist-packages/fastai2/learner.py in __call__(self, event_name)
    123 
--> 124     def __call__(self, event_name): L(event_name).map(self._call_one)
    125     def _call_one(self, event_name):

/usr/local/lib/python3.6/dist-packages/fastcore/foundation.py in map(self, f, *args, **kwargs)
    371              else f.__getitem__)
--> 372         return self._new(map(g, self))
    373 

/usr/local/lib/python3.6/dist-packages/fastcore/foundation.py in _new(self, items, *args, **kwargs)
    322     def _xtra(self): return None
--> 323     def _new(self, items, *args, **kwargs): return type(self)(items, *args, use_list=None, **kwargs)
    324     def __getitem__(self, idx): return self._get(idx) if is_indexer(idx) else L(self._get(idx), use_list=None)

/usr/local/lib/python3.6/dist-packages/fastcore/foundation.py in __call__(cls, x, *args, **kwargs)
     40 
---> 41         res = super().__call__(*((x,) + args), **kwargs)
     42         res._newchk = 0

/usr/local/lib/python3.6/dist-packages/fastcore/foundation.py in __init__(self, items, use_list, match, *rest)
    313         if (use_list is not None) or not _is_array(items):
--> 314             items = list(items) if use_list else _listify(items)
    315         if match is not None:

/usr/local/lib/python3.6/dist-packages/fastcore/foundation.py in _listify(o)
    249     if isinstance(o, str) or _is_array(o): return [o]
--> 250     if is_iter(o): return list(o)
    251     return [o]

/usr/local/lib/python3.6/dist-packages/fastcore/foundation.py in __call__(self, *args, **kwargs)
    215         fargs = [args[x.i] if isinstance(x, _Arg) else x for x in self.pargs] + args[self.maxi+1:]
--> 216         return self.fn(*fargs, **kwargs)
    217 

/usr/local/lib/python3.6/dist-packages/fastai2/learner.py in _call_one(self, event_name)
    126         assert hasattr(event, event_name)
--> 127         [cb(event_name) for cb in sort_by_run(self.cbs)]
    128 

/usr/local/lib/python3.6/dist-packages/fastai2/learner.py in <listcomp>(.0)
    126         assert hasattr(event, event_name)
--> 127         [cb(event_name) for cb in sort_by_run(self.cbs)]
    128 

/usr/local/lib/python3.6/dist-packages/fastai2/callback/core.py in __call__(self, event_name)
     23                (self.run_valid and not getattr(self, 'training', False)))
---> 24         if self.run and _run: getattr(self, event_name, noop)()
     25         if event_name=='after_fit': self.run=True #Reset self.run to True at each end of fit

/usr/local/lib/python3.6/dist-packages/fastai2/callback/wandb.py in begin_fit(self)
     55             idxs = wandbRandom.sample(range(len(self.dls.valid_ds)), self.n_preds)
---> 56             test_items = [self.dls.valid_ds.items[i] for i in idxs]
     57             self.valid_dl = self.dls.test_dl(test_items, with_labels=True)

/usr/local/lib/python3.6/dist-packages/fastai2/callback/wandb.py in <listcomp>(.0)
     55             idxs = wandbRandom.sample(range(len(self.dls.valid_ds)), self.n_preds)
---> 56             test_items = [self.dls.valid_ds.items[i] for i in idxs]
     57             self.valid_dl = self.dls.test_dl(test_items, with_labels=True)

/usr/local/lib/python3.6/dist-packages/pandas/core/frame.py in __getitem__(self, key)
   2799                 return self._getitem_multilevel(key)
-> 2800             indexer = self.columns.get_loc(key)
   2801             if is_integer(indexer):

/usr/local/lib/python3.6/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   2647             except KeyError:
-> 2648                 return self._engine.get_loc(self._maybe_cast_indexer(key))
   2649         indexer = self.get_indexer([key], method=method, tolerance=tolerance)

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 3412

Was able to reproduce by running:

wandbRandom = random.Random(0) # For repeatability
idxs = wandbRandom.sample(range(len(dls.valid_ds)), 36)
test_items = [dls.valid_ds.items[i] for i in idxs]

Think it has to do with issue with indexing into dataframe.

@boris