Skip to content
Advertisement

Creating and Use a PyTorch DataLoader

I am trying to create a PyTorch Dataset and DataLoader object using a sample data.

This is the tab seperated dataset:

JavaScript

This is the code to create the Dataset above and DataLoader object:

JavaScript

The code is simply saved with the filename “demo.py“. The code should succesfully execute once the command ‘python demo.py‘ is executed on a command prompt screen. I use Anaconda Prompt which has Torch (v 1.10) installed.

I have tried numerous methods to get the above working, but I only get an error which says:

JavaScript

I am not able to see which part of the index is wrong, as I don’t feel there seem to be anything wrong with the indexing. Can someone please help me ?

Advertisement

Answer

Your data seems to be space-separated, not tab-separated. So, when you specify delimiter="t", the entire row is read as a single column. But because of usecols=range(0,7), NumPy expects there to be seven columns, and throws an error when trying to iterate over them.

To fix this, either change the whitespaces to tabs in your data, or change the delimiter argument to delimiter=" ".

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement