ValueError: Expect x to be a non-empty array or dataset (Tensor Flow lite model maker on Collab)

Mena picture Mena · Aug 3, 2020 · Viewed 8.1k times · Source

I am following this tutorial on creating a custom Model using TensorFlow lite Model Maker on Collab.

import pathlib
path = pathlib.Path('/content/employee_pics') 
count = len(list(path.glob('*/*.jpg')))
count

data = ImageClassifierDataLoader.from_folder(path)
train_data, test_data = data.split(0.5)

I have an issue with step 2:

model = image_classifier.create(train_data)

I get an error: ValueError: Expect x to be a non-empty array or dataset.

enter image description here

Am I doing something wrong? The data set provided in the example works fine though. Why?

Answer

Yuqi Li picture Yuqi Li · Aug 6, 2020

This Error is caused by the size of training data is smaller than batch_size which is not allowed.

The default batch_size is 32, which means the number of training images should be no less than 32. There's no need to count the number of images per label, just need to make sure that the total training images to be at least 32.

You need to choose one of the following solutions to solve it.

  • Set batch_size smaller than training data size, e.g:
image_classifier.create(train_data, batch_size=4)
  • Increase the size of training data by adding more data.