How to clean edges of Mask using opencv

Hello, I have a image and i need to create mask for every person

  1. I have used resnet50 to extract mask for every person in the original image
  2. For every mask i create a image

However, the edges of the mask needs to be filtered with proper algorithm. Refer the attached mask image



please do some research on this problem. then present your findings.