1

I wanted to use MobileNet to obtain features of all images present in a dataset. But the error mentioned keeps popping up.

The full code that produced the error is:

`

from keras.applications import MobileNet
from keras.preprocessing.image import ImageDataGenerator
from keras.models import Model
from keras.applications.mobilenet import preprocess_input

# Load the MobileNet model
base_model = MobileNet(weights='imagenet', include_top=False)

# Define the data generator
data_generator = ImageDataGenerator(preprocessing_function=preprocess_input)

# Create the data generator for the custom dataset
image_generator = data_generator.flow_from_directory(
        'C:/Users/mahit/OneDrive/Pictures/Desktop/DATA AND VIDEOS//16k_images',
        target_size=(224, 224),
        batch_size=1,
        class_mode=None,
        shuffle=False)

# Obtain the image features
image_features = base_model.predict(image_generator, 16042)

# Save the image features to a file
np.save('mobilenet_image_features.npy', image_features)

`

The full error is as follows:

enter image description here

I wanted to obtain the image features and save it in a .npy file. But this error keeps coming up.

MAHITHA POTTI
  • 86
  • 1
  • 4
  • Go to the terminal, run `DIR "C:/Users/mahit/OneDrive/Pictures/Desktop/DATA AND VIDEOS//16k_images"` and see if you get a list of images. I have the feeling that the forward slashes (and maybe the double slash in `VIDEOS//16k_images`) are causing the issue. – ldavid Jan 23 '23 at 05:37

1 Answers1

0

"Sequence has length zero" indicates that there is no data provided by the data loader. This is usually due to issues with the provided path, for which flow_from_directory fails silently.

One way to confirm is as @Idavid suggested in their comment, but either way you can try any of the options suggested in this thread.

Ophir S
  • 395
  • 5
  • 13