Iterating through data loader returning dimension error

Jotham_Soboyejo: <p>Hi, i have been trying for days to join my training data and labels together but kept on meeting several errors but this error is quite difficult for me to understand, so if anyone could please shed some light i would be most thankful . I’m trying to Iterate through a concatenated data set that contains my train data and labels but i keep on encountering this error. Train_data dim = [27455, 1, 28, 28] and train_labels dim = [27455].</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/4/a/4a6024e8780cdce0e65aaa3c08bb78d0d91abe9c.png" data-download-href="https://discuss.pytorch.org/uploads/default/4a6024e8780cdce0e65aaa3c08bb78d0d91abe9c" title="Screenshot from 2020-04-27 17-12-02"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/4/a/4a6024e8780cdce0e65aaa3c08bb78d0d91abe9c_2_690x388.png" alt="Screenshot from 2020-04-27 17-12-02" data-base62-sha1="aBXjSYdybwUzR3GaXpmbx0GwlZy" width="690" height="388" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/4/a/4a6024e8780cdce0e65aaa3c08bb78d0d91abe9c_2_690x388.png, https://discuss.pytorch.org/uploads/default/optimized/3X/4/a/4a6024e8780cdce0e65aaa3c08bb78d0d91abe9c_2_1035x582.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/4/a/4a6024e8780cdce0e65aaa3c08bb78d0d91abe9c_2_1380x776.png 2x" data-dominant-color="4A2225"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Screenshot from 2020-04-27 17-12-02</span><span class="informations">1920×1080 264 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

ptrblck: <p>Could you post the code of your <code>Dataset</code> implementation?<br>
It seems you would like to return both the data and target as one tensor?</p>
<p>The usual approach would be to return these tensors separately, as they might have a different number of dimensions and shapes:</p>
<pre><code class="lang-python">def __getitem__(self, index):
    ...
    return data, target
</code></pre>

Jotham_Soboyejo: <code>
train = pd.read_csv("../datasets/sign-language-mnist/sign_mnist_train/sign_mnist_train.csv")
test = pd.read_csv("../datasets/sign-language-mnist/sign_mnist_test/sign_mnist_test.csv")
train_labels = train.pop('label').values
test_labels = test.pop('label').values
<p>train_data = train.values<br>
test_data = train.values</p>
<p>train_data, test_data = np.array(train_data, dtype=np.float32), np.array(test_data, dtype=np.float32)<br>
train_labels, test_labels = np.array(train_labels, dtype=np.float32), np.array(test_labels, dtype=np.float32)<br>
train_data, test_data = train_data.reshape((-1,1,28,28)), test_data.reshape((-1,1,28,28))</p>
<p>train_data = torch.from_numpy(train_data)<br>
train_labels = torch.from_numpy(train_labels)<br>
test_data = torch.from_numpy(test_data)<br>
test_labels = torch.from_numpy(test_labels)</p>
<p>train_data = train_data.to(torch.float)<br>
test_data = test_data.to(torch.float)</p>
<p>train_data, train_labels = torch.utils.data.TensorDataset(train_data), torch.utils.data.TensorDataset(train_labels)<br>
test_data, test_labels = torch.utils.data.TensorDataset(test_data), torch.utils.data.TensorDataset(test_labels)</p>
<p>train_loader = torch.utils.data.ConcatDataset([train_data, train_labels])<br>
test_loader = torch.utils.data.ConcatDataset([test_data, test_labels])</p>
<p>train_loader = torch.utils.data.DataLoader(train_loader,<br>
shuffle=True, batch_size=32)<br>
test_loader = torch.utils.data.DataLoader(test_loader,<br>
shuffle=True, batch_size=32)<br>
</p></code>