RuntimeError: stack expects each tensor to be equal size, but got [x] at entry 0 and [x] at entry 1

RuntimeError: stack expects each tensor to be equal size, but got [x] at entry 0 and [x] at entry 1

Problem description: When generating a dataloader, the training set can be run, but the test set has this error: RuntimeError: stack expects each tensor to be equal size, but got [200] at entry 0 and [116] at entry 1.

How to Solve: In generating the dataloader, I need to generate a dataset, so my error occurred because there is a minibatch in the dataset with a different number of data than the other minibatch, so I went into the custom dataset method to check, and through print debugging, I found that it was a problem with the dataset label.

Solution: Go into the dataset and print the output of the dataset.

Read More: