1
$\begingroup$

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?

$\endgroup$
0
$\begingroup$

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')
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.