Hello,
I’m currently trying to implement a weighted batch process in py torch. I never had any problem when using normal DataLoader. When I try to do that with a randomWeightSampler I get a problem during enumerate(TrainLoader).
This is how I create my loader for both train and test. I already checked the weight list and its look correct.
train_sampler = torch.utils.data.WeightedRandomSampler(self.train_samples_weight, len(self.dataset_train))
test_sampler = torch.utils.data.WeightedRandomSampler(self.test_samples_weight,len(self.dataset_test))
test_loader = DataLoader(dataset=self.dataset_test, batch_size=self.batch_size,sampler=test_sampler)
train_loader = DataLoader(dataset=self.dataset_train, batch_size=self.batch_size,sampler=train_sampler)

When calling:
for batch_idx, (data, target) in enumerate(train_loader):

my data array should be three dimensions such as[batch,time,features] but I got something like
[batch, sampler second parameter, time, features]
I checked other code when this approach was used and that seems to work fine. I’m wondering if the problem is in my DataSet class that you can find below, but I’m not sure since it is quite easy.
class triaxial_dataset(Dataset):
	"""Time Series dataset."""

	def __init__(self, data, label):
		self.data = data
		print(self.data.shape)
		self.label = label

	def __len__(self):
		return self.data.shape[0]

	def __getitem__(self, idx):
		return self.data[idx], self.label[idx][0]

I also looked into the documentation and previous asked question but couldn’t find something similar.