79806242

Date: 2025-10-31 22:24:27
Score: 0.5
Natty:
Report link

A solution to print images and labels even when the dataset is batched, "this case ". So here, the variable

imagexd and labelxd will pick a batch from the dataset as shown by test_ds.take(1). Now, to go to this selected batch, we will need a nested for loop, which will run up to the batch_size and print the respective image, along with its label on top.

####

plt.figure(figsize=(10, 10))
for (imagexd, labelxd) in (test_ds.take(1)):
  for i in range(batch_size):

    yea_image = imagexd[i].numpy().astype("int32")
    axd = plt.subplot(4,8, i+1)

    plt.imshow(yea_image)
    plt.axis("off")  
    plt.title(f"Label is {int(labelxd[i])}") 

####
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: kay_g