'InvalidArgumentError: jpeg::Uncompress failed. Invalid JPEG data or crop window. [[{{node decode_image/DecodeImage}}]] [Op:IteratorGetNext]
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)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|