Closed neverland0621 closed 1 year ago
Hello, The output of the model can be converted to a heatmap by using matplotlib like this:
from matplotlib import cm plt.imshow(output , cmap = cm.jet )
This maps the raw [0,1] to H->[240, 0]. (H being hue from HSV).
PS. For your second doubt: The count values might vary a tiny bit due to the gaussian blur(this is because only an infinitely large kernel can approximate the gaussian blur accurately)
Thanks
@aditya-malte Thank you for your help! The problems have been solved.^_^
Can you tell me how to solve it?
@neverland0621 you're welcome
@wait1988 you could use the code I have shown in my previous comment
@aditya-malte Could you tell me more about the heatmap . I use firest test imagein shanghai tech dataset .The output (output.detach().cpu().numpy())'s size is 11264,but the input image size is 1024*704 ,I can't get a heatmap for each pix in the input image. Plz help me out.
Hi SJLNNU, I didn't understand what you mean to say exactly. Check my answers to say if they help. Regards, Aditya Malte
@aditya-malte Hi ,sorry for my statement . There is the thing : I Add "plt.imshow(output.detach().cpu().numpy() , cmap = cm.jet )” at the end of code just like you said . But it returns
Traceback (most recent call last):
File "G:/CrowdDetection/CSRNet-pytorch-master/val.py", line 64, in
The Size of 'output.detach().cpu().numpy()' is not enough to reshape into input image size. What should I do to out put the heat Image? Thank you for your time .
Hello SJLNNU, The problem appears to be from some other part of your code then, because I haven't faced such an issue.
Best, Aditya Malte
@SJLNNU, @aditya-malte I also encountered the same problem. I solved it. the output is a tensor, tensor and PIL can be converted。in the val.py add the following cod:
from torchvision import transforms
import matplotlib.pyplot as plt
loader = transforms.Compose([
transforms.ToTensor()])
unloader = transforms.ToPILImage()
def imshow(tensor, title=None):
image = tensor.cpu().clone() # we clone the tensor to not do changes on it
image = image.squeeze(0) # remove the fake batch dimension
image = unloader(image)
plt.imshow(image)
if title is not None:
plt.title(title)
plt.pause(0.001) # pause a bit so that plots are updated
Now use can use imshow like this:
imshow(output)
result:
And then,you can also save tensor or PIL to image by use torchvision.utils.save_image
reference: https://pytorch.org/docs/stable/torchvision/utils.html
@SJLNNU, @aditya-malte I also encountered the same problem. I solved it. the output is a tensor, tensor and PIL can be converted。in the val.py add the following cod:
from torchvision import transforms import matplotlib.pyplot as plt loader = transforms.Compose([ transforms.ToTensor()]) unloader = transforms.ToPILImage() def imshow(tensor, title=None): image = tensor.cpu().clone() # we clone the tensor to not do changes on it image = image.squeeze(0) # remove the fake batch dimension image = unloader(image) plt.imshow(image) if title is not None: plt.title(title) plt.pause(0.001) # pause a bit so that plots are updated
Now use can use imshow like this:
imshow(output)
result:And then,you can also save tensor or PIL to image by use
torchvision.utils.save_image
referencer: https://pytorch.org/docs/stable/torchvision/utils.html
Thanks men ,I solved too.
Hello, The output of the model can be converted to a heatmap by using matplotlib like this:
from matplotlib import cm plt.imshow(output , cmap = cm.jet )
This maps the raw [0,1] to H->[240, 0]. (H being hue from HSV).
PS. For your second doubt: The count values might vary a tiny bit due to the gaussian blur(this is because only an infinitely large kernel can approximate the gaussian blur accurately)
Thanks
Thank you so much for this help.
Thank you for releasing the code. I have some questions about the source code. 1.How to generate the density map from the output of model?I didn't get the desity map from the output of the model when i run the val.ipython but only the groudtruth of density map.or ,how to transform the output of the model to densoty map?
print mse
I will appreciate the help if anyone has idea of the problem, thank you!