I am trying to covert a pandas data frame into a pytorch tensor in order to run a LSTM model, but I keep getting the following error stating that there is value error and unable to determine the shape of the object type 'series'. It then refers to the following code:
class MicroESDataset(Dataset):
def __init__(self, sequences):
self.sequences = sequences
def __len__(self):
return len(self.sequences)
def __getitem__(self, idx):
sequence, label = self.sequences[idx]
return dict (
sequence=torch.Tensor(sequence.to_numpy()),
label = torch.tensor(label).float ()
)
Am I missing something completely obvious? Thanks
Here is the exact error message and traceback:
ValueError Traceback (most recent call last)
<ipython-input-46-fb5c7eb803e1> in <module>()
----> 1 for item in data_module.train_dataloader():
2 print(item["sequence"].shape)
3 print(item["label"].shape)
4 # print(item["label"])
5 break
3 frames
/usr/local/lib/python3.7/dist-packages/torch/_utils.py in reraise(self)
427 # have message field
428 raise self.exc_type(message=msg)
--> 429 raise self.exc_type(msg)
430
431
ValueError: Caught ValueError in DataLoader worker process 0.
Original Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/worker.py", line 202, in _worker_loop
data = fetcher.fetch(index)
File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/fetch.py", line 44, in <listcomp>
data = [self.dataset[idx] for idx in possibly_batched_index]
File "<ipython-input-30-36c44aae196d>", line 13, in __getitem__
label = torch.tensor(label).float()
ValueError: could not determine the shape of object type 'Series'
labelis a Series object and Tensorflow doesn't know what to do with that.dataloadersnum_workers=0argument passed.