Pytorch DataLoader switch item to List and cause several errors

My source code is using pytorch and like this:

def Embed(sequenceSet):
  output = []
  for s in sequenceSet:
    PseDNCSequence = Embedding.PseDNC(str(s))
    ANFSequence = Embedding.ANF(str(s))
    EIIPSequence = Embedding.EIIP(str(s))
    emdbededSequence = PseDNCSequence+ANFSequence+EIIPSequence
    output.append(emdbededSequence)
  return np.array(output)

text = file.read()
lines = text.strip().split('\n')
embededS = Embed(lines)
embeddedSequences = torch.tensor(embededS)
my_dataset = TensorDataset(embeddedSequences)
loader = data.DataLoader(my_dataset, batch_size=batch_size, shuffle=True)

for epoch in range(num_epochs):
   for training_sample in loader:
      training_sample = training_sample.view(-1, sequenceLength)
      batch_size = training_sample.shape[0]
      ....

It is getting error " AttributeError: ‘list’ object has no attribute ‘view’ " at the line:

training_sample = training_sample.view(-1, sequenceLength)

I tried to change it into:

training_sample = torch.tensor(training_sample)
training_sample = training_sample.view(-1, sequenceLength)

… then I I received another error “ValueError: only one element tensors can be converted to Python scalars”

I already checked the other places and make sure that the input data to the loader is tensor. Can anybody help me how to solve it

Thank you so much !!!

Use torch.stack or torch.cat depending on the desired output shape instead of torch.tensor(training_sample).

hi @ptrblck ,

After tried it, but seem not work. For instead, I add one more fake column like this:

y = torch.ones(len(embededSequence), 1).float()
dataset = TensorDataset(embededSequence, y)

then it work