Skip to content

Instantly share code, notes, and snippets.

@rekalantar
Created May 30, 2023 10:21
Show Gist options
  • Select an option

  • Save rekalantar/37f9380ec44cc27f63ba17967bd8769b to your computer and use it in GitHub Desktop.

Select an option

Save rekalantar/37f9380ec44cc27f63ba17967bd8769b to your computer and use it in GitHub Desktop.
example = train_dataset[50]
for k,v in example.items():
print(k,v.shape)
xmin, ymin, xmax, ymax = get_bounding_box(example['ground_truth_mask'])
fig, axs = plt.subplots(1, 2)
axs[0].imshow(example['pixel_values'][1], cmap='gray')
axs[0].axis('off')
axs[1].imshow(example['ground_truth_mask'], cmap='copper')
# create a Rectangle patch for the bounding box
rect = patches.Rectangle((xmin, ymin), xmax-xmin, ymax-ymin, linewidth=1, edgecolor='r', facecolor='none')
# add the patch to the second Axes
axs[1].add_patch(rect)
axs[1].axis('off')
plt.tight_layout()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment