Importing Kaggle dataset into google colaboratory

While building a Deep Learning model, the first task is to import datasets online and this task proves to be very hectic sometimes.
We can easily import Kaggle datasets in just a few steps:
Code: Importing CIFAR 10 dataset

filter_none

edit
close

play_arrow

link
brightness_4
code

!pip install kaggle

chevron_right


Now go to your Kaggle account and create new API token from my account section, a kaggle.json file will be downloaded in your PC.
Code:

filter_none

edit
close

play_arrow

link
brightness_4
code

from google.colab import files
files.upload()

chevron_right


Code: Uploading the kaggle.json file

filter_none

edit
close

play_arrow

link
brightness_4
code

!mkdir -p ~/.kaggle
!cp kaggle.json ~/.kaggle/
!chmod 600 ~/.kaggle/kaggle.json

chevron_right


Copy the URL of your dataset and paste it in another cell.



Code: To unzip the uploaded dataset.

filter_none

edit
close

play_arrow

link
brightness_4
code

from zipfile import Zipfile
file_name=("cifar10-preprocessed.zip")
with Zipfile(file_name,'r') as zip:
             zip.extractall()
             print("done")

chevron_right


Code:

filter_none

edit
close

play_arrow

link
brightness_4
code

'./get_CIFAR-10.sh'
import tensorflow as tf
  
(x_train,y_train),(x_test,y_test) = tf.keras.cifar10.load_data()

chevron_right


Now your training and test set is ready to be used.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.