Lesson 1 official topic

2 Likes

Hello,
I just started the 1st FastAI course in conjunction with the recommended book.
The author advises to use tools like Kaggle or Paperspace instead of using the local environment, for practical reasons (GPU in particular)

What do you recommend? Kaggle or PaperSpace?

What is the general process? git clone the fastai github repository onto a Kaggle notebook and then browse each notebook?
Although I did it, I could not navigate, not being too familiar with the Kaggle platform, I see the .ipnyb file names available, but I canā€™t access each of the cloned notebooks from the notebook.

Sounds like ā€˜GPUā€™ is not selected. See this thread for my note on how to select it.

1 Like

Hi Saad,

I havenā€™t checked out PaperSpace so far, so wouldnā€™t be able to give a comparison. But here is the process to run the notebooks on other platforms.

If you are looking to run the code in the book then you can use colab: https://colab.research.google.com/

  • What you can do is simply replace github.com to Google Colab and the rest of the address. For example: https:// github.com/ fastai/fastbook/blob/master/01_intro.ipynb can be opened on colab with https:// colab.research.google.com/ github/ fastai/fastbook/blob/master/01_intro.ipynb (Note: Iā€™ve added spaces in the URL as it was turning the URL into a hyperlink and the modification wouldnā€™t be clear)

  • In order to use GPU on colab, you can ā€œchange runtime typeā€ to add a GPU accelerator

In addition to the text book code, the official notebook for this lecture is on Kaggle already: Is it a bird? Creating a model from your own data | Kaggle
So all you have to do is, copy and run it within Kaggle. Then you can modify it according to the problem of your choice!

Hello,
I just completet lesson 1 and tried to alter the official Kaggle notebook. I added a dataset of chess pieces and want to classify them, but I get bad results quite often.

  • Some pieces are classified correctly
  • Some easy looking pieces are classified incorrectly (check link for an example)
  • Kings are always classified incorrectly

Can someone please help me out? I tried a few different things but I just canā€™t find the reasonā€¦ https://www.kaggle.com/code/maxwe000/is-it-a-king-creating-a-model-from-your-own-data

Anyone tried toying with image segmentation?

I tried to modify the segmentation code from the textbook so that it could do image segmentation on my choice of images like the streets of Dubai or Paris.

For classification, we do learn.predict() at the end on our choice of input image and it gives the prediction along with the probabilities.

What to do for segmentation? I tried learn.segment() :see_no_evil: :sweat_smile: but there is no such thing as that.

Please help.

Sharing the NB below.

Segmentation as introduced in lession 1 seems to be connected to classification (classifying different pixels). Is there a different term for regression-segmentation (things like heatmaps etc)

You do learn.predict() after training your model to classify (or segment) a new image where you donā€™t have the correct label or segmentation mask (thats called ā€œinferenceā€). The .predict() method is agnostic to what task you are trying to solve.

Here is the relevant segment of the fast.ai documentation for semantic segmentation, this may nudge you in the right direction: fastai - Computer vision intro

1 Like

Youā€™ve hit the most common issue Iā€™ve seen extrapolating from the bird/forest exampleā€¦
Where that example was simplified by hardcoding zero in probs[0], you need to use the value ignored by the underscoreā€¦

i.e. instead ofā€¦

category,_,probs = learn.predict(PILImage.create('king.jpg'))
print(f"This is a: {category}.")
print(f"Probability it's a {category}: {probs[0]:.4f}")

useā€¦

category,index,probs = learn.predict(PILImage.create('king.jpg'))
print(f"This is a: {category}.")
print(f"Probability it's a {category}: {probs[index]:.4f}")
2 Likes

Hi guys, I could use some assistance with the codeā€¦ I am not using Jupyter Notebook rather I am using PyCharm (free edition without Jupyter Notebook). I am encountering an issue when trying to download the images from this code

searches = 'forest','bird'
path = Path('bird_or_not')
from time import sleep

#for o in searches:
#    dest = (path/o)
#    dest.mkdir(exist_ok=True, parents=True)
#    download_images(dest, urls=search_images(f'{o} photo'))
#    sleep(10)  # Pause between searches to avoid over-loading server
#    download_images(dest, urls=search_images(f'{o} sun photo'))
#    sleep(10)
#    download_images(dest, urls=search_images(f'{o} shade photo'))
#    sleep(10)
#    resize_images(path/o, max_size=400, dest=path/o)

The error that I get is

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\multiprocessing\spawn.py", line 116, in spawn_main
    exitcode = _main(fd, parent_sentinel)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\multiprocessing\spawn.py", line 125, in _main
    prepare(preparation_data)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\multiprocessing\spawn.py", line 236, in prepare
    _fixup_main_from_path(data['init_main_from_path'])
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_path
    main_content = runpy.run_path(main_path,
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 288, in run_path
    code, fname = _get_code_from_file(run_name, path_name)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 252, in _get_code_from_file
    with io.open_code(decoded_path) as f:
OSError: [Errno 22] Invalid argument:

I cannot for the life of me figure it out so any help would be much appreciated

I canā€™t see it either. It doesnā€™t help that you are in the 0.1%** group approaching it like this. I recommend you install WSL Ubuntu on Windows and first get it working with Jupyter the way 99.9%** others do it. Once you are comfortable doing it that way, you will be better positioned to try again on Windows.

**Note, 72% of statistics are made up on the spotā€¦

1 Like

Thanks for the fun stats. The thing is that I want to use PyCharm (free) since that is what I currently use for my job on a company machine with severely draconian restrictionsā€¦ so Jupyter is a bit of a no go for meā€¦

1 Like

On the ā€œwecome to fastaiā€ page on https://docs.fast.ai/, it is stated that:

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.

Where is this ā€œopen in colabā€ button or link? On the top of the cited page, all I see is ā€œCI failingā€, ā€œPyPIā€, ā€œConda (channel only)ā€, ā€œBuild fastaiā€, and ā€œimages docsā€. What am I missing?

I had the very same issue ā€“ check to see that your model predicts a picture of a forest to be a cow with 99% accuracy. If so, then do what is recommended in the message from bencoman that begins ā€œYouā€™ve hit the most common issue Iā€™ve seen extrapolating ā€¦ā€

Thank you a lot!

Hi! Very basic question: how do the cells in Jupyter (e.g. in the Is it a bird? file) have access to some libraries without installing them? E.g. from fastcore.all import *. I never saw a pip install fastcore.

I tried to reproduce this in my local iPython, but I canā€™t install fastai on a Mac m1.

Itā€™s because Kaggle kernels come with fastai library preinstalled

2 Likes

Ah that makes sense, thanks!

I got it working locally now and it seems that the fastai library makes packages like fastdownload and fastcore available.

The fastai library is installed in the second code block of the Jupyter notebook, so it all makes sense now :smile:

1 Like

If youā€™re going through Chapter 1 of the book, thereā€™s a section where you need to upload a picture to test your model. This didnā€™t work for me on Colab, but thereā€™s some workaround to it:

A- Manually by creating a folder in root and name it ā€œimagesā€
1- Click on the folders tab on the right, then right click to add a new folder and name it ā€˜imagesā€™
2-Above the folders, click on the first icon on the row to upload a file.
3-Move the photo to the ā€˜imagesā€™ folder youā€™ve created.
4-You can either name it ā€œchapter1_cat_example.jpgā€ or change this cell to the name of your picture. You can skip the upload part and execute this cell:

#hide
# For the book, we can't actually click an upload button, so we fake it
uploader = SimpleNamespace(data = ['images/<your_image_name.jpg>'])

B- This worked for me, by uploading the photos using the upload cell and skip the next cell and jump to prediction cell

Good luck.

1 Like