ValueError: Image size is zero in Google Colab

Question:

I’m learning ML model training following this tutorial from Tensorflow. I have uploaded my own dataset from my computer to a folder named "sample_arrow" in Google Colab and specified the path to it:

image_path = 'sample_arrow'

The folder contains images, the size is not 0. But I get an error when executing this line of code:

data = DataLoader.from_folder(image_path) train_data, test_data = data.split(0.9)

ValueError: Image size is zero

enter image description here

What is wrong here? Maybe the folder path is not specified correctly? I’m completely new to the topic, unfamiliar with Pyhon (have Java skills) and would appreciate a detailed answer.

Asked By: prosp

||

Answers:

At last, I’ve found the solution.
Import os and the correct path definition were missing:

import os


root_path = "/content/"    
image_path = os.path.join(os.path.dirname(root_path), 'sample_arrow')

enter image description here

Answered By: prosp

Use the following code in google colab:

import tensorflow as tf

data_path = tf.keras.utils.get_file(
      'flower_photos',
      'https://storage.googleapis.com/download.tensorflow.org/example_images/flower_photos.tgz',
      untar=True)


from tflite_model_maker import image_classifier
from tflite_model_maker.image_classifier import DataLoader

# Load input data specific to an on-device ML app.
data = DataLoader.from_folder(data_path)
train_data, test_data = data.split(0.9)

# Customize the TensorFlow model.
model = image_classifier.create(train_data)

# Evaluate the model.
loss, accuracy = model.evaluate(test_data)

# Export to Tensorflow Lite model and label file in `export_dir`.
model.export(export_dir='/tmp/')

So you need to download the data! took me a while to find the solution!!

Answered By: Mohammad H. Rafiei