yolact icon indicating copy to clipboard operation
yolact copied to clipboard

How to get mask?

Open Wickked-swag opened this issue 3 years ago • 21 comments

I just want to get the pic of mask.Just like a pic that the foreground is black and the background is white.Can anybody tell me how to do it?Thanks very much!

Wickked-swag avatar May 08 '21 04:05 Wickked-swag

https://github.com/dbolya/yolact/blob/57b8f2d95e62e2e649b382f516ab41f949b57239/eval.py#L159 You can export mask from here (It's already in numpy array). For example, you can do like the following: np.save('mask_data', masks.cpu().numpy())

kidpaul94 avatar May 16 '21 01:05 kidpaul94

@kidpaul94 Thanks! Do you know that how to convert numpy of mask_data to segmentation data([x, y, x, y, x, y ...])?

7eta avatar Jun 04 '21 04:06 7eta

numpy of mask has 3-dimension (instance, x, y). So, if you want to pull out 1st instance, for example:

mask = np.load('./mask_data.npy') solutions = np.argwhere(mask[0] != 0)

This will give you the segmentation data.

kidpaul94 avatar Jun 04 '21 17:06 kidpaul94

@kidpaul94 Thanks!!, I will try soon.

7eta avatar Jun 06 '21 23:06 7eta

@kidpaul94 I tried and it gave me an npy file like it was supposed too. So I'm running a whole folder of images and my ultimate gola is to get the segmentation masks in a png format so that I can compare with the background truth ones. Do you know how to do it?

I'm not exactly sure what you mean by "background truth". Are you talking about image input without any mask?

kidpaul94 avatar Aug 08 '21 19:08 kidpaul94

I'm sorry @kidpaul94 I'll try to explain it better. So my goal is to compare a png segmentation mask obtained by the output of yolact with the ground truth mask (we can call it the correct segmentation mask) that I used to make the coco annotations. I want to compare them to compute metrics like IoU etc.

So I'm testing yolact in a folder of 200 images and I'm getting the segmentation results like this Captura de ecrã 2021-08-09, às 01 58 25

But I would like to get them like this

Image01921_boat_0

The npy file contains pixel locations of the object you detected in 640x480 image. Can't you just generate 640x480 black background and convert the pixels corresponding to the npy file into white to get the specific format?

kidpaul94 avatar Aug 09 '21 23:08 kidpaul94

I'm sorry @kidpaul94 I'll try to explain it better. So my goal is to compare a png segmentation mask obtained by the output of yolact with the ground truth mask (we can call it the correct segmentation mask) that I used to make the coco annotations. I want to compare them to compute metrics like IoU etc.

So I'm testing yolact in a folder of 200 images and I'm getting the segmentation results like this Captura de ecrã 2021-08-09, às 01 58 25

But I would like to get them like this

Image01921_boat_0

Hi Miguel, First of all many thanks to you and kidpaul94, i found your comments useful. I'm trying to do something which I believe is similar to what you are suggesting: detect objects and extract them to a white background using the mask. Did you manage to do what you were trying to do? Best Regards

thierrydecae avatar Sep 23 '21 22:09 thierrydecae

I'm sorry @kidpaul94 I'll try to explain it better. So my goal is to compare a png segmentation mask obtained by the output of yolact with the ground truth mask (we can call it the correct segmentation mask) that I used to make the coco annotations. I want to compare them to compute metrics like IoU etc. So I'm testing yolact in a folder of 200 images and I'm getting the segmentation results like this Captura de ecrã 2021-08-09, às 01 58 25 But I would like to get them like this Image01921_boat_0

Hi Miguel, First of all many thanks to you and kidpaul94, i found your comments useful. I'm trying to do something which I believe is similar to what you are suggesting: detect objects and extract them to a white background using the mask. Did you manage to do what you were trying to do? Best Regards

Yes I'm able, do you still need it?

can you post your solution @MiguelAngeloMartinsRibeiro ?

for me commenting out image loading into GPU, and instead initializing empty images gives colored masks output without original background image.

if undo_transform:
        img_numpy = undo_image_transformation(img, w, h)
        #img_gpu = torch.Tensor(img_numpy).cuda()
        img_gpu = torch.zeros(img.shape).cuda()  # initializing background as black
else:
        #img_gpu = img / 255.0
        img_gpu = torch.zeros(img.shape).cuda()  # initializing background as black
        h, w, _ = img.shape

bharathraja avatar Mar 24 '22 11:03 bharathraja

@bharathraja I use a modified eval.py script that I found somewhere, don't really know where anymore

https://github.com/MiguelAngeloMartinsRibeiro/YolactMiguel but you can find it here

I'm sorry @kidpaul94 I'll try to explain it better. So my goal is to compare a png segmentation mask obtained by the output of yolact with the ground truth mask (we can call it the correct segmentation mask) that I used to make the coco annotations. I want to compare them to compute metrics like IoU etc.

So I'm testing yolact in a folder of 200 images and I'm getting the segmentation results like this Captura de ecrã 2021-08-09, às 01 58 25

But I would like to get them like this

Image01921_boat_0

Hello,Miguel! I'm trying to do something which is similar to what you are suggesting. May I refer to your solution,I'll appreciate your help very much!

zzl-gray avatar Apr 28 '22 15:04 zzl-gray

I'm sorry @kidpaul94 I'll try to explain it better. So my goal is to compare a png segmentation mask obtained by the output of yolact with the ground truth mask (we can call it the correct segmentation mask) that I used to make the coco annotations. I want to compare them to compute metrics like IoU etc. So I'm testing yolact in a folder of 200 images and I'm getting the segmentation results like this Captura de ecrã 2021-08-09, às 01 58 25 But I would like to get them like this Image01921_boat_0

Hello,Miguel! I'm trying to do something which is similar to what you are suggesting. May I refer to your solution,I'll appreciate your help very much!

My solution is in the GitHub link above your answer

With that new eval.py you just need to run it as dbolya says (https://github.com/MiguelAngeloMartinsRibeiro/YolactMiguel)

python eval.py --trained_model=weights/yolact_base_54_800000.pth --score_threshold=0.15 --top_k=15 --images=path/to/input/folder:path/to/output/folder

and you'll get a folder with the masks

From there you just need to compute the IoU by comparing the masks with the GT

Good luck @zzl-gray

I'm sorry @kidpaul94 I'll try to explain it better. So my goal is to compare a png segmentation mask obtained by the output of yolact with the ground truth mask (we can call it the correct segmentation mask) that I used to make the coco annotations. I want to compare them to compute metrics like IoU etc. So I'm testing yolact in a folder of 200 images and I'm getting the segmentation results like this Captura de ecrã 2021-08-09, às 01 58 25 But I would like to get them like this Image01921_boat_0

Hello,Miguel! I'm trying to do something which is similar to what you are suggesting. May I refer to your solution,I'll appreciate your help very much!

My solution is in the GitHub link above your answer

I want to output the segmentation area of the image person is white, and other classifications are black, how to do it.

wafaer avatar Aug 08 '22 02:08 wafaer

@MiguelAngeloMartinsRibeiro is it possible to get each mask separately of the detected object with the original image size? I am trying to extract each object's length, width, and mask area. If I get each mask with color or binary image, I can pull that data.

hafizur-r avatar Sep 23 '22 14:09 hafizur-r

@MiguelAngeloMartinsRibeiro, your solution link is not activated any more. Can you please share your solution again? TIA

hafizur-r avatar Sep 25 '22 04:09 hafizur-r

@MiguelAngeloMartinsRibeiro, your solution link is not activated any more. Can you please share your solution again? TIA

@hafizur-r https://github.com/MiguelAngeloMartinsRibeiro/Real-Time-Ship-Instance-Segmentation-with-3D-fully-connected-CRF-for-Maritime-Surveillance/blob/main/Yolact%2B%2B/eval_images_yolact.py see if this one is working

@MiguelAngeloMartinsRibeiro Thank you! I got it from another post.

hafizur-r avatar Sep 26 '22 14:09 hafizur-r

@MiguelAngeloMartinsRibeiro,您的解决方案链接不再激活。你能再分享一下你的解决方案吗?TIA

@hafizur-r https://github.com/MiguelAngeloMartinsRibeiro/Real-Time-Ship-Instance-Segmentation-with-3D-fully-connected-CRF-for-Maritime-Surveillance/blob/main/Yolact%2B%2B/eval_images_yolact.py参见如果这个有效

hi, i try to get the mask with this new eval.py but i can't get anything after ran it. if anyone has the same problem? or if there is ant other ways to get the mask

BinZhou-23 avatar Mar 26 '23 14:03 BinZhou-23