Skip to content
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

how to test on a single image and get masks? #39

Closed
sporterman opened this issue May 13, 2019 · 8 comments
Closed

how to test on a single image and get masks? #39

sporterman opened this issue May 13, 2019 · 8 comments

Comments

@sporterman
Copy link

No description provided.

@dbolya
Copy link
Owner

dbolya commented May 13, 2019

From the readme:

python eval.py --trained_model=weights/yolact_base_54_800000.pth --score_threshold=0.3 --top_k=100 --image=my_image.png

Or do you want to export the masks as a numpy array or something?

@sporterman
Copy link
Author

@dbolya Thanks, i want to get person's masks in picture, numpy array format

@dbolya
Copy link
Owner

dbolya commented May 13, 2019

On this line:

yolact/eval.py

Line 150 in a70b68d

Add

np.save('masks.npy', masks.cpu().numpy())

The masks will be of size num_detections x im_h x im_w. If you want to export the class indices too, do the same with classes but don't include .cpu().numpy() (it's already a numpy array at that point; classes is a vector of size num_detections). Then use the above command and it'll call this function. If you don't want to still display the image, you can call exit() after you add that line.

If you want a cleaner solution, lmk. This is kind of hacky.

@sporterman
Copy link
Author

Much appreciate, Thasnks!

@majinshaoyuindustry
Copy link

On this line:

yolact/eval.py

Line 150 in a70b68d

Add

np.save('masks.npy', masks.cpu().numpy())

The masks will be of size num_detections x im_h x im_w. If you want to export the class indices too, do the same with classes but don't include .cpu().numpy() (it's already a numpy array at that point; classes is a vector of size num_detections). Then use the above command and it'll call this function. If you don't want to still display the image, you can call exit() after you add that line.

If you want a cleaner solution, lmk. This is kind of hacky.

Please provide a cleaner solution if possible. I am trying to streaming the mask (especially humans) into programs such as Touchdesigner and be able to manipulate that (ie. invisible shader in glsl). I tried the line of code above and use a simple function from pyplot to view it as image but failed:

import numpy as np
from matplotlib import pyplot as plt
img_array = np.load("masks.npy")
plt.imshow(img_array, cmap="gray")
plt.show()

TypeError: Invalid shape (1, 480, 640) for image data

Any suggestions please?

Thank you in advance!

@dbolya
Copy link
Owner

dbolya commented Feb 10, 2020

@majinshaoyuindustry matplotlib expects either a 2d image or a 3d image with channels at the end. In your case just use plt.imshow(img_array[0], cmap="gray") instead.

And yeah, I agree these hacks are not very pretty. We're working on a cleaner API (#323)

@majinshaoyuindustry
Copy link

@majinshaoyuindustry matplotlib expects either a 2d image or a 3d image with channels at the end. In your case just use plt.imshow(img_array[0], cmap="gray") instead.

And yeah, I agree these hacks are not very pretty. We're working on a cleaner API (#323)

Thanks that worked out pretty well. One more question: if I want to export this mask in real-time with a webcam, is there an easy way to create a buffer? Like it will only save 30frames in the folder with the later frames override the earlier ones.

@dbolya
Copy link
Owner

dbolya commented Feb 19, 2020

@majinshaoyuindustry The webcam part is already implement (see the Readme for how to run off a webcam), but you'll have to implement the frame buffer part yourself.

Here's where I save the frames:

yolact/eval.py

Line 739 in f54b0a5

out.write(frame_buffer.get())

So you can just replace that line with something special for your buffer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants