How to create heatmap by given coordinates in mat file in pytorch

I am working on one network, for that the input is image and heatmap corresponding to 21 landmarks for face alignment. I want to preprocess the data. Could anyone suggest any method of how to generate heatmap from the given x,y coordinate in mat file in PyTorch.

Could you explain your use case a bit more?
Do you have heatmaps or coordinates stored in the mat file?
Would you like to create a model, which predicts one or the other and are stuck in creating the targets?

Hi @ptrblck,
I have coordinates in the mat file for the 21 landmarks for every image. The input to the network is an image(RGB) concatenated with heatmaps of these 21 landmarks. I am trying to train a network which will generate 68 landmarks using the above input.

Thanks for this information.
Since you have the landmarks, how would you like to create the heatmaps?
Do you want to plot these landmarks as single pixels into a single channel image and concatenate it with the input or are you thinking about another approach?

The landmarks as a single-pixel need to be plotted in 3 channels i.e RGB and concatenated with the image.

In that case, simple indexing should work fine:

N, H, W = 12, 10, 10
landmarks = torch.randint(0, H, (N, 2))

tmp = torch.zeros(N, 3, H, W)
rows, cols = landmarks.split(1, 1)
tmp[torch.arange(N), :, rows, cols] = 1.

image = torch.randn(N, 3, H, W)
image = torch.cat((image, tmp), 1)
print(image.shape)
> torch.Size([12, 6, 10, 10])
1 Like

Thanks @ptrblck. I’ll try this and update.