Name 'widgets' is not defined & taking lot of time to run the fastbook ch-1 on colab

I am running the first chapter of fastbook on colab - while running this cell with uploader, it is giving me an error.

Also, why it is taking huge amount of time for me on colab to run the chapter-1?


It took me 32min and 47 mins where as in the book - it is just 14secs and 19secs ??

(I changed the runtime to GPU!)

2 Likes

See the recent post in v2 chat. Most likely the wrong torch version is installed. Also widgets will not work in colab.

Were you able to solve this?

Widgets do not work in Colab (as my previous post states). If it takes a long time to train make sure you have the GPU enabled and torch.cuda.is_available() returns true

1 Like

Greetings!
How do I solve the first error i.e. NameError?

You can’t run the widgets section inside Google Colab, so there is no working solution. As I said in the first sentence and my first post.

It just happened to me in paperspace: https://nmf7d80p.gradient.paperspace.com/notebooks/fastbook/01_intro.ipynb

I searched for information about widgets in jupyter and gradient and found this:

https://ipywidgets.readthedocs.io/en/stable/examples/Widget%20Basics.html

Using that information I added the following line:

import ipywidgets as widgets

to the existing code so that it is now:

#hide_output
import ipywidgets as widgets
uploader = widgets.FileUpload()
uploader

and it ran and I could upload my image. So, if others are having that problem, try adding that import statement.

23 Likes

I had this issue on Paperspace too and this did the trick. Thanks @jeffbiss!

1 Like

Good to hear that I was able to help someone! You’re welcome.

Saved me too, thanks!

This solution worked for me but then I had this error in the next bit of code

NameError: name ‘SimpleNamespace’ is not defined

Is there some kind of compatibility error going on? Super discouraging to have wrenches thrown into your very first examples.

Depending on what I missed, I had other errors, don’t remember if that was one though. I suggest to start at the very beginning and run each bit of code, maybe you missed one and that lead to that error, I know that that was the case for me. Try it and let us know if it clears up or not.

1 Like

This worked for me too, thanks!

OK, thanks.

Thanks … I had the same problem and this solution worked for me.

It was so helpful. Thanks a lot

First write the following code :
from fastbook import *
After this write the code for widgets.FileUpload()

1 Like

What a lifesaver! Thanks a ton @jeffbiss

You’re welcome! I’m just glad that I am actually able to help.

jeffbliss, thank you! This solved the issue in SageMaker as well.

Best
PO

1 Like