Giter Club home page Giter Club logo

fastai's Introduction

Welcome to fastai

CI PyPI Conda (channel only) docs

Installing

You can use fastai without any installation by using Google Colab. In fact, every page of this documentation is also available as an interactive notebook - click “Open in colab” at the top of any page to open it (be sure to change the Colab runtime to “GPU” to have it run fast!) See the fast.ai documentation on Using Colab for more information.

You can install fastai on your own machines with conda (highly recommended), as long as you’re running Linux or Windows (NB: Mac is not supported). For Windows, please see the “Running on Windows” for important notes.

We recommend using miniconda (or miniforge). First install PyTorch using the conda line shown here, and then run:

conda install -c fastai fastai

To install with pip, use: pip install fastai.

If you plan to develop fastai yourself, or want to be on the cutting edge, you can use an editable install (if you do this, you should also use an editable install of fastcore to go with it.) First install PyTorch, and then:

git clone https://github.com/fastai/fastai
pip install -e "fastai[dev]"

Learning fastai

The best way to get started with fastai (and deep learning) is to read the book, and complete the free course.

To see what’s possible with fastai, take a look at the Quick Start, which shows how to use around 5 lines of code to build an image classifier, an image segmentation model, a text sentiment model, a recommendation system, and a tabular model. For each of the applications, the code is much the same.

Read through the Tutorials to learn how to train your own models on your own datasets. Use the navigation sidebar to look through the fastai documentation. Every class, function, and method is documented here.

To learn about the design and motivation of the library, read the peer reviewed paper.

About fastai

fastai is a deep learning library which provides practitioners with high-level components that can quickly and easily provide state-of-the-art results in standard deep learning domains, and provides researchers with low-level components that can be mixed and matched to build new approaches. It aims to do both things without substantial compromises in ease of use, flexibility, or performance. This is possible thanks to a carefully layered architecture, which expresses common underlying patterns of many deep learning and data processing techniques in terms of decoupled abstractions. These abstractions can be expressed concisely and clearly by leveraging the dynamism of the underlying Python language and the flexibility of the PyTorch library. fastai includes:

  • A new type dispatch system for Python along with a semantic type hierarchy for tensors
  • A GPU-optimized computer vision library which can be extended in pure Python
  • An optimizer which refactors out the common functionality of modern optimizers into two basic pieces, allowing optimization algorithms to be implemented in 4–5 lines of code
  • A novel 2-way callback system that can access any part of the data, model, or optimizer and change it at any point during training
  • A new data block API
  • And much more…

fastai is organized around two main design goals: to be approachable and rapidly productive, while also being deeply hackable and configurable. It is built on top of a hierarchy of lower-level APIs which provide composable building blocks. This way, a user wanting to rewrite part of the high-level API or add particular behavior to suit their needs does not have to learn how to use the lowest level.

Layered API

Migrating from other libraries

It’s very easy to migrate from plain PyTorch, Ignite, or any other PyTorch-based library, or even to use fastai in conjunction with other libraries. Generally, you’ll be able to use all your existing data processing code, but will be able to reduce the amount of code you require for training, and more easily take advantage of modern best practices. Here are migration guides from some popular libraries to help you on your way:

Windows Support

Due to python multiprocessing issues on Jupyter and Windows, num_workers of Dataloader is reset to 0 automatically to avoid Jupyter hanging. This makes tasks such as computer vision in Jupyter on Windows many times slower than on Linux. This limitation doesn’t exist if you use fastai from a script.

See this example to fully leverage the fastai API on Windows.

We recommend using Windows Subsystem for Linux (WSL) instead – if you do that, you can use the regular Linux installation approach, and you won’t have any issues with num_workers.

Tests

To run the tests in parallel, launch:

nbdev_test

For all the tests to pass, you’ll need to install the dependencies specified as part of dev_requirements in settings.ini

pip install -e .[dev]

Tests are written using nbdev, for example see the documentation for test_eq.

Contributing

After you clone this repository, make sure you have run nbdev_install_hooks in your terminal. This install Jupyter and git hooks to automatically clean, trust, and fix merge conflicts in notebooks.

After making changes in the repo, you should run nbdev_prepare and make additional and necessary changes in order to pass all the tests.

Docker Containers

For those interested in official docker containers for this project, they can be found here.

fastai's People

Contributors

albertvillanova avatar arampacha avatar asvcode avatar borisdayma avatar chrisrichardmiles avatar dependabot[bot] avatar dienhoa avatar feynlee avatar hamelsmu avatar johan12345 avatar jph00 avatar karthik-d-k avatar kevinbird15 avatar kushajveersingh avatar lgvaz avatar malligaraj avatar manisnesan avatar marii-moe avatar morganmcg1 avatar moritzschwyzer avatar muellerzr avatar ohmeow avatar omer-dor avatar philtrade avatar richarddwang avatar sgugger avatar tcapelle avatar tmabraham avatar tyoc213 avatar warner-benjamin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fastai's Issues

dataset.read_dir misses one file

I wanted to make predictions for a testset for a kaggle competition, but one file is missing.
I found the source of the error. In the dataset.read_dir function the any(fnames) check consumes one file from the iterator, so it is missing later on.

I will think of a good solution and make a pull request later if no one else is faster.

def read_dir(path, folder):
    # TODO: warn or error if no files found?
    full_path = os.path.join(path, folder)
    fnames = iglob(f"{full_path}/*.*")
    if any(fnames):
        return [os.path.relpath(f,path) for f in fnames]
    else:
        raise FileNotFoundError("{} folder doesn't exist or is empty".format(folder))

ImageClassifierData.from_paths cannot be called without transforms

download

This is raised because FilesDataset expects to be passed transform that responds to sz

class FilesDataset(BaseDataset):
    def __init__(self, fnames, transform, path):
        self.path,self.fnames = path,fnames
        super().__init__(transform)
    def get_n(self): return len(self.y)
    def get_sz(self): return self.transform.sz

I do not know what would be the correct way to fix this. Assuming images of varying sizes can live in referenced directories this gets tricky. I am also not sure if anything else uses this or if it is just a convenience method for the user.

(BTW I can train the model ok with just setting the body of get_sz to pass)

conda env update fails on Windows 10 x64

I am running Anaconda with conda 4.4.7-py36_0 on Windows 10 x64.
When I run conda env update the following is the output:

Using Anaconda API: https://api.anaconda.org
Solving environment: failed

ResolvePackageNotFound:
  - libgcc
  - cuda90
  - glib
  - torchvision[version='>=0.1.9']
  - pytorch[version='>=0.2.0']
  - fontconfig
  - jbig
  - libgfortran
  - readline
  - terminado
  - libffi
  - ptyprocess

The libgcc packages for Win64 are woefully out of date: https://anaconda.org/search?q=platform%3Awin-64+libgcc
Its not a problem for me to spin up some Linux VM, but then I would lose CUDA acceleration, or at least some stability/performance Is it possible to make all this run on Windows 10 x64?

lesson1 learn.fit(0.01, 2) error!

learn.fit(0.01, 2)
learn.fit(0.01, 2)
Epoch
0% 0/2 [00:00<?, ?it/s]
0%| | 0/360 [00:00<?, ?it/s]

RuntimeError Traceback (most recent call last)
in ()
----> 1 learn.fit(0.01, 2)

d:\Anaconda3\envs\fastai\lib\site-packages\fastai\learner.py in fit(self, lrs, n_cycle, wds, **kwargs)
97 self.sched = None
98 layer_opt = self.get_layer_opt(lrs, wds)
---> 99 self.fit_gen(self.model, self.data, layer_opt, n_cycle, **kwargs)
100
101 def lr_find(self, start_lr=1e-5, end_lr=10, wds=None):

d:\Anaconda3\envs\fastai\lib\site-packages\fastai\learner.py in fit_gen(self, model, data, layer_opt, n_cycle, cycle_len, cycle_mult, cycle_save_name, metrics, callbacks, **kwargs)
87 n_epoch = sum_geom(cycle_len if cycle_len else 1, cycle_mult, n_cycle)
88 fit(model, data, n_epoch, layer_opt.opt, self.crit,
---> 89 metrics=metrics, callbacks=callbacks, reg_fn=self.reg_fn, clip=self.clip, **kwargs)
90
91 def get_layer_groups(self): return self.models.get_layer_groups()

d:\Anaconda3\envs\fastai\lib\site-packages\fastai\model.py in fit(model, data, epochs, opt, crit, metrics, callbacks, kwargs)
82 for (*x,y) in t:
83 batch_num += 1
---> 84 loss = stepper.step(V(x),V(y))
85 avg_loss = avg_loss * avg_mom + loss * (1-avg_mom)
86 debias_loss = avg_loss / (1 - avg_mom
batch_num)

d:\Anaconda3\envs\fastai\lib\site-packages\fastai\model.py in step(self, xs, y)
41 if isinstance(output,(tuple,list)): output,*xtra = output
42 self.opt.zero_grad()
---> 43 loss = raw_loss = self.crit(output, y)
44 if self.reg_fn: loss = self.reg_fn(output, xtra, raw_loss)
45 loss.backward()

d:\Anaconda3\envs\fastai\lib\site-packages\torch\nn\functional.py in nll_loss(input, target, weight, size_average, ignore_index, reduce)
1047 weight = Variable(weight)
1048 if dim == 2:
-> 1049 return torch._C._nn.nll_loss(input, target, weight, size_average, ignore_index, reduce)
1050 elif dim == 4:
1051 return torch._C._nn.nll_loss2d(input, target, weight, size_average, ignore_index, reduce)

RuntimeError: Expected object of type Variable[torch.cuda.LongTensor] but found type Variable[torch.cuda.IntTensor] for argument #1 'target'

Seems not to be a reliable way of checking if the code is run in a notebook

def in_ipynb():

@sebastianruder when I test this in my notebook cfg['IPKernelApp']['parent_appname'] returns a traitlets.config.loader.LazyConfigValue object. Please see this stackoverflow's thread. Thanks for the added feature!

ipykernel==4.8.1
ipython==6.2.1
jupyter==1.0.0
jupyter-client==5.2.2
jupyter-console==5.2.0
jupyter-contrib-core==0.3.3
jupyter-contrib-nbextensions==0.4.0
jupyter-core==4.4.0
jupyter-highlight-selected-word==0.1.0
jupyter-latex-envs==1.4.1
jupyter-nbextensions-configurator==0.4.0

ImageClassifierData.from_dls exception

TypeError: __init__() missing 1 required positional argument: 'classes'

full tracE:


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-10-26994d0e2667> in <module>()
      1 arch=resnet34
      2 # data = ImageClassifierData.from_paths(PATH, tfms=tfms_from_model(arch, sz))
----> 3 data = ImageClassifierData.from_dls(None, train_loader, val_loader)
      4 learn = ConvLearner.pretrained(arch, data, precompute=True)
      5 learn.fit(0.01, 3)

~/nbs/x/fastai/dataset.py in from_dls(cls, path, trn_dl, val_dl, test_dl)
    191         trn_dl,val_dl = ModelDataLoader(trn_dl),ModelDataLoader(val_dl)
    192         if test_dl: test_dl = ModelDataLoader(test_dl)
--> 193         return cls(path, trn_dl, val_dl, test_dl)
    194 
    195     @property

TypeError: __init__() missing 1 required positional argument: 'classes'```

ValueError: some parameters appear in more than one parameter group

Getting this error anytime I try to run learn.lr_find or learn.fit with VGG16 or VGG19.

Below is the traceback.

ValueError                                Traceback (most recent call last)
<ipython-input-6-95b405c2ed1e> in <module>()
----> 1 lrf=learn.lr_find()
      2 learn.sched.plot()

/home/james/fastai_2/courses/dl1/fastai/learner.py in lr_find(self, start_lr, end_lr, wds)
    131         """
    132         self.save('tmp')
--> 133         layer_opt = self.get_layer_opt(start_lr, wds)
    134         self.sched = LR_Finder(layer_opt, len(self.data.trn_dl), end_lr)
    135         self.fit_gen(self.model, self.data, layer_opt, 1)

/home/james/fastai_2/courses/dl1/fastai/learner.py in get_layer_opt(self, lrs, wds)
     90 
     91     def get_layer_opt(self, lrs, wds):
---> 92         return LayerOptimizer(self.opt_fn, self.get_layer_groups(), lrs, wds)
     93 
     94     def fit(self, lrs, n_cycle, wds=None, **kwargs):

/home/james/fastai_2/courses/dl1/fastai/layer_optimizer.py in __init__(self, opt_fn, layer_groups, lrs, wds)
     15         if len(wds)==1: wds=wds*len(layer_groups)
     16         self.layer_groups,self.lrs,self.wds = layer_groups,lrs,wds
---> 17         self.opt = opt_fn(self.opt_params())
     18 
     19     def opt_params(self):

/home/james/fastai_2/courses/dl1/fastai/core.py in <lambda>(*args, **kwargs)
     63 
     64 def SGD_Momentum(momentum):
---> 65     return lambda *args, **kwargs: optim.SGD(*args, momentum=momentum, **kwargs)
     66 
     67 def one_hot(a,c): return np.eye(c)[a]

/home/james/anaconda3/envs/tensorflow/lib/python3.6/site-packages/torch/optim/sgd.py in __init__(self, params, lr, momentum, dampening, weight_decay, nesterov)
     54         if nesterov and (momentum <= 0 or dampening != 0):
     55             raise ValueError("Nesterov momentum requires a momentum and zero dampening")
---> 56         super(SGD, self).__init__(params, defaults)
     57 
     58     def __setstate__(self, state):

/home/james/anaconda3/envs/tensorflow/lib/python3.6/site-packages/torch/optim/optimizer.py in __init__(self, params, defaults)
     40             group_set = set(group['params'])
     41             if not param_set.isdisjoint(group_set):
---> 42                 raise ValueError("some parameters appear in more than one "
     43                                  "parameter group")
     44             param_set.update(group_set)

CPU-only installation

It wold be better if you provide environment-cpu.yml (or something like this) without - cuda90 and - cudnn requirements
and update README.MD for CPU only installation

TypeError from torch when doing model.fit in lesson4-imdb

I am trying to reproduce the code in lesson4-imdb notebook. I ran conda env update and the issue still exists.

I am running the following cell:

m3.freeze_to(-1)
m3.fit(lrs/2, 1, metrics=[accuracy])
m3.unfreeze()
m3.fit(lrs, 1, metrics=[accuracy], cycle_len=1)

to get the TypeError as mentioned below:

TypeError                                 Traceback (most recent call last)
<ipython-input-58-450637379222> in <module>()
      1 m3.freeze_to(-1)
----> 2 m3.fit(lrs/2, 1, metrics=[accuracy])
      3 m3.unfreeze()
      4 m3.fit(lrs, 1, metrics=[accuracy], cycle_len=1)

~/gandalf/fastai/courses/dl1/fastai/learner.py in fit(self, lrs, n_cycle, wds, **kwargs)
    207         self.sched = None
    208         layer_opt = self.get_layer_opt(lrs, wds)
--> 209         return self.fit_gen(self.model, self.data, layer_opt, n_cycle, **kwargs)
    210 
    211     def warm_up(self, lr, wds=None):

~/gandalf/fastai/courses/dl1/fastai/learner.py in fit_gen(self, model, data, layer_opt, n_cycle, cycle_len, cycle_mult, cycle_save_name, use_clr, metrics, callbacks, use_wd_sched, norm_wds, wds_sched_mult, **kwargs)
    154         n_epoch = sum_geom(cycle_len if cycle_len else 1, cycle_mult, n_cycle)
    155         return fit(model, data, n_epoch, layer_opt.opt, self.crit,
--> 156             metrics=metrics, callbacks=callbacks, reg_fn=self.reg_fn, clip=self.clip, **kwargs)
    157 
    158     def get_layer_groups(self): return self.models.get_layer_groups()

~/gandalf/fastai/courses/dl1/fastai/model.py in fit(model, data, epochs, opt, crit, metrics, callbacks, **kwargs)
    104             i += 1
    105 
--> 106         vals = validate(stepper, data.val_dl, metrics)
    107         if epoch == 0: print(layout.format(*names))
    108         print_stats(epoch, [debias_loss] + vals)

~/gandalf/fastai/courses/dl1/fastai/model.py in validate(stepper, dl, metrics)
    126         preds,l = stepper.evaluate(VV(x), VV(y))
    127         loss.append(to_np(l))
--> 128         res.append([f(preds.data,y) for f in metrics])
    129     return [np.mean(loss)] + list(np.mean(np.stack(res),0))
    130 

~/gandalf/fastai/courses/dl1/fastai/model.py in <listcomp>(.0)
    126         preds,l = stepper.evaluate(VV(x), VV(y))
    127         loss.append(to_np(l))
--> 128         res.append([f(preds.data,y) for f in metrics])
    129     return [np.mean(loss)] + list(np.mean(np.stack(res),0))
    130 

~/gandalf/fastai/courses/dl1/fastai/metrics.py in accuracy(preds, targs)
      8 def accuracy(preds, targs):
      9     preds = torch.max(preds, dim=1)[1]
---> 10     return (preds==targs).float().mean()
     11 
     12 def accuracy_thresh(thresh):

~/miniconda3/envs/fastai/lib/python3.6/site-packages/torch/tensor.py in __eq__(self, other)
    346 
    347     def __eq__(self, other):
--> 348         return self.eq(other)
    349 
    350     def __ne__(self, other):

TypeError: eq received an invalid combination of arguments - got (Variable), but expected one of:
 * (int value)
      didn't match because some of the arguments have invalid types: (Variable)
 * (torch.cuda.LongTensor other)
      didn't match because some of the arguments have invalid types: (Variable)

The additional warning before the above error is as follows:

Exception in thread Thread-4:
Traceback (most recent call last):
  File "/home/nirant/miniconda3/envs/fastai/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/home/nirant/miniconda3/envs/fastai/lib/python3.6/site-packages/tqdm/_tqdm.py", line 144, in run
    for instance in self.tqdm_cls._instances:
  File "/home/nirant/miniconda3/envs/fastai/lib/python3.6/_weakrefset.py", line 60, in __iter__
    for itemref in self.data:
RuntimeError: Set changed size during iteration

I have insufficient understanding of deep learning to fix this. Is the problem in line 128 of fastai/models.py?

Any assistance or guidance is really appreciated.

metrics.py invokes torch.max with "an invalid combination of arguments "


TypeError Traceback (most recent call last)
in ()
----> 1 accuracy(*learn.TTA())

~/fastai/courses/dl1/fastai/metrics.py in accuracy(preds, targs)
3
4 def accuracy(preds, targs):
----> 5 preds = torch.max(preds, dim=1)[1]
6 return (preds==targs).float().mean()
7

TypeError: torch.max received an invalid combination of arguments - got (numpy.ndarray, dim=int), but expected one of:

  • (torch.FloatTensor source)
  • (torch.FloatTensor source, torch.FloatTensor other)
    didn't match because some of the keywords were incorrect: dim
  • (torch.FloatTensor source, int dim)
  • (torch.FloatTensor source, int dim, bool keepdim)

RandomScaleXY instantiation issue?

In 5300b15, RandomScaleXY was added with constructor signature:

def __init__(self, sz, max_zoom, p=0.75, tfm_y=TfmType.NO):

5300b15#diff-48685f6197acf069ae438de1ac77a613R320

Later in the same file, there is a definition for image_gen, where RandomScaleXY is used:

scale = [RandomScaleXY(sz, max_zoom, tfm_y) if max_zoom is not None else ScaleXY(sz, tfm_y)]

5300b15#diff-48685f6197acf069ae438de1ac77a613R409

Isn't tfm_y (local to image_gen) being used as the value of the p parameter?

Should that not be:

scale = [RandomScaleXY(sz, max_zoom, tfm_y=tfm_y) if max_zoom is not None else ScaleXY(sz, tfm_y)]

?

DL1 Lesson1 : error in most_by_correct()

In lesson 1, the logic in most_by_mask() is not evaluated as I think it was intended because the operator precedence of bitwise AND is greater than logical equals. This can give erroneous results if there are strong false predictions. I only noticed it when training with a very small data and validation set of doors vs windows.

From fastai/courses/dl1/lesson1.ipynb:

def most_by_correct(y, is_correct): 
    mult = -1 if (y==1)==is_correct else 1
    return most_by_mask((preds == data.val_y)==is_correct & (data.val_y == y), mult)

I am pretty sure it should be:

def most_by_correct(y, is_correct): 
    mult = -1 if (y==1)==is_correct else 1
    return most_by_mask(((preds == data.val_y)==is_correct) & (data.val_y == y), mult)

lm_rnn.py concat returns "IndexError: list index out of range"

IndexError Traceback (most recent call last)
in ()
1 m3.freeze_to(-1)
----> 2 m3.fit(lrs/2, 1, metrics=[accuracy])
3 m3.unfreeze()
4 m3.fit(lrs, 1, metrics=[accuracy], cycle_len=1)

~/fastai/courses/dl1/fastai/learner.py in fit(self, lrs, n_cycle, wds, **kwargs)
207 self.sched = None
208 layer_opt = self.get_layer_opt(lrs, wds)
--> 209 self.fit_gen(self.model, self.data, layer_opt, n_cycle, **kwargs)
210
211 def warm_up(self, lr, wds=None):

~/fastai/courses/dl1/fastai/learner.py in fit_gen(self, model, data, layer_opt, n_cycle, cycle_len, cycle_mult, cycle_save_name, use_clr, metrics, callbacks, use_wd_sched, norm_wds, wds_sched_mult, **kwargs)
154 n_epoch = sum_geom(cycle_len if cycle_len else 1, cycle_mult, n_cycle)
155 fit(model, data, n_epoch, layer_opt.opt, self.crit,
--> 156 metrics=metrics, callbacks=callbacks, reg_fn=self.reg_fn, clip=self.clip, **kwargs)
157
158 def get_layer_groups(self): return self.models.get_layer_groups()

~/fastai/courses/dl1/fastai/model.py in fit(model, data, epochs, opt, crit, metrics, callbacks, kwargs)
88 batch_num += 1
89 for cb in callbacks: cb.on_batch_begin()
---> 90 loss = stepper.step(V(x),V(y))
91 avg_loss = avg_loss * avg_mom + loss * (1-avg_mom)
92 debias_loss = avg_loss / (1 - avg_mom
batch_num)

~/fastai/courses/dl1/fastai/model.py in step(self, xs, y)
38 def step(self, xs, y):
39 xtra = []
---> 40 output = self.m(*xs)
41 if isinstance(output,(tuple,list)): output,*xtra = output
42 self.opt.zero_grad()

~/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py in call(self, *input, **kwargs)
323 for hook in self._forward_pre_hooks.values():
324 hook(self, input)
--> 325 result = self.forward(*input, **kwargs)
326 for hook in self._forward_hooks.values():
327 hook_result = hook(self, input, result)

~/anaconda3/lib/python3.6/site-packages/torch/nn/modules/container.py in forward(self, input)
65 def forward(self, input):
66 for module in self._modules.values():
---> 67 input = module(input)
68 return input
69

~/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py in call(self, *input, **kwargs)
323 for hook in self._forward_pre_hooks.values():
324 hook(self, input)
--> 325 result = self.forward(*input, **kwargs)
326 for hook in self._forward_hooks.values():
327 hook_result = hook(self, input, result)

~/fastai/courses/dl1/fastai/lm_rnn.py in forward(self, input)
129 raw_outputs.append(r)
130 outputs.append(o)
--> 131 return self.concat(raw_outputs), self.concat(outputs)
132
133

~/fastai/courses/dl1/fastai/lm_rnn.py in concat(self, arrs)
117
118 def concat(self, arrs):
--> 119 return [torch.cat([l[si] for l in arrs]) for si in range(len(arrs[0]))]
120
121 def forward(self, input):

IndexError: list index out of range

Problem in the lesson #5

In the "Collaborative filtering" section got the error when trying to learn.fit:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-6-8cf2e7ab9f6b> in <module>()
----> 1 learn.fit(1e-2, 2, wds=wd, cycle_len=1, cycle_mult=2, use_wd_sched=True)

~/courses/fastai/courses/dl1/fastai/learner.py in fit(self, lrs, n_cycle, wds, **kwargs)
    207         self.sched = None
    208         layer_opt = self.get_layer_opt(lrs, wds)
--> 209         return self.fit_gen(self.model, self.data, layer_opt, n_cycle, **kwargs)
    210 
    211     def warm_up(self, lr, wds=None):

~/courses/fastai/courses/dl1/fastai/learner.py in fit_gen(self, model, data, layer_opt, n_cycle, cycle_len, cycle_mult, cycle_save_name, use_clr, metrics, callbacks, use_wd_sched, norm_wds, wds_sched_mult, **kwargs)
    154         n_epoch = sum_geom(cycle_len if cycle_len else 1, cycle_mult, n_cycle)
    155         return fit(model, data, n_epoch, layer_opt.opt, self.crit,
--> 156             metrics=metrics, callbacks=callbacks, reg_fn=self.reg_fn, clip=self.clip, **kwargs)
    157 
    158     def get_layer_groups(self): return self.models.get_layer_groups()

~/courses/fastai/courses/dl1/fastai/model.py in fit(model, data, epochs, opt, crit, metrics, callbacks, **kwargs)
     78     avg_mom=0.98
     79     batch_num,avg_loss=0,0.
---> 80     for cb in callbacks: cb.on_train_begin()
     81     names = ["epoch", "trn_loss", "val_loss"] + [f.__name__ for f in metrics]
     82     layout = "{!s:10} " * len(names)

AttributeError: 'NoneType' object has no attribute 'on_train_begin'

How to contribute?

How to contribute?

I'd like to contribute to this project. But I don't know where to start. Is there any suggestions? Thank you.

Use Cross-platform Functions Instead of Linux Only Shell Commands

There's a few places in Lesson 1 that uses Linux-only shell commands. This is an issue for Windows users. Why not use platform independent code? For example:

Linux only: !ls {PATH}
Cross-platform: os.listdir(PATH)

Linux only: !ls {PATH}valid
Cross-platform: os.listdir(PATH + 'valid')

Linux only: files = !ls {PATH}valid/cats | head
Cross-platform: files = os.listdir(PATH + 'valid/cats')

Linux only: !rm -rf {PATH}tmp
Cross-platform: os.removedirs(PATH + 'tmp')

Preprocessing during Data Loading

Is there a way to pre-process the images when using ImageClassifierData.from_paths() so that each image is center-cropped with a rectangular region rather than a square region? If so, what does the API call look like?

ResolvePackageNotFound: cuda90

I ran conda env update command right after I cloned repo.

But it raises following error:

Using Anaconda API: https://api.anaconda.org
Solving environment: failed

ResolvePackageNotFound:
  - cuda90

Conda version: conda 4.4.6
OS: macOS 10.13

Thank you.

Lesson 4 (v2) is not working on crestle.com

When importing

%reload_ext autoreload
%autoreload 2
%matplotlib inline

from fastai.learner import *

import torchtext
from torchtext import vocab, data
from torchtext.datasets import language_modeling

from fastai.rnn_reg import *
from fastai.rnn_train import *
from fastai.nlp import *
from fastai.lm_rnn import *

import dill as pickle

Got the following error:

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-1-50d149e01473> in <module>()
     11 from fastai.rnn_reg import *
     12 from fastai.rnn_train import *
---> 13 from fastai.nlp import *
     14 from fastai.lm_rnn import *
     15 

~/courses/fastai/courses/dl1/fastai/nlp.py in <module>()
      5 from .dataset import *
      6 from .learner import *
----> 7 from .text import *
      8 from .lm_rnn import *
      9 

~/courses/fastai/courses/dl1/fastai/text.py in <module>()
      9 def sub_br(x): return re_br.sub("\n", x)
     10 
---> 11 my_tok = spacy.load('en')
     12 my_tok.tokenizer.add_special_case('<eos>', [{ORTH: '<eos>'}])
     13 my_tok.tokenizer.add_special_case('<bos>', [{ORTH: '<bos>'}])

/usr/local/lib/python3.6/dist-packages/spacy/__init__.py in load(name, **overrides)
     17             "to load. For example:\nnlp = spacy.load('{}')".format(depr_path),
     18             'error')
---> 19     return util.load_model(name, **overrides)
     20 
     21 

/usr/local/lib/python3.6/dist-packages/spacy/util.py in load_model(name, **overrides)
    117     elif hasattr(name, 'exists'):  # Path or Path-like to model data
    118         return load_model_from_path(name, **overrides)
--> 119     raise IOError("Can't find model '%s'" % name)
    120 
    121 

OSError: Can't find model 'en'

Seems that I need to do the following command in the virtual environment, but I don't know how to get into it:

$ python -m spacy download en

Please, add it to dependencies. I also wrote an email to the support at crestle.com about this issue.


P.S. Got it to work. I downloaded model with the following command:

!pip3 install https://github.com/explosion/spacy-models/releases/download/en_core_web_md-1.2.0/en_core_web_md-1.2.0.tar.gz

and changed

my_tok = spacy.load('en')

to

my_tok = spacy.load('en_core_web_sm')

in the fastai/text.py file. After this is required to restart a kernel.
But it's not a good solution manually to tweak the library. So not closing.

Default embedding sizes for ColumnarModelData

In lesson 4 of dl1 we learned what embedding matrixes are about and a heuristic for generating them: cardinality/2, but not bigger than 50 - implemented in the notebook as:

cat_sz = [(c, len(joined_samp[c].cat.categories)+1) for c in cat_vars]
emb_szs = [(c, min(50, (c+1)//2)) for _,c in cat_sz]

We then pass that as the first parameter to the fit method:
m = md.get_learner(emb_szs, ...)

I'm wondering if it would make sense to make that parameter optional, and to use the heuristic discussed as the default value - we already passed in the data frame and the categorical fields:
md = ColumnarModelData.from_data_frame(PATH, val_idx, df, yl.astype(np.float32), cat_flds=cat_vars, bs=128, test_df=df_test)

Any thoughts? If this wouldn't be sensible and I've mis-understood the content I've asked a similar question in the fast.ai forums here: http://forums.fast.ai/t/lesson-4-is-there-a-non-teaching-reason-not-to-have-default-embedding-sizes/11391

Question: Why does T() avoid to_gpu() when dtype==np.float32?

I've noticed that for float32 numpy arrays I need to call .cuda() despite calling V. This isn't an issue, but I'm wondering why this is. Does it have something to do with .cuda()'s async argument?


def T(a):
    if torch.is_tensor(a): res = a
    else:
        a = np.array(np.ascontiguousarray(a))
        if a.dtype in (np.int8, np.int16, np.int32, np.int64):
            res = torch.LongTensor(a.astype(np.int64))
        elif a.dtype in (np.float32, np.float64):   #  <--------------
            return torch.FloatTensor(a.astype(np.float32))   #  <--------------
        else: raise NotImplementedError
    return to_gpu(res, async=True)

https://github.com/fastai/fastai/blob/master/fastai/core.py#L17

V -- > V_ --> T -- > to_gpu --> cuda, for numpy arrays that don't contain floats.


Meta: Let me know if I should ask questions like these on forums.fast.ai instead of creating a github issue.

Calling `python` within fastai/fasti directory causes a core dump

In exploring the fastai library, I tried calling python to test some code. While in the fastai/fastai directory, this caused a core dump:

(fastai) prairie@gold:~/fastai/fastai$ python
Fatal Python error: Py_Initialize: can't initialize sys standard streams
Traceback (most recent call last):
  File "/home/prairie/fastai/fastai/io.py", line 1, in <module>
ImportError: attempted relative import with no known parent package
Aborted (core dumped)

This doesn't happen withpython2.7

This is a minor edge case which is easy to avoid, but I pass it on any way. (Not even sure if this is anaconda related.)

Thanks for a terrific fastai library and an equally impressive MOOC! Much appreciated.

Expected object of type Variable[torch.cuda.LongTensor] in model.py

Running on Windows 10 appears to expose a type mismatch issue in model.py.

RuntimeError: Expected object of type Variable[torch.cuda.LongTensor] but found type Variable[torch.cuda.IntTensor] for argument #1 'target'​

Report on fastai forum: http://forums.fast.ai/t/windows-10-installation-notes-windows-command-and-wsl-bash/6500/54?u=bsalita

Patch and explanation: http://forums.fast.ai/t/windows-10-installation-notes-windows-command-and-wsl-bash/6500/55?u=bsalita

Is there a static type analyzer which can be run on fastai code to catch these kinds of errors?

Use of import * in the fastai library

Hello everyone.

I was going through the fastai GitHub repository to understand the internal working. I noticed that almost everywhere import * has been used. I believe that it makes understanding the codebase difficult. (Why is import * bad)

If you also feel that the wildcard imports should be done away with, let me know I would be happy to submit a PR to try and fix this.

Thanks.

RuntimeError: received 0 items of ancdata

I'm running into an issue when trying to predict with the dn models. From what I've researched it seems maybe related to this issue pytorch/pytorch#973 from the pytorch forums and the workaround there was setting the number of workers to 0. If anybody else has encountered this or knows how to set the number of workers to 0, I tried setting num_workers on ImageClassifierData to 0, but that didn't solve the issue for me. I don't know if there is anything that can be done on the fastai side since it appears to be a pytorch problem, but I figured it's at least worth documenting and if anybody has any ideas they can look into it.

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-13-c94a818ff72b> in <module>()
     10     learn[i].fit(0.01, 3, cycle_len=1, cycle_mult=4)
     11 
---> 12     test_predictions = learn[i].predict(is_test=True)
     13 
     14     #tmp_log_preds,tmp_y = learn[i].TTA(is_test=True, n_aug=50)

~/fastaip1v2/fastai/courses/dl1/fastai/learner.py in predict(self, is_test)
    136         self.load('tmp')
    137 
--> 138     def predict(self, is_test=False): return self.predict_with_targs(is_test)[0]
    139 
    140     def predict_with_targs(self, is_test=False):

~/fastaip1v2/fastai/courses/dl1/fastai/learner.py in predict_with_targs(self, is_test)
    140     def predict_with_targs(self, is_test=False):
    141         dl = self.data.test_dl if is_test else self.data.val_dl
--> 142         return predict_with_targs(self.model, dl)
    143 
    144     def predict_dl(self, dl): return predict_with_targs(self.model, dl)[0]

~/fastaip1v2/fastai/courses/dl1/fastai/model.py in predict_with_targs(m, dl)
    115     if hasattr(m, 'reset'): m.reset()
    116     preda,targa = zip(*[(get_prediction(m(*VV(x))),y)
--> 117                         for *x,y in iter(dl)])
    118     return to_np(torch.cat(preda)), to_np(torch.cat(targa))
    119 

~/fastaip1v2/fastai/courses/dl1/fastai/model.py in <listcomp>(.0)
    114     m.eval()
    115     if hasattr(m, 'reset'): m.reset()
--> 116     preda,targa = zip(*[(get_prediction(m(*VV(x))),y)
    117                         for *x,y in iter(dl)])
    118     return to_np(torch.cat(preda)), to_np(torch.cat(targa))

~/fastaip1v2/fastai/courses/dl1/fastai/dataset.py in __next__(self)
    226         if self.i>=len(self.dl): raise StopIteration
    227         self.i+=1
--> 228         return next(self.it)
    229 
    230     @property

~/anaconda3/envs/fastai/lib/python3.6/site-packages/torch/utils/data/dataloader.py in __next__(self)
    193         while True:
    194             assert (not self.shutdown and self.batches_outstanding > 0)
--> 195             idx, batch = self.data_queue.get()
    196             self.batches_outstanding -= 1
    197             if idx != self.rcvd_idx:

~/anaconda3/envs/fastai/lib/python3.6/multiprocessing/queues.py in get(self)
    335             res = self._reader.recv_bytes()
    336         # unserialize the data after having released the lock
--> 337         return _ForkingPickler.loads(res)
    338 
    339     def put(self, obj):

~/anaconda3/envs/fastai/lib/python3.6/site-packages/torch/multiprocessing/reductions.py in rebuild_storage_fd(cls, df, size)
     68         fd = multiprocessing.reduction.rebuild_handle(df)
     69     else:
---> 70         fd = df.detach()
     71     try:
     72         storage = storage_from_cache(cls, fd_id(fd))

~/anaconda3/envs/fastai/lib/python3.6/multiprocessing/resource_sharer.py in detach(self)
     56             '''Get the fd.  This should only be called once.'''
     57             with _resource_sharer.get_connection(self._id) as conn:
---> 58                 return reduction.recv_handle(conn)
     59 
     60 

~/anaconda3/envs/fastai/lib/python3.6/multiprocessing/reduction.py in recv_handle(conn)
    180         '''Receive a handle over a local connection.'''
    181         with socket.fromfd(conn.fileno(), socket.AF_UNIX, socket.SOCK_STREAM) as s:
--> 182             return recvfds(s, 1)[0]
    183 
    184     def DupFd(fd):

~/anaconda3/envs/fastai/lib/python3.6/multiprocessing/reduction.py in recvfds(sock, size)
    159             if len(ancdata) != 1:
    160                 raise RuntimeError('received %d items of ancdata' %
--> 161                                    len(ancdata))
    162             cmsg_level, cmsg_type, cmsg_data = ancdata[0]
    163             if (cmsg_level == socket.SOL_SOCKET and

RuntimeError: received 0 items of ancdata

change in 'add_datepart()' for the `df[targ_pre+'Elapsed']` formula ?

Hi,

I have some trouble reproducing some of Jeremy's notebooks' results from Rossmann (DL1) and Bulldozers (ML1) videos, when using the 'add_datepart()' function in Structured.py.

It keeps generating 10+ digits figures, like "1356998400" while it's more likely in the range of 100s, maybe 1000s days max if counting the number of days elapsed between 2 events ?

Looking at the history of the code, and some screen captures from Jeremy's videos in Oct-Nov 2017, I noticed this change in code.

Before: df[targ_pre+'Elapsed'] = (fld - fld.min()).dt.days

Today: df[targ_pre+'Elapsed'] = fld.astype(np.int64) // 10**9

AssertionError: Torch not compiled with CUDA enabled

I was testing ./courses/dl1/lesson1.ipynb on macOS 10.12.6, Python 3.6, torch 0.2.0

while running learn = ConvLearner.pretrained(resnet34, data, precompute=True)

AssertionError Traceback (most recent call last)
in ()
1 data = ImageClassifierData.from_paths(PATH, tfms=tfms_from_model(resnet34, 299))
----> 2 learn = ConvLearner.pretrained(resnet34, data, precompute=True)
3 # learn.fit(0.01, 2)
/Users/user/fastai/courses/dl1/fastai/conv_learner.py in pretrained(self, f, data, ps, xtra_fc, xtra_cut, **kwargs)
87 @classmethod
88 def pretrained(self, f, data, ps=None, xtra_fc=None, xtra_cut=0, **kwargs):
---> 89 models = ConvnetBuilder(f, data.c, data.is_multi, data.is_reg, ps=ps, xtra_fc=xtra_fc, xtra_cut=xtra_cut)
90 return self(data, models, **kwargs)
91
/Users/user/fastai/courses/dl1/fastai/conv_learner.py in init(self, f, c, is_multi, is_reg, ps, xtra_fc, xtra_cut)
40 fc_layers = self.get_fc_layers()
41 self.n_fc = len(fc_layers)
---> 42 self.fc_model = nn.Sequential(fc_layers).cuda()
43 apply_init(self.fc_model, kaiming_normal)
44 self.model=nn.Sequential(
(layers+fc_layers)).cuda()
/Users/user/anaconda2/envs/py3/lib/python3.6/site-packages/torch/nn/modules/module.py in cuda(self, device_id)
145 copied to that device
146 """
--> 147 return self._apply(lambda t: t.cuda(device_id))
148
149 def cpu(self):
/Users/user/anaconda2/envs/py3/lib/python3.6/site-packages/torch/nn/modules/module.py in _apply(self, fn)
116 def _apply(self, fn):
117 for module in self.children():
--> 118 module._apply(fn)
119
120 for param in self._parameters.values():
/Users/user/anaconda2/envs/py3/lib/python3.6/site-packages/torch/nn/modules/module.py in _apply(self, fn)
122 # Variables stored in modules are graph leaves, and we don't
123 # want to create copy nodes, so we have to unpack the data.
--> 124 param.data = fn(param.data)
125 if param._grad is not None:
126 param._grad.data = fn(param._grad.data)
/Users/user/anaconda2/envs/py3/lib/python3.6/site-packages/torch/nn/modules/module.py in (t)
145 copied to that device
146 """
--> 147 return self._apply(lambda t: t.cuda(device_id))
148
149 def cpu(self):
/Users/user/anaconda2/envs/py3/lib/python3.6/site-packages/torch/_utils.py in cuda(self, device, async)
64 else:
65 new_type = getattr(torch.cuda, self.class.name)
---> 66 return new_type(self.size()).copy
(self, async)
67
68
/Users/user/anaconda2/envs/py3/lib/python3.6/site-packages/torch/cuda/init.py in _lazy_new(cls, *args, **kwargs)
264 @staticmethod
265 def _lazy_new(cls, *args, **kwargs):
--> 266 _lazy_init()
267 # We need this method only for lazy init, so we can remove it
268 del _CudaBase.new
/Users/user/anaconda2/envs/py3/lib/python3.6/site-packages/torch/cuda/init.py in _lazy_init()
82 raise RuntimeError(
83 "Cannot re-initialize CUDA in forked subprocess. " + msg)
---> 84 _check_driver()
85 torch._C._cuda_init()
86 torch._C._cuda_sparse_init()
/Users/user/anaconda2/envs/py3/lib/python3.6/site-packages/torch/cuda/init.py in _check_driver()
49 def _check_driver():
50 if not hasattr(torch._C, '_cuda_isDriverSufficient'):
---> 51 raise AssertionError("Torch not compiled with CUDA enabled")
52 if not torch._C._cuda_isDriverSufficient():
53 if torch._C._cuda_getDriverVersion() == 0:
AssertionError: Torch not compiled with CUDA enabled

Error in the lesson #6

In the "Gradient Descent - Classification" section got the following error:

learning_rate = 1e-2
for t in range(3000):
    p = (-lin(a,b,x)).exp()
    y_hat = 1/(1+p)
    loss = nll(y_hat,y)
    if t % 1000 == 0:
        print(loss.data[0], np.mean(to_np(y)==(to_np(y_hat)>0.5)))
#         print(y_hat)
    
    loss.backward()
    a.data -= learning_rate * a.grad.data
    b.data -= learning_rate * b.grad.data
    a.grad.data.zero_()
    b.grad.data.zero_()    
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/numpy/core/fromnumeric.py in _wrapfunc(obj, method, *args, **kwds)
     51     try:
---> 52         return getattr(obj, method)(*args, **kwds)
     53 

/usr/local/lib/python3.6/dist-packages/torch/autograd/variable.py in __getattr__(self, name)
     66             return getattr(self.data, name)
---> 67         return object.__getattribute__(self, name)
     68 

AttributeError: 'Variable' object has no attribute 'clip'

During handling of the above exception, another exception occurred:

RuntimeError                              Traceback (most recent call last)
<ipython-input-15-99e65ec4591a> in <module>()
      3     p = (-lin(a,b,x)).exp()
      4     y_hat = 1/(1+p)
----> 5     loss = nll(y_hat,y)
      6     if t % 1000 == 0:
      7         print(loss.data[0], np.mean(to_np(y)==(to_np(y_hat)>0.5)))

<ipython-input-13-30484270c42d> in nll(y_hat, y)
      1 def nll(y_hat, y):
----> 2     y_hat = np.clip(y_hat, 1e-5, 1-1e-5)
      3     return (y*y_hat.log() + (1-y)*(1-y_hat).log()).mean()

/usr/local/lib/python3.6/dist-packages/numpy/core/fromnumeric.py in clip(a, a_min, a_max, out)
   1773 
   1774     """
-> 1775     return _wrapfunc(a, 'clip', a_min, a_max, out=out)
   1776 
   1777 

/usr/local/lib/python3.6/dist-packages/numpy/core/fromnumeric.py in _wrapfunc(obj, method, *args, **kwds)
     60     # a downstream library like 'pandas'.
     61     except (AttributeError, TypeError):
---> 62         return _wrapit(obj, method, *args, **kwds)
     63 
     64 

/usr/local/lib/python3.6/dist-packages/numpy/core/fromnumeric.py in _wrapit(obj, method, *args, **kwds)
     40     except AttributeError:
     41         wrap = None
---> 42     result = getattr(asarray(obj), method)(*args, **kwds)
     43     if wrap:
     44         if not isinstance(result, mu.ndarray):

/usr/local/lib/python3.6/dist-packages/torch/autograd/variable.py in __bool__(self)
    123             return False
    124         raise RuntimeError("bool value of Variable objects containing non-empty " +
--> 125                            torch.typename(self.data) + " is ambiguous")
    126 
    127     __nonzero__ = __bool__

RuntimeError: bool value of Variable objects containing non-empty torch.cuda.ByteTensor is ambiguous

Improve the naming of things?

I think the fast.ai lessons are great and I like the idea of the fastai library but the (idiosyncratic) naming style of the library makes my brain hurt -- and I believe it will hurt adoption of this library.

Some examples: can you tell what these names mean?

  • m
  • sz
  • bs
  • lrs
  • wds
  • tfms

It's hard to tell what they are without context but even in context it's often not obvious what these things mean. I called it an idiosyncratic naming style because this is how Jeremy likes to name the variables in his notebooks during the lessons, but they are not standard abbreviations and they're not obvious (at least not to me).

I suggest using terms that are fully written out:

  • model
  • input_size or image_size (or even img_size)
  • batch_size
  • learning_rates
  • weight_decays
  • transforms

It's not just the above terms; abbreviations and two-letter parameter names are used throughout the codebase. If I see a parameter sz it doesn't immediately read as size to me, and even if it does, it still doesn't tell me what it is the size of.

In my own library, I have a function plot_most_confident_incorrect_by_recall(). Long name but it's pretty obvious what it does (it plots the examples that were classified with high confidence but that were incorrect according to the recall metric).

API design is user interface design. If this library is intended to make deep learning easy (or uncool again 😄) then in my opinion the API could be made a lot more frictionless.

Thanks!

Resolve package not found

I was running the conda env update command and I received the following error on a Windows 10 machine

Solving environment: failed

ResolvePackageNotFound:
  - pytorch[version='>=0.2.0']
  - ptyprocess
  - libgcc
  - glib
  - fontconfig
  - readline
  - libgfortran
  - jbig
  - libffi
  - torchvision[version='>=0.1.9']

fix_missing possible bug?

On this line the fix_missing function would "fix" a given column if it contains any missing values in it by filling in the NaN by the median and adding a new column like my_column_name_na.
The way we use it is typically like this (by passing in the na_dict from the train dataset to the test dataset):

train_df, y, nas, mapper = proc_df(train_df, 'Sales', do_scale=True) 
test_df, _, nas, mapper = proc_df(test_df, 'Sales', do_scale=True, mapper=mapper, na_dict=nas)

Now what happens if both dataframes has, say, a column named material and this columns has no NaN in train_df but do have NaN in test_df? We will end up with test_df having 1 more column than train_df and it will break the number of inputs for our model right?

Bug in fast.ai transform.py

transforms_pt = [RandomRotateZoom(9, 0.18, 0.1), RandomLighting(0.05, 0.1), RandomDihedral()]
tfms=tfms_from_model(f_model, sz, aug_tfms=transforms_pt, pad=sz//12)

val_idx = get_cv_idxs(train_len)
data = ImageClassifierData.from_csv(path, 'train-jpg', f'{path}train_v2.csv', bs, tfms, suffix='.jpg', val_idxs=val_idx, test_name='test-jpg')
lr=0.2
lrs=[lr/9, lr/3, lr]
learn = ConvLearner.pretrained(f_model, data, metrics=metrics)
        
learn.fit(lr, 3, cycle_len=1, cycle_mult=2)
Error: 
  0%|          | 0/506 [00:00<?, ?it/s]
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-28-a0d195fa61d1> in <module>()
     11 learn = ConvLearner.pretrained(f_model, data, metrics=metrics)
     12 
---> 13 learn.fit(lr, 3, cycle_len=1, cycle_mult=2)

~/fastai/courses/dl1/fastai/learner.py in fit(self, lrs, n_cycle, wds, **kwargs)
    211         self.sched = None
    212         layer_opt = self.get_layer_opt(lrs, wds)
--> 213         self.fit_gen(self.model, self.data, layer_opt, n_cycle, **kwargs)
    214 
    215     def warm_up(self, start_lr=1e-5, end_lr=10, wds=None):

~/fastai/courses/dl1/fastai/learner.py in fit_gen(self, model, data, layer_opt, n_cycle, cycle_len, cycle_mult, cycle_save_name, metrics, callbacks, use_wd_sched, norm_wds, wds_sched_mult, **kwargs)
    158         n_epoch = sum_geom(cycle_len if cycle_len else 1, cycle_mult, n_cycle)
    159         fit(model, data, n_epoch, layer_opt.opt, self.crit,
--> 160             metrics=metrics, callbacks=callbacks, reg_fn=self.reg_fn, clip=self.clip, **kwargs)
    161 
    162     def get_layer_groups(self): return self.models.get_layer_groups()

~/fastai/courses/dl1/fastai/model.py in fit(model, data, epochs, opt, crit, metrics, callbacks, **kwargs)
     84         stepper.reset(True)
     85         t = tqdm(iter(data.trn_dl), leave=False, total=len(data.trn_dl))
---> 86         for (*x,y) in t:
     87             batch_num += 1
     88             for cb in callbacks: cb.on_batch_begin()

~/anaconda3/envs/fastai/lib/python3.6/site-packages/tqdm/_tqdm.py in __iter__(self)
    951 """, fp_write=getattr(self.fp, 'write', sys.stderr.write))
    952 
--> 953             for obj in iterable:
    954                 yield obj
    955                 # Update and possibly print the progressbar.

~/fastai/courses/dl1/fastai/dataset.py in __next__(self)
    241         if self.i>=len(self.dl): raise StopIteration
    242         self.i+=1
--> 243         return next(self.it)
    244 
    245     @property

~/fastai/courses/dl1/fastai/dataloader.py in __iter__(self)
     73     def __iter__(self):
     74         with ThreadPoolExecutor(max_workers=self.num_workers) as e:
---> 75             for batch in e.map(self.get_batch, iter(self.batch_sampler)):
     76                 yield get_tensor(batch, self.pin_memory)
     77 

~/anaconda3/envs/fastai/lib/python3.6/concurrent/futures/_base.py in result_iterator()
    584                     # Careful not to keep a reference to the popped future
    585                     if timeout is None:
--> 586                         yield fs.pop().result()
    587                     else:
    588                         yield fs.pop().result(end_time - time.time())

~/anaconda3/envs/fastai/lib/python3.6/concurrent/futures/_base.py in result(self, timeout)
    423                 raise CancelledError()
    424             elif self._state == FINISHED:
--> 425                 return self.__get_result()
    426 
    427             self._condition.wait(timeout)

~/anaconda3/envs/fastai/lib/python3.6/concurrent/futures/_base.py in __get_result(self)
    382     def __get_result(self):
    383         if self._exception:
--> 384             raise self._exception
    385         else:
    386             return self._result

~/anaconda3/envs/fastai/lib/python3.6/concurrent/futures/thread.py in run(self)
     54 
     55         try:
---> 56             result = self.fn(*self.args, **self.kwargs)
     57         except BaseException as exc:
     58             self.future.set_exception(exc)

~/fastai/courses/dl1/fastai/dataloader.py in get_batch(self, indices)
     66 
     67     def get_batch(self, indices):
---> 68         res = self.collate_fn([self.dataset[i] for i in indices], self.pad_idx)
     69         if not self.transpose: return res
     70         res[0] = res[0].T

~/fastai/courses/dl1/fastai/dataloader.py in <listcomp>(.0)
     66 
     67     def get_batch(self, indices):
---> 68         res = self.collate_fn([self.dataset[i] for i in indices], self.pad_idx)
     69         if not self.transpose: return res
     70         res[0] = res[0].T

~/fastai/courses/dl1/fastai/dataset.py in __getitem__(self, idx)
     95     def __getitem__(self, idx):
     96         x,y = self.get_x(idx),self.get_y(idx)
---> 97         return self.get(self.transform, x, y)
     98 
     99     def __len__(self): return self.n

~/fastai/courses/dl1/fastai/dataset.py in get(self, tfm, x, y)
    100 
    101     def get(self, tfm, x, y):
--> 102         return (x,y) if tfm is None else tfm(x,y)
    103 
    104     @abstractmethod

~/fastai/courses/dl1/fastai/transforms.py in __call__(self, im, y)
    463         if crop_type == CropType.NO: crop_tfm = NoCropXY(sz, tfm_y)
    464         self.tfms = tfms + [crop_tfm, normalizer, channel_dim]
--> 465     def __call__(self, im, y=None): return compose(im, y, self.tfms)
    466 
    467 

~/fastai/courses/dl1/fastai/transforms.py in compose(im, y, fns)
    444 def compose(im, y, fns):
    445     for fn in fns:
--> 446         im, y =fn(im, y)
    447     return im if y is None else (im, y)
    448 

~/fastai/courses/dl1/fastai/transforms.py in __call__(self, x, y)
    134         if choice==0: pass
    135         elif choice==1: x = rotate_cv(x, rand0(self.deg), self.mode)
--> 136         elif choice==2: x = zoom_cv(x, random.random()*self.zoom)
    137         elif choice==3:
    138             str_choice = random.randint(0,1)

~/fastai/courses/dl1/fastai/transforms.py in zoom_cv(x, z)
     17 def zoom_cv(x,z):
     18     if z==0: return x
---> 19     r,c,*_ = im.shape
     20     M = cv2.getRotationMatrix2D((c/2,r/2),0,z+1.)
     21     return cv2.warpAffine(x,M,(c,r))

NameError: name 'im' is not defined

No matching distribution for ipython

When installing dependencies via:
pip install -r requirements.txt

I get:

Could not find a version that satisfies the requirement ipython>=6.2.0 (from -r requirements.txt (line 9)) (from versions: 0.10, 0.10.1, 0.10.2, 0.11, 0.12, 0.12.1, 0.13, 0.13.1, 0.13.2, 1.0.0, 1.1.0, 1.2.0, 1.2.1, 2.0.0, 2.1.0, 2.2.0, 2.3.0, 2.3.1, 2.4.0, 2.4.1, 3.0.0, 3.1.0, 3.2.0, 3.2.1, 3.2.2, 3.2.3, 4.0.0b1, 4.0.0, 4.0.1, 4.0.2, 4.0.3, 4.1.0rc1, 4.1.0rc2, 4.1.0, 4.1.1, 4.1.2, 4.2.0, 4.2.1, 5.0.0b1, 5.0.0b2, 5.0.0b3, 5.0.0b4, 5.0.0rc1, 5.0.0, 5.1.0, 5.2.0, 5.2.1, 5.2.2, 5.3.0, 5.4.0, 5.4.1, 5.5.0)
No matching distribution found for ipython>=6.2.0 (from -r requirements.txt (line 9))

Is it a bug in the requirements.txt file?

I know the README.md suggests using conda, but i'd rather use virtualenv or virtualenvwrapper. Is this the problem?

error from metrics=[accuracy] in lesson-4.imdb

From https://github.com/fastai/fastai/blob/master/courses/dl1/lesson4-imdb.ipynb
m3.fit(lrs/2, 1, metrics=[accuracy])

metrics throws an up the pytorch stack.

m3.fit(lrs/2, 1)

results no error

error

TypeError: eq received an invalid combination of arguments - got (Variable), but expected one of:

  • (int value)
    didn't match because some of the arguments have invalid types: (Variable)
  • (torch.cuda.LongTensor other)
    didn't match because some of the arguments have invalid types: (Variable)

Unclear variables

Hi guys, thanks a lot for your job, it's the best ml course I've ever seen.

I just have a issue about variable names in notebooks and especially in fastai library. It's ok to read a notebook right after watching its lesson, but if I want to recall something after a few days, I can't do this just looking at code, e.g. lrf=learn.lr_find(), I need at least read markdown, think model.find_learn_rate() would be much understandable even without any comments.

Btw this does not prevent you to use shortcuts, you can add them as aliases, e.g. lr_find() would be an alias for find_learn_rate().

So what do you think? I will look at the code during the course anyway, so I would provide a few pull requests with improved var names if you agree.

Raise an error if test_name='test' but the test folder is empty or doesn't exist.

When you define the data object and do provide test_name='test'

data = ImageClassifierData.from_csv(PATH, folder='train', csv_fname=f'{PATH}labels.csv',
                                    tfms=tfms, val_idxs=get_cv_idxs(n=4750), test_name='test', bs=12)

But, the test folder is empty or doesn't exist, this assignment results in the following error:
image
image

The function read_dir() in dataset.py is used to read the test. The function already contains a TODO: warn or error if no files are found?

read_dir() is only used to read the test data folder.

image

image

The function gets called only when test_name is True. I think this should raise a FileNotFoundError is it returns an empty list. Something like the following:

image

That way the error message would be more explicit.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.