[英]ValueError: Asked to retrieve element 0, but the Sequence has length 0 while trying to obtain image features using MobileNet
I wanted to use MobileNet to obtain features of all images present in a dataset.我想使用 MobileNet 获取数据集中所有图像的特征。 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:完整错误如下:
I wanted to obtain the image features and save it in a.npy file.我想获取图像特征并将其保存在.npy 文件中。 But this error keeps coming up.
但是这个错误不断出现。
"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.这通常是由于提供的路径存在问题,
flow_from_directory
静默失败。
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 .一种确认方法是@Idavid 在他们的评论中建议,但无论哪种方式,您都可以尝试此线程中建议的任何选项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.