Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

import dataset into google colab from another drive account

lastly I'm working on google colab I get this dataset colled celeba and it is into a google drive accout and this account is not mine but I have the access to go through it now because the internet problems and drive capacity I can not dounload the dataset then upload it to my drive ... so the question is: is there any way to let google colab get access to this dataset or such a way to import the path...

I have this function definition below

create_celebahq_cond_continuous('/content/drive/My Drive/kiki96/results/tfrecords','https://drive.google.com/open?id=0B7EVK8r0v71pWEZsZE9oNnFzTm8','https://drive.google.com/open?id=0B4qLcYyJmiz0TXY1NG02bzZVRGs',4,100,False)

where I have tried to put the sharablelink of the dataset but, it does not work

please help

like image 804
kikicoder Avatar asked Apr 05 '20 21:04

kikicoder


People also ask

How do I import a dataset into colab from Google Drive?

It is the easiest way to upload a CSV file in Colab. For this go to the dataset in your GitHub repository, and then click on “View Raw”. Copy the link to the raw dataset and pass it as a parameter to the read_csv() in pandas to get the dataframe.


2 Answers

To download a file to Colab

If you want to download the file directly into your Google Colab instance, then you can use gdown.

Note that the file must be shared to the public.

If the link to your dataset is https://drive.google.com/file/d/10vAwF6hFUjvw3pf6MmB_S0jZm9CLWbSx/view?usp=sharing, you can use:

!gdown --id "10vAwF6hFUjvw3pf6MmB_S0jZm9CLWbSx"


To download the file to your Drive

Instead, if you want to download it to your drive then

Mount your Google Drive

from google.colab import drive
drive.mount('/content/drive')

Change the directory to a folder in your Google Drive

cd '/content/drive/My Drive/datasets/'

Download the file into your Google Drive folder

!gdown --id "10vAwF6hFUjvw3pf6MmB_S0jZm9CLWbSx"


To download a folder

If you are trying to download a folder, follow these steps:

  1. Open the shared folder

Shared Folder

  1. Click "Add shortcut to my drive" and select a folder

Adding to drive

  1. Mount your Google Drive to Google Colab

  2. Go to the folder where you added the shortcut

Access to shared folder

You can see the newly-added folder, being referenced by its Google Drive folder ID.

like image 125
knoop Avatar answered Oct 22 '22 15:10

knoop


You can use the script here to download the whole folder.

https://github.com/segnolin/google-drive-folder-downloader

I've made it into an easy function.

def folder_download(folder_id):
  # authenticate
  from google.colab import auth
  auth.authenticate_user()
  # get folder_name
  from googleapiclient.discovery import build
  service = build('drive', 'v3')
  folder_name = service.files().get(fileId=folder_id).execute()['name']
  # import library and download
  !wget -qnc https://github.com/segnolin/google-drive-folder-downloader/raw/master/download.py
  from download import download_folder
  download_folder(service, folder_id, './', folder_name)
  return folder_name

You can simply call it with the folder_id.

folder_download('0B7EVK8r0v71pWEZsZE9oNnFzTm8')

And it will create that folder in Colab.

like image 2
korakot Avatar answered Oct 22 '22 16:10

korakot