How can I load file from my local drive in keras using get_file?

I am using google colab and I need to load data from my local drive. How I can do that using get_file? what should be the origin?

Topic keras tensorflow

Category Data Science


get_file() is used for loading files from a URL,hence it can not load local files. If you have mounted you gdrive and can access you files stored in drive through colab, you can access the files using the path '/gdrive/My Drive/your_file'. for eg:

base_dir ='/gdrive/My Drive/weld_data'   

train_generator = datagen.flow_from_directory(
base_dir,
target_size=(IMAGE_SIZE, IMAGE_SIZE),
batch_size=BATCH_SIZE, 
subset='training')

If you need to unzip the file, you can use import zipfile with zipfile.ZipFile(your_file, 'r') as zip_ref: zip_ref.extractall(directory_to_extract_to)

I used '/content' as the directory_to_extract_to.

Then you can access the data the usual way.

base_dir = '/content/my_folder'    

train_generator = datagen.flow_from_directory(
base_dir,
target_size=(IMAGE_SIZE, IMAGE_SIZE),
batch_size=BATCH_SIZE, 
subset='training')

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.