How do i load images dataset using tf.keras.utils.get_file

I;m working with cifar-10 dataset and i need the dataset available publicly, so i pushed it to gitlab. i want to load this dataset in my code, after some digging i found an example where they used tf.keras.utils.get_file() which looked perfect but when i try to load my dataset i get a NotADirectoryError. but it loads just fine with the example i found online which is confusing, can someone please explain why it wouldn't work for my dataset?

here's the example i found that works, the is_dir() returns true

import pathlib data_root_orig = tf.keras.utils.get_file( 'flower_photos',') data_root = pathlib.Path(data_root_orig) print(data_root.is_dir() ) 

here's my dataset I'm trying to load. Initially throws train_data is not a directory, when i try again it seems to work but is_dir is false and i'm unable to get to the files in my dataset

import pathlib import tensorflow as tf data_root_orig = tf.keras.utils.get_file('train', ' untar=True, archive_format='zip') data_root = pathlib.Path(data_root_orig) print(data_root, type(data_root),data_root.is_dir()) 

3 Answers

# download IMDb movie review dataset import tensorflow as tf dataset = tf.keras.utils.get_file( fname="aclImdb.tar.gz", origin="", extract=True, ) 

//reference:

import tensorflow as tf import pathlib url = ' data_dir = tf.keras.utils.get_file('dataset', url, extract=True) # if url = ' => untar=True data_dir = pathlib.Path(data_dir) image_count = len(list(data_dir.glob('*/*.jpg'))) 

for tensorflow 2 you may find dataset directly in ~/.keras/datasets and use it as you want to

doc tf.keras.utils.get_file

I had the same problem, and I had to take other a slightly different path, you can do as I did and see if it serves you well.. So I uploaded the .zip file in my Google Drive account, mounted it to Colab, and then i used patoolib.extract_archive(zip_file_path, outdir='destination_folder') and continued coding using the images from the destination_folder .. of course you're gonna need to install the library using !pip install patool and then import it using import patoolib.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like