When run code, I get error:
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (63,) + inhomogeneous part.
train = img_Datagen.flow_from_directory(train_dir,
batch_size = 16,
class_mode = 'binary',
target_size = (IMG_HEIGHT, IMG_WIDTH)
)
validation = val_Datagen.flow_from_directory(val_dir,
batch_size = 2,
class_mode = 'binary',
target_size = (IMG_HEIGHT, IMG_WIDTH)
)
history = model.fit(train, epochs = 2,
validation_data = validation,
steps_per_epoch = 63,
callbacks = [lr],
batch_size = 16)
# save best checkpoint as hdf5
model.save('/tmp/best_model3_1.hdf5')
# load the best model
best_model3_1 = tf.keras.models.load_model('/tmp/best_model3_1.hdf5')
# calculate test accuracy using the best model
loss, acc = best_model3_1.evaluate_generator(test)
print("\nTest Loss: {:.2f}".format(loss))
print("Test Accuracy: {:.2f}".format(acc))
print(len(actual_labels))
63
print(len(predicted_labels))
63
actual_labels, predicted_labels = [], []
for _ in range(len(test)):
test_images, test_labels = next(test)
actual_labels.append(test_labels)
predicted_labels.append(best_model3_1.predict(test_images).ravel())
actual_labels = np.array(actual_labels, dtype = float).ravel()
predicted_labels = np.array(predicted_labels, dtype = float).ravel()
Error:
5 predicted_labels.append(best_model3_1.predict(test_images).ravel())
6
----> 7 actual_labels = np.array(actual_labels, dtype = float).ravel()
8 predicted_labels = np.array(predicted_labels, dtype = float).ravel()
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (63,) + inhomogeneous part.
Why do I get this error message? ValueError: setting an array element with a sequence.
I shoud be fix ????
Thank you.