Apply transforms.ToPILImage with nn.Sequential

Is there a way to apply transforms.ToPILImage with nn.Sequential e.g,

transforms_func = torch.nn.Sequential(*tranform_lst)

I wanna use a batch-wise transform in the training loop, and my inputs are torch tensors. hence there is a need to convert to PIL and back to tensor.


it looks like ToPILImage and ToTensor might not be necessary after all…

example from colourjitter, F.adjust_hue(img, hue_factor):

    if not isinstance(img, torch.Tensor):
        return F_pil.adjust_hue(img, hue_factor)

    return F_t.adjust_hue(img, hue_factor)

transforms functions are capable of working with both PIL and tensor types, and they do so inside transforms.functional.

I think we can safely remove transforms.ToPILImage() and transforms.ToTensor() in case batch of images are already in tensor format, and we can directly apply transforms.ToTensor() on them.