I have a dataset folder on my local drive which has 5 batches of training data and 1 batch of test data. How do I upload this folder to Google Colab and load it into a data bunch using the fastai library ?
I’d recommend syncing colab with your Google Drive and uploading the files to Google Drive You can either press “Mount Drive” and run the cell that is generated, or do:
from google.colab import drive drive.mount('/content/drive')
I’ve done this part. But how do I load it into a data bunch after that ?
This is my data folder on my Gooogle Drive. Now, how do I load it into a data bunch in Google Colab using the fastai library ?
You’d dictate a
Path that points to your drive. After you mount it your google drive stuff is in
/content/drive. In Google Colab we do not need the
/content bit. So for your example, navigating to the “fast.ai” folder is as simple as
path = Path('drive/My Drive/fast.ai') Does this help?
Second, how are these batches saved? Eg. what are they?
Each batch contains 10000 images divided amongst 10 classes.
I’m really sorry for the repeated buggering but after creating this path, path.ls() returns
I used codelab last week, and I was able to acces my google drive using these steps
- install colab from fastai: !curl -s https://course.fast.ai/setup/colab | bash
- import drive: from google.colab import drive
- mount google drive: drive.mount(’/content/gdrive’, force_remount=True)
- after this I had to authenticate
- I created a folder to hold my data;
root_dir = “/content/gdrive/My Drive/”
base_dir = root_dir + ‘fastai-v3/’
from pathlib import Path
path = Path(base_dir + ‘data/bears’)
dest = path
- now I can see this folder in google drive and in my notebook
Thanks @tomvanacker. Will try it out.
I am still not able to access files in Jupyter nb.
the images in Markup still appear broken.
How to i see the images in the markup and access files from my Drive in collab?
One thing I notice. In your screenshot earlier, files are located at “My Drive/fast.ai/cifar-10-batches-py”. So why do you set the base_dir to “Colab Notebooks/fastai/course-v3/nbs.dl1”? Did you put a copy of the course inside your google drive?
Hi that was someone else’s screenshot, even i faced something similar so i posted even my question here, also yeah i cloned entire course-v3 into my drive
ok, that explains it. So where are your data files located? And how do you load them? Can you show some code? “The images in markup appear broken” … do you have screenshot?
my present working directory is the nbs/dl1, so ideally it should get images/notebook_tutorial/add.png, but i dont know why it doesnt load.
what happens if you use the complete path “/content/gdrive/My Drive/Colab Notebooks/fastai/course-v3/nbs.dl1/images/notebook_tutorial/add.png” ?
Maybe is it a good idea to read this article: https://medium.com/ai³-theory-practice-business/set-up-colab-for-fastai-courses-61e75bcfb3b6