0

I am trying to create image classification model using tensorflow lite for android app here: https://www.tensorflow.org/tutorials/images/classification However, I am using my local directory.

Here is my code:

import matplotlib.pyplot as plt
import numpy as np
import os
import PIL
import tensorflow as tf

from tensorflow import keras
from tensorflow.keras import layers
from tensorflow.keras.models import Sequential

import pathlib
data_dir = pathlib.Path('C:/Users/aalroumi/Documents/MLKIT/V')

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

and here is an image of the output:

![][1]

and this is the image of my local directory:

So why am I getting image size is zero?

Am I missing something? I did everything right.

Because I am trying to files.download('model.tflite')

Image size is zero error:

Thank you

Abdulmajeed
  • 1,502
  • 2
  • 10
  • 13
  • Your glob pattern has a slash in it, implying the images should be in subdirectories, but it appears that they are not. Could that be it? – David Conrad Nov 13 '21 at 22:52
  • That is actually true. It shows the number of images but again when I am loading, why does it show image size is zero? if you see I edit my reply and it shows the error in the image. Thank you for the help though for the previous enquiry. – Abdulmajeed Nov 13 '21 at 23:06
  • always put code, data and full error message as text (not screenshot, not link) in question (not in comment). – furas Nov 14 '21 at 00:41
  • first you should check in documentation `from_folder` - maybe it loads only `.jpg` but you have `.JPEG`. OR maybe it needs special package with images and labels. – furas Nov 14 '21 at 00:43
  • based on source code `from_folder(data_dir)` needs images in subfolders which are used as labels - `data_dir/label1/*.jpeg`, etc, `data_dir/label2/*.jpeg` – furas Nov 14 '21 at 00:50

1 Answers1

1

It seems you have images directly in data_dir so you should use *.JPEG to get them in glob()


But from_folder(data_dir) expects images in subfolders which names will be used as labels for images.

ie.

data_dir/cat/small_cat.JPEG
data_dir/cat/big_cat.JPEG
# ...
data_dir/dog/white_dog.JPEG
data_dir/dog/black_dog.JPEG

but you don't have subfolders so it can't find images in subfolders.
It doesn't count images directly in data_dir

furas
  • 134,197
  • 12
  • 106
  • 148