Hi Ptrblck,
apologies for the delay in getting back to you. I ran your code on a sample deck and compared the values in data to the input array X and i can see that the tensor data doesn’t get shuffled by view the output in the print data statement to the print X statement…
from __future__ import print_function
import torch
import torch.nn.parallel
from torch.utils.data import DataLoader
from torch.utils.data import TensorDataset
x = torch.randn(42, 2048)
y = torch.randn(42, 1)
print("x=",x)
#print("y=",y)
dataset = TensorDataset(x, y)
train_loader = DataLoader(dataset, batch_size=1, shuffle=True)
for idx in range(x.size(0)):
data, target = dataset[idx]
assert (data==x[idx]).all(), "data shuffled"
assert (target==y[idx]).all(), "target shuffled"
for epoch in range(1):
for (data, target) in train_loader:
#print("data=",data.shape)
print("data",data)
#np.savetxt(f2,target.numpy())
however when I repeat the same exercise with my dataset the contents of data are not in the same order as the input. The code is:
X_train=train_array.transpose([1,0,2]).reshape(42000,2048) #the input array size is [42000,2048,1]
X_train=torch.Tensor(X_train)
y_train=np.arange(1,42001,1)
y_train=y_train.reshape(42000,1)
y_train=torch.from_numpy(y_train)
train_dataset = TensorDataset(X_train, y_train)
train_loader = DataLoader(train_dataset, batch_size=BATCHSIZE, shuffle=True)
for idx in range(X_train.size(0)):
data, target = train_dataset[idx]
assert (data==X_train[idx]).all(), "data shuffled"
assert (target==y_train[idx]).all(), "target shuffled"
for epoch in range(num_epochs):
for (data, target) in train_loader:
#print("data=",data.shape)
np.savetxt(f,data.numpy())
np.savetxt(f2,target.numpy())
data=data.unsqueeze(1)
print("data_sq=",data.shape)
I’m begining to think that i have done something silly but i really can’t see what I have done
Chaslie