Received correct answer on my local machine, while google colab did not send correct answer

Hi,

I developed the following code to concatenate two data together. I received correct answer on my local machine, while google colab did not send correct answer. Please advice

class ConcatDataset(Dataset):
  def __init__(self, x1, x2, y): self.x1, self.x2, self.y = x1, x2, y
  def __len__(self): return len(self.y)
  def __getitem__(self, i): return (self.x1[i], self.x2[i]), self.y[i]

#concatenate base and target dataset
train_ds = ConcatDataset(x1_train, x2_train, y_train)
valid_ds = ConcatDataset(x1_valid, x2_valid, y_valid)

#create training and validation data loaders from train and valid dataset
train_dl = DataLoader(train_ds, batch_size=2)
valid_dl = DataLoader(valid_ds, batch_size=2)

#create train data bunch from training and validation data loaders
data_train = DataBunch(train_dl, valid_dl)

from torchvision.utils import make_grid
def imshow(inp): plt.imshow(np.clip(inp.numpy().transpose((1, 2, 0)), 0, 1))
(x1, x2), y = next(iter(data_train.train_dl)); concat = torch.cat((x1, x2), 0); plt.figure(figsize = (24, 9)); imshow(make_grid(concat, nrow=2))

Google Colab Concatenation Sample Result (Wrong Concatenation):

My Local Machine Concatenation Sample Result (Correct Concatenation):

@ptrblck

Hi: Do you have any idea why this happened?

I don’t understand the use case completely.
It seems you are trying to concatenate the output of two different loaders.
Are you using any random transformations, such as flipping or rotation?
What would the expected output be?

1 Like

Yes, I am trying to concatenate two data loaders and do not use any augmentation rule.
The problem is that the code works well on my pc, while the same code does not correctly work in google colab. The output has to be concatenated dataset.

We should upload the data as zip file in google drive, because uploading the images may cause that problem for dataloaders.