Resuing a zip file from google colab
For anyone wondering how to do this...
first, zip you file containing your images and upload to Google Drive
second, in Google Colab, mount your drive
from google.colab import drive
drive.mount('/content/drive')
third, copy the zip folder into your local environment
!cp "/file path with the zip image folder.zip" "whatever you want to call the file when unzipped"
fourth, unzip in local colab into a folder you made
!unzip -uq "whatever you want to call the file when unzipped" -d "folder where you want them unzipped (or just make one up)"
You will have to do this every time, but it is super quick compared to what I was doing before
How to access zip files from drive on Google collab?
Skip PyDrive and mount your Google Drive directly using this snippet:
from google.colab import drive
drive.mount('/content/drive')
Then, you can access directories in Drive just as though they were normal files on the backend VM.
Import data into Google Colaboratory
An official example notebook demonstrating local file upload/download and integration with Drive and sheets is available here:
https://colab.research.google.com/notebooks/io.ipynb
The simplest way to share files is to mount your Google Drive.
To do this, run the following in a code cell:
from google.colab import drive
drive.mount('/content/drive')
It will ask you to visit a link to ALLOW "Google Files Stream" to access your drive. After that a long alphanumeric auth code will be shown that needs to be entered in your Colab's notebook.
Afterward, your Drive files will be mounted and you can browse them with the file browser in the side panel.
Here's a full example notebook
How to open and work on files stored in Google drive from Google colab?
First you need to mount google drive and then
from google.colab import drive
drive.mount('/content/gdrive')Click the link on colb and authenticate (copy password and paste in colab) to mount and access your gdrive.
You can access your folder as shown below
path_to_data = '/content/gdrive/My Drive/MyFolder_where_data_stored'
Unique_Labels_List = os.listdir(path_to_data)After running model, save the model, zip and download to local.
!zip -r ./MyFolder.zip /content/MyFolder
files.download("/content/MyFolder.zip")
There are many other things you can do. Check this resource for some more commands and you can find many more by searching in google. Thanks!
My colab won't let me import my dataset folder in drive
Is /content/gdrive/MyDrive/Colab Notebooks/PetImages
a ZIP file or is this the folder containing the ZIP file you want to extract?
The error message says that you are not passing a ZIP file but a folder.
So probably:
zf = zipfile.ZipFile(DATA_PATH + "PetImages/images.zip", "r")
zf.extractall(DATA_PATH)
upload file to another Drive Google colab
I finally found a solution through the PyDrive library.
Here is an example for the curious little ones ;)
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
gfile = drive.CreateFile({'parents': [{'id': 'ID folder'}]})
gfile.SetContentFile("file path")
gfile.Upload()
Once the imports and the creation of the gauth variable have been executed, you will be asked for permissions on your account (don't be surprised)
Hope this helps anyone in need !
Related Topics
Pyside - Pyqt:How to Make Set Qtablewidget Column Width as Proportion of the Available Space
Turn the Column Headers into the First Row and Row Headers into the First Column in Pandas Dataframe
How to Find the Average of Particular Numbers in a CSV File
Google Chrome Closes Immediately After Being Launched With Selenium
Python-3: Why This Following Code Returns None in Print Statement
Python Check Multi-Level Dict Key Existence
Convert Image Files to a CSV File
Stored Procedures With Sqlalchemy
Pyodbc Error Data Source Name Not Found and No Default Driver Specified Paradox
How to Merge Two Cnn That Are Trained Over Different Data Stream
How to Display a Plot in Fullscreen
Matching Text Between a Pair of Single Quotes
How to Do This Horizontally Instead of Vertically in Python
How to Send Smtp Email for Office365 With Python Using Tls/Ssl
How to Determine If Current Time Is Within a Specified Range Using Python'S Datetime Module
Selenium Python Send_Key Error: List Object Has No Attribute