You can use the reduce=False option. This will make it so that you get a loss per pixel. You can do something like the following:
loss = nn.NLLLoss2d(reduce=False)
# x has size (N, C, 224, 224)
out = loss(x, t)
# out has size (N, 224, 224). Your weights have size (224, 224)
result = (out * weights).sum()