New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
where is the alpha mask in the png #286
Comments
The default behavior is just to overlay the mask on top of the original image. If you want to output and alpha channel as an image instead, that's a simple change. Just replace this block: Lines 189 to 209 in 13bb0c6
with if args.display_masks and cfg.eval_mask_branch and num_dets_to_consider > 0:
# After this, mask is of size [num_dets, h, w, 1]
masks = masks[:num_dets_to_consider, :, :, None]
img_gpu = (masks.sum(dim=0) >= 1).float().expand(-1, -1, 3).contiguous()
else:
img_gpu *= 0 and run evaluation with But I can do you one better! If you instead replace the block with if args.display_masks and cfg.eval_mask_branch and num_dets_to_consider > 0:
# After this, mask is of size [num_dets, h, w, 1]
masks = masks[:num_dets_to_consider, :, :, None]
img_gpu *= (masks.sum(dim=0) >= 1).float().expand(-1, -1, 3)
else:
img_gpu *= 0 everything will already be masked out for you. Though you probably also want a chroma key so actually that might not be very useful now that I think about it. Yeah it's prob better just to use the mask because you'd need both anyway :/ |
Hi, @dbolya thanks for the explanation. In addition to this, I am just trying to mask out all the single instances from the image individually, for example if there are multiple chairs or Tv eetc I will mask out all of them individually or if there are single one of them, I will do the same thing. Every saved image will include one masked object. But it is just doing it for just one object then only gives black frames. My modified version your above code is like this: if args.display_masks and cfg.eval_mask_branch and num_dets_to_consider > 0:
masks = masks[:num_dets_to_consider, :, :, None]
print('maskshape', (masks.shape))
for i in range(num_dets_to_consider):
msk = masks[i, :, :, None]
mask = msk.view(1, 968, 1296, 1)
print('newmaskshape', (mask.shape))
img_gpu *= (mask.sum(dim=0) >= 1).float().expand(-1, -1, 3)
img_numpy = (img_gpu * 255).byte().cpu().numpy()
cv2.imwrite('.../mask'+str(i)+'.jpg', img_numpy) Can you see where the problem is? |
@bayraktare That's because of To fix, just change these lines: img_gpu *= (mask.sum(dim=0) >= 1).float().expand(-1, -1, 3)
img_numpy = (img_gpu * 255).byte().cpu().numpy() to img_gpu_masked = img_gpu * (mask.sum(dim=0) >= 1).float().expand(-1, -1, 3)
img_numpy = (img_gpu_masked * 255).byte().cpu().numpy() Untested so let me know if it doesn't work. |
Yeah @dbolya that runs great. Thanks a lot.
|
Hi @dbolya, could you point out if I can only crop the bounding box? Thanks |
@bayraktare I would like to have the background in green color (greenscreen mimicking) instead of the black one, do you have any insight how can I do that ? |
Thanks it worked. Had to change
to
To make it work with any input size image |
I just modified the above code from 189 lines to 209 |
Sorry newbie question - I just assumed the saved png has the alpha mask in it (the a of 8 bit each rgba) and it can be accessed in other programs image processing ( photoshop, gimp. pillow) so for instance, in my case, I can set up a process with it to mask out the background and create a new image without the background. Yet when I inspect the outputed png I do not see a transparency 8 bit matte. How does one access the matte as an image file.
The text was updated successfully, but these errors were encountered: