3

I'm trying to run the first guide from Tensorflow in Google Colab.

I import the dataset with

import pathlib

dataset_url = "https://storage.googleapis.com/download.tensorflow.org/example_images/flower_photos.tgz"
archive = tf.keras.utils.get_file(origin=dataset_url, extract=True)
data_dir = pathlib.Path(archive).with_suffix('')

However, when I run the following I get 0 images found

image_count = len(list(data_dir.glob('*/*.jpg')))
print(image_count)

When analyzing the routes and stuff I do this:

import os

print(data_dir)
print(archive)
os.listdir()

data dir says: /root/.keras/datasets/flower_photos

os.listdir(), on the other hand, says that I'm in the "content" folder. Which is in the same level as "root" folder.

Why aren't my images loading? Link to the notebook is here: https://colab.research.google.com/github/tensorflow/docs/blob/master/site/en/tutorials/load_data/images.ipynb

0

1 Answer 1

0

This tutorial is 5 years old and it seems it doesn't work as expected.

It seems it expects data in folder

/root/.keras/datasets/flower_photos/

but (using !ls -al /root/.keras/datasets/) I found it is in

/root/.keras/datasets/flower_photos.tgz/flower_photos/

So it needs

# data_dir = pathlib.Path(archive).with_suffix('')
data_dir = pathlib.Path(archive) / 'flower_photos'

After this change next lines work.


EDIT (2025.11.02):

It seems someone reported this problem half year ago. Maybe it will be fixed.

Fixing the dataset path for images.ipynb by kiransair · Pull Request #2361 · tensorflow/docs

In this issue I added link to this question - maybe this will help.

EDIT (2025.11.04):

It seems they finally changed this path on Google Colab.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.