How to Download Kaggle Datasets Directly to Google Drive Using Google Colab
First, create a Kaggle_Datasets
folder in Google Drive.
Next, open Google Colab and enter the following code in the first cell:
!pip install opendatasets
Run the cell.
In the next cell, enter the following code:
dont forgot to change the datasets url in code
import shutil
import opendatasets as od
import os
from google.colab import drive
# Mount Google Drive
drive.mount(‘/content/drive’)
# Define the output directory in Google Drive where the dataset will be downloaded
output_dir = ‘/content/drive/MyDrive/Kaggle_Datasets’
# Define the name of the new folder to be created inside the output directory
new_folder_name = ‘Embryo_Classification’ # Replace with your folder name
# Create the new folder if it doesn’t exist
new_folder_path = os.path.join(output_dir, new_folder_name)
os.makedirs(new_folder_path, exist_ok=True)
# Define the Kaggle dataset URL
dataset_url = ‘https://www.kaggle.com/datasets/gauravduttakiit/embryo-classification-efficientnet/data' #replace with the datasets link you want to download
# Download the dataset to the specified directory in Google Drive
od.download(dataset_url, data_dir=new_folder_path)
# Move the downloaded zip file to the new folder
zip_file_name = ‘embryo-classification-efficientnet.zip’ # Replace with your folder name
zip_file_path = os.path.join(output_dir, zip_file_name)
shutil.move(zip_file_path, new_folder_path)
Run this cell. It will ask for your username and API key.
For obtaining the API key, check out this tutorial:
https://christianjmills.com/posts/kaggle-obtain-api-key-tutorial/
After entering your credentials, the dataset will be downloaded as both a zip folder and an unzipped folder in the Kaggle_Datasets
folder in Google Drive.