Lesson 3 - Non-beginner discussion

This is the topic for any non-beginner discussion around lesson 3. It won’t be actively monitored by Jeremy or I tonight, but we will answer standing questions in here tomorrow (if needed).

1 Like

Since we’re talking about deployment … I’m hoping someone can provide some insight into why I’m getting this error when I call learn.predict(img_bytes) in my FastAPI/Starlette project:

See: https://forums.fast.ai/t/fastapi-starlette-issue-attributeerror-fakeloader-object-has-no-attribute-noops/66916/2?u=wgpubs

I’m using version 0.0.15 and the code is pretty much the same as reference examples from last week. Been wrestling with this for several days but I’m at wits end as to what is going on. I have noticed that other folks are seeing the same

File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/site-packages/fastai2/torch_core.py", line 213, in to_concat
    if is_listy(xs[0]): return type(xs[0])([to_concat([x[i] for x in xs], dim=dim) for i in range_of(xs[0])])
IndexError: list index out of range

… error in other places, so maybe its related.

Thanks much!

I stumbled over the below syntax in the notebook (similarly for the earlier train_epoch function). I would expect dl and opt to be parameters of the function, for clarity and to avoid unwanted side effects.

Is there a particular reason for this or just for brevity?

def train_epoch(model):
    for xb,yb in dl:
        calc_grad(xb, yb, model)
        opt.step()
        opt.zero_grad()

It’s just for brevity and a very common thing to see in Jupyter Notebooks but admittedly feels uncomfortable at first.

Is mixup augmentation in the libary? Sorry - not at a place where I can search the docs.

2 Likes

Yes it is: http://dev.fast.ai/callback.mixup

1 Like

Thank you! And if we do TTA it will take different random crops?

Question from Anant (TWiML Study Group): How do we write our own transforms?

1 Like

Checkout the pets tutorial (which I am in the midts of improving so maybe check it in 48 hours :wink: ). It (will) contain all what you need on this.

2 Likes

TTA will take different random crops (and different versions of your augmentation transforms) yes.

1 Like

When would you want and also not want to use TTA? Any particular use cases for and/or against it?

It is slower, so you might have compute constraints.

Outside of that, any negatives in terms of model performance? It seems like it would be generally better to use since your essentially giving yourself a bigger validation set to evaluate against.

Obviously you would validate it, so you would know if it’s actually better or not :wink:

1 Like

Yah yah … very true.

Btw, if you can solve/explain my issue in post #1 above … I’ll buy you a beer (a good kind … like the kind we brew in San Diego) :slight_smile:

I am no longer replying to people reporting errors without showing the whole stack trace :stuck_out_tongue:

I linked to it … here’s it again though … the whole gory thing …

Traceback (most recent call last):--------------------------------------------------------------------| 0.00% [0/1 00:00<00:00]
  File "<string>", line 1, in <module>
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/multiprocessing/spawn.py", line 105, in spawn_main
    exitcode = _main(fd)
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/multiprocessing/spawn.py", line 115, in _main
    self = reduction.pickle.load(from_parent)
AttributeError: '_FakeLoader' object has no attribute 'noops'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/multiprocessing/spawn.py", line 105, in spawn_main
    exitcode = _main(fd)
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/multiprocessing/spawn.py", line 115, in _main
    self = reduction.pickle.load(from_parent)
AttributeError: '_FakeLoader' object has no attribute 'noops'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/multiprocessing/spawn.py", line 105, in spawn_main
    exitcode = _main(fd)
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/multiprocessing/spawn.py", line 115, in _main
    self = reduction.pickle.load(from_parent)
AttributeError: '_FakeLoader' object has no attribute 'noops'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/multiprocessing/spawn.py", line 105, in spawn_main
    exitcode = _main(fd)
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/multiprocessing/spawn.py", line 115, in _main
    self = reduction.pickle.load(from_parent)
AttributeError: '_FakeLoader' object has no attribute 'noops'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/multiprocessing/spawn.py", line 105, in spawn_main
    exitcode = _main(fd)
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/multiprocessing/spawn.py", line 115, in _main
    self = reduction.pickle.load(from_parent)
AttributeError: '_FakeLoader' object has no attribute 'noops'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/multiprocessing/spawn.py", line 105, in spawn_main
    exitcode = _main(fd)
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/multiprocessing/spawn.py", line 115, in _main
    self = reduction.pickle.load(from_parent)
AttributeError: '_FakeLoader' object has no attribute 'noops'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/multiprocessing/spawn.py", line 105, in spawn_main
    exitcode = _main(fd)
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/multiprocessing/spawn.py", line 115, in _main
    self = reduction.pickle.load(from_parent)
AttributeError: '_FakeLoader' object has no attribute 'noops'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/multiprocessing/spawn.py", line 105, in spawn_main
    exitcode = _main(fd)
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/multiprocessing/spawn.py", line 115, in _main
    self = reduction.pickle.load(from_parent)
AttributeError: '_FakeLoader' object has no attribute 'noops'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/multiprocessing/spawn.py", line 105, in spawn_main
    exitcode = _main(fd)
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/multiprocessing/spawn.py", line 115, in _main
    self = reduction.pickle.load(from_parent)
AttributeError: '_FakeLoader' object has no attribute 'noops'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/multiprocessing/spawn.py", line 105, in spawn_main
    exitcode = _main(fd)
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/multiprocessing/spawn.py", line 115, in _main
    self = reduction.pickle.load(from_parent)
AttributeError: '_FakeLoader' object has no attribute 'noops'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/multiprocessing/spawn.py", line 105, in spawn_main
    exitcode = _main(fd)
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/multiprocessing/spawn.py", line 115, in _main
    self = reduction.pickle.load(from_parent)
AttributeError: '_FakeLoader' object has no attribute 'noops'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/multiprocessing/spawn.py", line 105, in spawn_main
    exitcode = _main(fd)
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/multiprocessing/spawn.py", line 115, in _main
    self = reduction.pickle.load(from_parent)
AttributeError: '_FakeLoader' object has no attribute 'noops'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/multiprocessing/spawn.py", line 105, in spawn_main
    exitcode = _main(fd)
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/multiprocessing/spawn.py", line 115, in _main
    self = reduction.pickle.load(from_parent)
AttributeError: '_FakeLoader' object has no attribute 'noops'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/multiprocessing/spawn.py", line 105, in spawn_main
    exitcode = _main(fd)
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/multiprocessing/spawn.py", line 115, in _main
    self = reduction.pickle.load(from_parent)
AttributeError: '_FakeLoader' object has no attribute 'noops'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/multiprocessing/spawn.py", line 105, in spawn_main
    exitcode = _main(fd)
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/multiprocessing/spawn.py", line 115, in _main
    self = reduction.pickle.load(from_parent)
AttributeError: '_FakeLoader' object has no attribute 'noops'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/multiprocessing/spawn.py", line 105, in spawn_main
    exitcode = _main(fd)
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/multiprocessing/spawn.py", line 115, in _main
    self = reduction.pickle.load(from_parent)
AttributeError: '_FakeLoader' object has no attribute 'noops'
INFO:     127.0.0.1:59886 - "POST /predict HTTP/1.1" 500 Internal Server Error                                                 
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/site-packages/uvicorn/protocols/http/httptools_impl.py", line 385, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in __call__
    return await self.app(scope, receive, send)
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/site-packages/fastapi/applications.py", line 149, in __call__
    await super().__call__(scope, receive, send)
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/site-packages/starlette/applications.py", line 102, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/site-packages/starlette/middleware/errors.py", line 181, in __call__
    raise exc from None
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/site-packages/starlette/middleware/errors.py", line 159, in __call__
    await self.app(scope, receive, _send)
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/site-packages/starlette/exceptions.py", line 82, in __call__
    raise exc from None
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/site-packages/starlette/exceptions.py", line 71, in __call__
    await self.app(scope, receive, sender)
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/site-packages/starlette/routing.py", line 550, in __call__
    await route.handle(scope, receive, send)
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/site-packages/starlette/routing.py", line 227, in handle
    await self.app(scope, receive, send)
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/site-packages/starlette/routing.py", line 41, in app
    response = await func(request)
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/site-packages/fastapi/routing.py", line 166, in app
    dependant=dependant, values=values, is_coroutine=is_coroutine
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/site-packages/fastapi/routing.py", line 119, in run_endpoint_function
    return await dependant.call(**values)
  File "./main.py", line 43, in predict
    pred_class = inf_learn.predict(path/'0172.jpg')[0]
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/site-packages/fastai2/learner.py", line 231, in predict
    inp,preds,_,dec_preds = self.get_preds(dl=dl, with_input=True, with_decoded=True)
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/site-packages/fastai2/learner.py", line 219, in get_preds
    self._do_epoch_validate(dl=dl)
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/site-packages/fastai2/learner.py", line 178, in _do_epoch_validate
    dl,*_ = change_attrs(dl, names, old, has);       self('after_validate')
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/site-packages/fastai2/learner.py", line 124, in __call__
    def __call__(self, event_name): L(event_name).map(self._call_one)
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/site-packages/fastcore/foundation.py", line 372, in map
    return self._new(map(g, self))
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/site-packages/fastcore/foundation.py", line 323, in _new
    def _new(self, items, *args, **kwargs): return type(self)(items, *args, use_list=None, **kwargs)
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/site-packages/fastcore/foundation.py", line 41, in __call__
    res = super().__call__(*((x,) + args), **kwargs)
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/site-packages/fastcore/foundation.py", line 314, in __init__
    items = list(items) if use_list else _listify(items)
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/site-packages/fastcore/foundation.py", line 250, in _listify
    if is_iter(o): return list(o)
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/site-packages/fastcore/foundation.py", line 216, in __call__
    return self.fn(*fargs, **kwargs)
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/site-packages/fastai2/learner.py", line 127, in _call_one
    [cb(event_name) for cb in sort_by_run(self.cbs)]
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/site-packages/fastai2/learner.py", line 127, in <listcomp>
    [cb(event_name) for cb in sort_by_run(self.cbs)]
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/site-packages/fastai2/callback/core.py", line 24, in __call__
    if self.run and _run: getattr(self, event_name, noop)()
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/site-packages/fastai2/callback/core.py", line 95, in after_validate
    if self.with_input:     self.inputs  = detuplify(to_concat(self.inputs, dim=self.concat_dim))
  File "/Users/admin/Development/_tools/anaconda/envs/fastapi_test_app/lib/python3.7/site-packages/fastai2/torch_core.py", line 213, in to_concat
    if is_listy(xs[0]): return type(xs[0])([to_concat([x[i] for x in xs], dim=dim) for i in range_of(xs[0])])
IndexError: list index out of range

Yes, it’s in callback

Sorry did not see the link (and it’s not gory, it’s informative :wink: ).
Your problem is that the web app cannot load the exported model, which I suspect comes from a mismatch of fastai2 or PyTorch versions between training and exporting the model on one side, deploying on the other side. (the real error is AttributeError: '_FakeLoader' object has no attribute 'noops' in the unpickling of the Learner)

For mobile development on the edge, does Fastai2/Pytorch support exporting something equivalent to what TensorflowLite does?