When I try to get targets from the train_ds, it receives zero. I think I got all the targets correctly in a previous way, and the only thing that I haven’t understood is the target of a batch of data, which is still imbalanced. For example, I changed the batch_size to 6, which is the number of my classes and passed it as the number of data into WeightedRandomSampler and after loading a batch of data I expected to have a target with one sample of each class but I got different:
weight = 1. / class_sample_count
samples_weight = weight[target]

sampler = WeightedRandomSampler(samples_weight, batch_size, replacement=True)

inputs, targets = next(iter(train_dl))     # Get a batch of training data
print(targets)

tensor([5, 3, 1, 4, 5, 5])