Counting Objects w/ Instance Segmentation

I was wondering if anyone knows how to count the number of objects by using instance segmentation. Can anyone direct me to example code?

I prefer to use instance segmentation over object detection simply because it’s easier and cleaner to label the data automatically with segmentation vs trying to draw a box around irregular shapes.

Thanks a bunch!