Lesson 2 on Colab

download_images(path/file, dest, max_pics=200)

gives this error

FileNotFoundError Traceback (most recent call last)

<ipython-input-22-e85756baeaa4> in <module>() ----> 1 download_images(path/file, dest, max_pics=200)

/usr/local/lib/python3.6/dist-packages/fastai/vision/data.py in download_images(urls, dest, max_pics, max_workers, timeout) 194 def download_images(urls:Collection[str], dest:PathOrStr, max_pics:int=1000, max_workers:int=8, timeout=4): 195 “Download images listed in text file urls to path dest, at most max_pics" --> 196 urls = open(urls).read().strip().split(”\n")[:max_pics] 197 dest = Path(dest) 198 dest.mkdir(exist_ok=True)

FileNotFoundError: [Errno 2] No such file or directory: ‘data/bears/urls_black.txt’


How to upload the urls_black.txt file to the colab environment (if possible then from the pc directly)

1 Like

hi sheatran I have to deal with the same problem and I find this in the forum that works for me:
1 - create a new code cell after the line “folder = ‘grizzly’…” and put the following code:

from google.colab import drive
drive.mount('/content/gdrive', force_remount=True)
root_dir = "/content/gdrive/My Drive/"
base_dir = root_dir + 'fastai-v3/data/'

2 - After that you will see a link to authorize you notebook to acess you google drive, click on it, and insert the code back in you notebook.

3 - After that change this line “path = Path(‘data/bears’)” for this:
path = Path(base_dir)

4 - open you google drive and there will be a folder “fastai-v3/data” where you can upload you .txt

Make sure you are executing the steps mentioned in the video and take care of the folder you notebook will be reading (e.g. using print() for that),

11 Likes

I am not able to generate the text file using the javascript from the google image search. Can someone share with me the txt file or tell me what I could be doing wrong. I am using google chrome and this is the script that I am running.

urls = Array.from(document.querySelectorAll(’.rg_di .rg_meta’)).map(el=>JSON.parse(el.textContent).ou);
window.open(‘data:text/csv;charset=utf-8,’ + escape(urls.join(’\n’)));

@challa What is happening, when you’re executing this line in the javascript console of browser?

@apoorv16 I can see a new tab opening and get closed even before I can do anything.

@challa That downloads a file ‘download.csv’ , check that once. Once check if pop-up is getting blocked. Let me if the problem is still not solved

1 Like

I have same issue and i only see black window.

i found this solution works. Found on forums.

javascript:document.body.innerHTML = `<a href="data:text/csv;charset=utf-8,${escape(Array.from(document.querySelectorAll('.rg_di .rg_meta')).map(el=>JSON.parse(el.textContent).ou).join('\n'))}" download="links.txt">download urls</a>`;
2 Likes

@sahil.soni2409 Great, by the way you were trying in which browser ?

For the javascript that scrapes the url, are the urls supposed to be separated in a new line? I have all the urls joined together using the script provided.

I used Chrome.

@mario_jorge I successfully ran steps 1-3 but I do not see a “fastai-v3” folder on my Google Drive, what am I doing wrong?

nevermind it just appeared!

1 Like

Hi, i am doing lesson-2 and i have a doubt on the opening images part in production.
img = open_image(path/‘blackbears.txt’/‘00000021.jpg’)
In the above code, how do i know there is a file with name “00000021.jpg” and what are the other names?
@smigula

From my understanding that was simply some example code of deploying a model, the name of that file could be anything it depends on what it is saved as when it is uploaded to your server. I would bypass that section of the lesson and follow these instructions on deploying your model to render.

Thanks for the process, it helped.

But when downloading different type of images in their respective folders, I only find images visible in 1 of them other 2 are empty.

It couldn’t download black bears and brown bears images.

2 Likes

Hello, can anyone help me figure out why I can not seem to download the images after I scraped them off of google images? I keep getting this error:

FileNotFoundError Traceback (most recent call last)

<ipython-input-13-e85756baeaa4> in <module>() ----> 1 download_images(path/file, dest, max_pics=200)

/usr/local/lib/python3.6/dist-packages/fastai/vision/data.py in download_images(urls, dest, max_pics, max_workers, timeout) 192 def download_images(urls:Collection[str], dest:PathOrStr, max_pics:int=1000, max_workers:int=8, timeout=4): 193 “Download images listed in text file urls to path dest , at most max_pics " --> 194 urls = open(urls).read().strip().split(”\n")[:max_pics] 195 dest = Path(dest) 196 dest.mkdir(exist_ok=True)

FileNotFoundError: [Errno 2] No such file or directory: ‘/content/gdrive/My Drive/fastai-v3/data/urls_grizzly.csv’

I’ve seen a few blog post suggesting to the following code :
from google.colab import drive
drive.mount(’/content/gdrive’, force_remount=True)
root_dir = “/content/gdrive/My Drive/”
base_dir = root_dir + 'fastai-v3/data/

However this does not work. I keep getting the same error. I’ve moved the files around to several locations, but I still keep getting the error. Can someone please help, I’m using google colab by the way.

Thank You

Hey, it would be a big help if you could run me through what I have to do. I did exactly like you said…but there seems to be folder named fastai-v3/data

Hey, did you figure it out. Like could you run the notebook on google colab? I am having a hard time getting the data loaded into the notebook

I actually never got it working. I just went on to the next tutorial, and just worked through problems in data science books to make up for it.