I have a embed_arr_list
which is a list of 3d arrays with variable 3rd dimension shape, like this:
for arr in embed_arr_list:
print(arr.shape)
(50, 128, 331)
(50, 128, 331)
(50, 128, 331)
(50, 128, 331)
(50, 128, 201)
(50, 128, 201)
(50, 128, 532)
(50, 128, 532)
(50, 128, 532)
(50, 128, 532)
len(embed_arr_list)
10
I also have a target_list
, containing the targets (floats).
len(target_list)
10
Then, I want to build a dataloader
import torch
import numpy as np
from torch.utils.data import TensorDataset, DataLoader
tensor_x = torch.Tensor(embed_arr_list) # transform to torch tensor
tensor_y = torch.Tensor(target_list)
my_dataset = TensorDataset(tensor_x,tensor_y) # create your datset
my_dataloader = DataLoader(my_dataset) # create your dataloader
However, I got the following error
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-84-f293256d52d8> in <module>
3 from torch.utils.data import TensorDataset, DataLoader
4
----> 5 tensor_x = torch.Tensor(embed_arr_list) # transform to torch tensor
6 tensor_y = torch.Tensor(target_list)
7
ValueError: expected sequence of length 331 at dim 3 (got 201)
May I know how to feed the variable length 3d arrays to the dataloader without using padding?
Because I want to use nn.AdaptiveAvgPool3d
, which I understand should adapt to variable input dimensions.
Thank you!