To extract validation labels from a batched dataset you can do this:
valid_labels = list(valid_ds.flat_map(lambda x, y: tf.data.Dataset.from_tensor_slices((x, y))).as_numpy_iterator())
valid_labels = [y for x, y in valid_labels]
Probably, there is some easier way to do it. But now I can’t think of anything else.
Then you get predicted values from the model:
pred_labels = model.predict(valid_ds)
And use this to get a confusion matrix:
conf_m = tf.math.confusion_matrix(valid_labels, pred_labels)