Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
630 views
in Technique[技术] by (71.8m points)

tensorflow - Loading Images out of .zip files from google drive into google colab

With the code snippet in google colab below, I'm able to read the jpg images from tar-file "flower_photos.tgz in my google drive through URL "https://storage.googleapis.com/download.tensorflow.org/example_images/flower_photos.tgz"

import tensorflow as tf
import IPython.display as display
from PIL import Image 
import pathlib
dataset_url = https://storage.googleapis.com/download.tensorflow.org/example_images/flower_photos.tgz"
data_dir = tf.keras.utils.get_file(origin=dataset_url, 
                                                         fname='flower_photos', 
                                                           untar=True)
data_dir = pathlib.Path(data_dir)***

With the code snippet below I was able to display the jpg-Images in folder

roses = list(data_dir.glob('roses/*'))
for image_path in roses[:1]: 
       print(image_path)
       display.display(Image.open(str(image_path)))

The .tar file contains the following folders:

  1. Level: Folder sunflower
  2. Level: Folder daisy, folder roses … Each folder contains some jpg-images

I want to do the same with the .zip file ?Santana.zip‘ file from my google drive. I copied the following link to the .zip file ?Santana.zip‘ in my google drive: https://drive.google.com/file/d/1ommgi8hPEqwwWGhhAGIIBmXv7rLJXSE4/

The structure of this .zip file is the following:

1.Level Folder Santana

2.Level Folder Santana1 and Santana2

Each Folder contains some .jpg files

I’ve tried to read the images with the code snippet in google colab below:

import tensorflow as tf
import IPython.display as display
from PIL import Image 
import pathlib

import tensorflow as tf
import IPython.display as display
from PIL import Image 
import pathlib

dataset_url = "https://drive.google.com/file/d/1ommgi8hPEqwwWGhhAGIIBmXv7rLJXSE4/"

data_dir = tf.keras.utils.get_file(origin=dataset_url, 
                                   fname='Santana',
                                   extract=True)
data_dir = pathlib.Path(data_dir)
Santana1 = list(data_dir.glob('Santana1/*'))
for image_path in Santana1[:1]: 
    display.display(Image.open(str(image_path)))
    print(image_path)

But the images in folder Santana1 aren’t displayed.

Does anyone know what’s wrong?

question from:https://stackoverflow.com/questions/65909156/loading-images-out-of-zip-files-from-google-drive-into-google-colab

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...