InvalidArgumentError:jpeg::解压缩失败。 JPEG 数据或裁剪窗口无效。 [[{{节点decode_image/DecodeImage}}]] [Op:IteratorGetNext]

发布于 2025-01-17 05:03:21 字数 2377 浏览 1 评论 0原文

嗨,我收到错误

InvalidArgumentError:jpeg::解压缩失败。无效的 JPEG 数据或 裁剪窗口。 [[{{节点解码图像/解码图像}}]] [操作:IteratorGetNext]

运行下面的代码后。该错误来自行

for image_batch, label_batch in test_dataset

我可以知道为什么会出现此错误吗?谢谢

BATCH_SIZE = 32
IMG_SIZE = (224, 224)

train_dataset = image_dataset_from_directory(data_dir,
                                              shuffle=True,
                                              label_mode = 'categorical',
                                              validation_split = 0.2,
                                              batch_size=BATCH_SIZE,
                                              seed = 42,
                                              subset = "training",
                                              image_size=IMG_SIZE
                                             )

validation_dataset = image_dataset_from_directory(data_dir,
                                              shuffle=True,
                                              label_mode = 'categorical',
                                              validation_split = 0.2,
                                              batch_size=BATCH_SIZE,
                                              seed = 42,
                                              subset = "validation",
                                              image_size=IMG_SIZE
                                             )

train_size = int(0.8 * len(train_dataset))
test_dataset = train_dataset.skip(train_size)    

y_pred_species = []  # store predicted labels
y_pred_diseases = []
y_true = []  # store true labels
    
# iterate over the dataset
for image_batch, label_batch in test_dataset:   # use dataset.unbatch() with repeat
    # append true labels
    y_true.append(label_batch)
    # compute predictions
    preds = model.predict(image_batch)
    # append predicted labels
    y_pred_species.append(np.argmax(preds[0], axis = - 1))
    y_pred_diseases.append(np.argmax(preds[1], axis = - 1))
    
# convert the true and predicted labels into tensors
correct_labels = tf.concat([item for item in y_true], axis = 0)
correct_labels = np.argmax(correct_labels, axis=1)
predicted_species_labels = tf.concat([item for item in y_pred_species], axis = 0)
predicted_diseases_labels = tf.concat([item for item in y_pred_diseases], axis = 0)

Hi I am getting the error

InvalidArgumentError: jpeg::Uncompress failed. Invalid JPEG data or
crop window. [[{{node decode_image/DecodeImage}}]]
[Op:IteratorGetNext]

after running the code below. The error is coming from the line,

for image_batch, label_batch in test_dataset

May I know why does this error appear? thanks

BATCH_SIZE = 32
IMG_SIZE = (224, 224)

train_dataset = image_dataset_from_directory(data_dir,
                                              shuffle=True,
                                              label_mode = 'categorical',
                                              validation_split = 0.2,
                                              batch_size=BATCH_SIZE,
                                              seed = 42,
                                              subset = "training",
                                              image_size=IMG_SIZE
                                             )

validation_dataset = image_dataset_from_directory(data_dir,
                                              shuffle=True,
                                              label_mode = 'categorical',
                                              validation_split = 0.2,
                                              batch_size=BATCH_SIZE,
                                              seed = 42,
                                              subset = "validation",
                                              image_size=IMG_SIZE
                                             )

train_size = int(0.8 * len(train_dataset))
test_dataset = train_dataset.skip(train_size)    

y_pred_species = []  # store predicted labels
y_pred_diseases = []
y_true = []  # store true labels
    
# iterate over the dataset
for image_batch, label_batch in test_dataset:   # use dataset.unbatch() with repeat
    # append true labels
    y_true.append(label_batch)
    # compute predictions
    preds = model.predict(image_batch)
    # append predicted labels
    y_pred_species.append(np.argmax(preds[0], axis = - 1))
    y_pred_diseases.append(np.argmax(preds[1], axis = - 1))
    
# convert the true and predicted labels into tensors
correct_labels = tf.concat([item for item in y_true], axis = 0)
correct_labels = np.argmax(correct_labels, axis=1)
predicted_species_labels = tf.concat([item for item in y_pred_species], axis = 0)
predicted_diseases_labels = tf.concat([item for item in y_pred_diseases], axis = 0)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文