@MariosOreo Thanks for your answer.
Yeah I saw that there is no way to get “target labels” inside transforms.Compose since the call to it includes “img” only. I was accessing MNIST dataset’s train_data and train_labels. I thought transforms would apply to them as well. My bad. I later found that they are applied only in data loaders.