Sorry, I found this code online for DiceLoss and wanted to use it in my code, below is the full code for DiceLoss:
    def forward(self, input, target):
        weights = 1
        encoded_target = input.data.clone().zero_()
        encoded_target.scatter_(1, target.unsqueeze(1), 1)
        # encoded_target = Variable(encoded_target)
        assert input.size() == encoded_target.size(), "Input sizes must be equal."
        assert input.dim() == 5, "Input must be a 4D Tensor."
        num = (input * encoded_target).sum(dim=4).sum(dim=3).sum(dim=2)
        den1 = input.pow(2).sum(dim=4).sum(dim=3).sum(dim=2)
        den2 = encoded_target.pow(2).sum(dim=4).sum(dim=3).sum(dim=2)
        dice = (2 * num / (den1 + den2)) * weights
        return ((1-dice.sum()) / dice.size(1)) / 5

I want to create a target tensor to calculate the loss against. Thats why I thought if I create it in the same was as in my second post will it be the same thing as scatter?
I assume scatter here is trying to do the same thing…