-
Notifications
You must be signed in to change notification settings - Fork 283
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 convert the generated npy file into an image #110
Comments
For example: from torchvision.utils import save_image
import torch
import matplotlib.pyplot as plt
import numpy as np
import math
# load npy
logit = np.load(npy_filename)
C, H, W = logit.shape
# normalize
logit = torch.from_numpy(logit)[None] # (1,C,H,W) in [-inf,+inf]
prob = logit.softmax(dim=1)[0] # (C,H,W) in [0,1]
# save as images
for c in range(C):
save_image(prob[c], f"class_{c}.png")
# or visualize w/ matplotlib
n = math.ceil(C**0.5)
fig, ax = plt.subplots(nrows=n, ncols=n, constrained_layout=True)
ax = ax.flatten()
[a.axis("off") for a in ax]
for c in range(C):
ax[c].set_title(f"class {c}")
ax[c].imshow(prob[c])
plt.show() |
Thank you for your help. Actually, I want to ask how the images of dataset test to be submitted to PASCAL VOC's official website for testing were converted from npy to images. I have been puzzled for a long time and look forward to your reply. Thank you very much! |
thank you! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks you for your work.
How to convert the generated npy file into an image?
I look forward to your reply. Thank you.
The text was updated successfully, but these errors were encountered: