@christopherkuemmel I tried your method and it worked but turned out the number of input images is not fixed in each training example.
For example, the first training triplet could have (3 imgs, 1 positive imgs, 2 negative imgs) and the second would have (4 imgs, 1 positive imgs, 4 negative imgs). This raise an RuntimeError: RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0. Got 3 and 4 in dimension 1 at /pytorch/aten/src/TH/generic/THTensor.cpp:689 and they say the only solution  is to have batchsize=1.
So I think I would stick with batchsize=1 for now. Thank for your help anyway