L1 loss between a single image and batch of images

Hi,
I’m trying to assess which loss to use in some project and I need to calculate loss between a single image and batch of images.

So far this is what I have is this:

Which seems unnecessary since I don’t really need the same images to appear batch_num times.

Any other way? if i give only one image instead of copying it to be the same size? will by broadcasting it will achieve the same result?

You can use expand method to the single image. It points to the same mem adress than the original image.
https://pytorch.org/docs/stable/tensors.html#torch.Tensor.expand

Thank didn’t know that existed, good idea