简体   繁体   English

ValueError:要求检索元素 0,但在尝试使用 MobileNet 获取图像特征时序列的长度为 0

[英]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.

相关问题 图像生成器错误:要求检索元素 0,但序列长度为 0 - Error in Image generator : Asked to retrieve element 0, but the Sequence has length 0 ValueError:尝试存储图像HoG功能时,使用序列设置数组元素 - ValueError: setting an array element with a sequence while trying to store image HoG features ValueError:字典更新序列元素#0的长度为1; 从文件读取时需要2 - ValueError: dictionary update sequence element #0 has length 1; 2 is required while reading from file 训练时出现此错误-ValueError:字典更新序列元素#0的长度为1; 2个为必填项 - Getting this error while training - ValueError: dictionary update sequence element #0 has length 1; 2 is required 值错误:字典更新序列元素 #6 的长度为 1; 2 是必需的 - ValueError: dictionary update sequence element #6 has length 1; 2 is required ValueError:字典更新序列元素#0的长度为4; 2是必需的(python) - ValueError: dictionary update sequence element #0 has length 4; 2 is required (python) 3 ValueError:字典更新序列元素#0的长度为3; 2个为必填项1 - 3 ValueError: dictionary update sequence element #0 has length 3; 2 is required 1 FLASK-ValueError:字典更新序列元素#0的长度为1; 2个为必填项 - FLASK - ValueError: dictionary update sequence element #0 has length 1; 2 is required 值错误:字典更新序列元素 #0 的长度为 28; 2 是必需的 - ValueError: dictionary update sequence element #0 has length 28; 2 is required 值错误:字典更新序列元素 #13 的长度为 1; 2 是必需的 - ValueError: dictionary update sequence element #13 has length 1; 2 is required
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM