How to use resized_crop_mask?

Hi,
I want to randomly adding rectangle masks to image by using transform for data augmentation.
I found transform.v2 has resized_crop_mask. But I can’t upgrade my torchvision for some reason. I want directly implement the function. How can I do it? Thanks a lot!

def resized_crop_mask():
    ...
    return

class MyDataset(Dataset):
    def __init__(self, root_dir):
        super(MyDataset, self).__init__()
        self.transform = transforms.Compose(
            [transforms.ToPILImage(),
             transforms.RandomHorizontalFlip(),
             resized_crop_mask(),
             transforms.ToTensor(),
             transforms.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),
             ])
        self.root_dir = root_dir
        self.img...

    def __getitem__(self, index):
        sample = self.img[index]
        label...
        if self.transform is not None:
            sample = self.transform(sample)
        return sample, label

    def __len__(self):
        return len(self.img)

This is ChatGPT suggestion. But not sure if it is well coded.

The posted code does not show any implementation, but just a template how transformations are used in a custom Dataset.

You can reuse the torchvision implementation from here by copy/pasting all needed parts since you cannot update for some reason.