A problem in transform compose

Hi,
I want to add the adjust_brightness function to my transform.Compose,but that function has a integrant parameter img so that i can only apply this to my loop. Is there any methods to make it a compatible part in transform.Compose for other similar datasets? I’m a beginner in pytorch.
Thanks in advance!


import matplotlib.pyplot as plt
import numpy as np
import torch
torch.manual_seed(60)
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
import torchvision
from torchvision import datasets, transforms
batchSize=1
transform = transforms.Compose([transforms.ToTensor(),
                                transforms.Normalize([0.5],[0.5])])
#Load the training data
trainset = datasets.FashionMNIST(root='./data', train=False,
                                       download=True, transform=transform)
trainloader = torch.utils.data.DataLoader(trainset, batch_size=batchSize,
                                          shuffle=True, num_workers=0)
def imshow(img):
    img = img / 2 + 0.5     # unnormalize back to range [0, 1]
    npimg = img.numpy()
    plt.imshow(np.transpose(npimg, (1, 2, 0))) #rearrange dimensions to numpy format for disply
    plt.show()
for images, labels in trainloader:  # only take first element of dataset
    if labels==torch.tensor([9]):
        images = transforms.functional.adjust_brightness(img = images,brightness_factor = 100)
        imshow(torchvision.utils.make_grid(images))
        

You could use transforms.Lambda and pass the method (via a partial) to it or write a custom transformation class and use it in the transforms.Compose.