@M_S  would suggest instead of using the torch.utils for transforms, you can design your own utils.py with self designed transformations. You can import it and use it accordingly and should be able to help you out with you problem, ill add a link as an example -

  
      github.com
  
  
    kuangliu/pytorch-retinanet/blob/master/transform.py 22
'''Perform transforms on both PIL image and object boxes.'''
import math
import random

import torch
import torchvision.transforms as transforms

from PIL import Image, ImageDraw


def resize(img, boxes, size, max_size=1000):
    '''Resize the input PIL image to the given size.

    Args:
      img: (PIL.Image) image to be resized.
      boxes: (tensor) object boxes, sized [#ojb,4].
      size: (tuple or int)
        - if is tuple, resize image to the size.
        - if is int, resize the shorter side to the size while maintaining the aspect ratio.
      max_size: (int) when size is int, limit the image longer size to max_size.


  This file has been truncated. show original

  
  
    
    
  
  


Give it a look, Using your own file gives you more freedom to mess around with things.