Skip to content

Instantly share code, notes, and snippets.

@akTwelve
Last active November 23, 2023 21:01
Show Gist options
  • Save akTwelve/dc79fc8b9ae66828e7c7f648049bc42d to your computer and use it in GitHub Desktop.
Save akTwelve/dc79fc8b9ae66828e7c7f648049bc42d to your computer and use it in GitHub Desktop.
COCO Image Viewer | immersivelimit.com/tutorials/create-coco-annotations-from-scratch
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@zeeshanalipanhwar
Copy link

zeeshanalipanhwar commented Dec 21, 2020

Hi @akTwelve, upon visualizing my own custom dataset I noticed that the masks of some instances did not get displayed while those of some did. This was due to segmentation_points being a numpy array, so sometimes the array when stringified looked like this '241, 5, 242, ..., 244, 5, 245]'. It can be avoided by adding:
segmentation_points = list (segmentation_points) after the following line of the function display_image in the notebook.
segmentation_points = np.multiply(segmentation_points, adjusted_ratio).astype(int).

@FreshlyBrewedCode
Copy link

Thanks for sharing!
I quickly added the option to visualize keypoints. I simply added the parameter in the display_image function:

def display_image(self, image_id, show_polys=True, show_bbox=True, show_crowds=True, show_keypoints=True, use_url=False):

and in the function body below the if show_bbox block I added:

if show_keypoints:
    for i, segm in enumerate(self.segmentations[image_id]):
        keypoints = segm.get('keypoints', None)
        if not keypoints is None:
            for k in range(0, segm.get('num_keypoints', 0)):
                x = keypoints[k * 3 + 0]
                y = keypoints[k * 3 + 1]
                visibility = keypoints[k * 3 + 2]
                html += '<circle cx="{}" cy="{}" r="3" fill="{}" />'.format(x, y, "red")

this will draw all keypoints using red svg circles, regardless of their visibility.

@alexeyev
Copy link

Thank you for sharing!

For photos with non-landscape orientation I had to add this to your code: https://stackoverflow.com/a/63798032/1616037

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment