Getting Started with fastai-v2

This is just an fyi - installed fastai2 on AWS:

Fastai Version: 0.0.5
Torch Version: 1.4.0
cuda: True
python version: 3.7.6 (default, Jan 8 2020, 19:59:22)
[GCC 7.3.0]
torchvision: 0.5.0

This caused the following error when testing on the planet dataset when calling show_batch()


AttributeError Traceback (most recent call last)
in
----> 1 dbunch.show_batch(max_n=9, figsize=(12,9))

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastai2/data/core.py in show_batch(self, b, max_n, ctxs, show, **kwargs)
75
76 def show_batch(self, b=None, max_n=9, ctxs=None, show=True, **kwargs):
—> 77 if b is None: b = self.one_batch()
78 if not show: return self._pre_show_batch(b, max_n=max_n)
79 show_batch(*self._pre_show_batch(b, max_n=max_n), ctxs=ctxs, max_n=max_n, **kwargs)

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastai2/data/load.py in one_batch(self)
128 def one_batch(self):
129 if self.n is not None and len(self)==0: raise ValueError(f’This DataLoader does not contain any batches’)
–> 130 with self.fake_l.no_multiproc(): res = first(self)
131 if hasattr(self, ‘it’): delattr(self, ‘it’)
132 return res

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastcore/utils.py in first(x)
172 def first(x):
173 “First element of x, or None if missing”
–> 174 try: return next(iter(x))
175 except StopIteration: return None
176

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastai2/data/load.py in iter(self)
95 self.randomize()
96 self.before_iter()
—> 97 for b in _loadersself.fake_l.num_workers==0:
98 if self.device is not None: b = to_device(b, self.device)
99 yield self.after_batch(b)

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/torch/utils/data/dataloader.py in init(self, loader)
374 class _SingleProcessDataLoaderIter(_BaseDataLoaderIter):
375 def init(self, loader):
–> 376 super(_SingleProcessDataLoaderIter, self).init(loader)
377 assert self._timeout == 0
378 assert self._num_workers == 0

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/torch/utils/data/dataloader.py in init(self, loader)
321 self._dataset = loader.dataset
322 self._dataset_kind = loader._dataset_kind
–> 323 self._IterableDataset_len_called = loader._IterableDataset_len_called
324 self._auto_collation = loader._auto_collation
325 self._drop_last = loader.drop_last

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastcore/foundation.py in getattr(self, k)
221 attr = getattr(self,self._default,None)
222 if attr is not None: return getattr(attr, k)
–> 223 raise AttributeError(k)
224 def dir(self): return custom_dir(self, self._dir() if self._xtra is None else self._dir())
225 # def getstate(self): return self.dict

AttributeError: _IterableDataset_len_called

Downgraded pytorch(on both 1.2.0 and 1.3.1) and no issues now.

Hi s.s.o,

Were you able to fix this issue?
Facing same issue.

Thanks

Finally was able to fix it follow below if you are still stuck.
run —
conda install pytorch=1.2.0 -c pytorch
before pip install fastai2

2 Likes

I had to create symbolic links to fastscript, fastcore, nbdev, and fastai2 in my courses folder to run the notebooks. Is this what’s expected when doing editable install?

No, an editable install should make the packages available in your enviromnent.

Thanks! Not sure what’s wrong, but it’s working for now, so I’ll let it be. I’m also still getting a “No such kernel named python3” error when running nbdev_test_nbs. I’m guessing the two issues are related, but not sure. Try as I might, I’ve not found the solution yet.

I have no problems whatsoever running fastpages or fastai v1, but I get the “no such kernel” error when testing fastai2 and fastcore.

In case anyone else needs this, I solved the problem with python3 -m ipykernel install --user following this thread.

1 Like

Hi, 1. while trying to do regression on my own data with tabular_learner I am getting AssertionError: Could not infer loss function from the data, please pass a loss function. 2. When I specify loss_func=mse I get extreme train_loss and valid_loss, while fastai v1 works fine with the same data. Would appreceate your help. Thank you!

I’d recommend posting in fastai2 tabular thread here:
Fastai v2 tabular and also please include the code you’ve used to build it, what the error states, etc

Ok, I will do that right away, tnx

Hi, what is the way to predict multiple items at once? I used to do this with a test set with fastai v1, but I can not find the way to do this with v2 because it seems like there is no info in the docs. Would appreciate a hint, thank you!

Answering my own question, now it works the following way for tabular models.

to is a TabularPandas object.

test_to = to.new(test_df)  
test_to.process()
test_dbunch = test_to.dataloaders(bs=4000, shuffle_train=False)
preds,_ = learn.get_preds(dl=test_dbunch[0])
1 Like

You can also do learn.dls.test_dl(test_df) and have that done in one step. You also don’t need to do the DataLoaders step because a TabularPandas object is a DataLoader itself

Can you please share setup steps for AWS?

Regards
Ganesh Bhat

Hey Ganesh I’m on a double shift today so won’t be able to look at it for a day or two, hopefully someone else can chime in

Thanks for your response. I found another blog to setup fastai2 on AWS.

1 Like

Using pip I see that fastai2 is up to version 0.0.17.

However, I don’t see a 0.0.17 tag in the commit history of the fastai github? If I pip install the latest fastai2 version, do I get something that is at least fairly up to date relative to the current commit on master?

Thanks.

Recently got the book (in Germany). Jeremy, can’t thank you enough. You are an inspiration.

1 Like