I am trying to upload my dataset(SWELL-KW) instead of MNIST in "Hybrid quantum-classical Neural Networks with PyTorch and Qiskit" provided by IBM qiskit but it says "AttributeError: module 'torchvision.datasets' has no attribute 'SWELL'. I could not find the dataset in torch vision. Is that the reason? If I try to give the path of dataset which is on my system, it indicates unicode error. Thank You.


1 Answer 1


Yes, since the dataset does not exist in torchvision, trying to load it through torchvision will produce this error. Instead, save your SWELL-KW dataset as a .csv file, read it in, and convert the train/test data vectors, and labels each as their own PyTorch tensor.

For example, let's say I have my own custom dataset that consists of coordinate pairs and associated labels. I save the data into a file myData.csv such that the first column contains the x-coordinates, the second column contains the y-coordinates and the third column contains the labels. First, we load data row by row,

import csv
import torch
Xs = []
Ys = []

with open('myData.csv', mode ='r') as data:
    csvFile = csv.reader(data)
    for row in csvFile:
        Xs.append([float(row[0]), float(row[1])])

and then we convert each of our lists to PyTorch tensors,

X_tensor = torch.FloatTensor(Xs)
Y_tensor = torch.FloatTensor(Ys)

Your data is now ready to use. For more complex datasets or specific use cases you may need to create a custom dataset class.

  • $\begingroup$ Thank you. But since I am a beginner, please let me know how do I convert the dataset into pytorch tensor after reading the dataset using pd.read_csv()? I have a train and test data csv files on the system. I am trying to upload my dataset. what could be the steps? [![enter image description here][1]][1] [![enter image description here][2]][2] [1]: i.sstatic.net/Lq8PR.png [2]: i.sstatic.net/gkCFp.png $\endgroup$
    – user14924
    Commented Apr 2, 2021 at 14:30
  • $\begingroup$ Sure, let me know if my latest edit helps. $\endgroup$
    – ryanhill1
    Commented Apr 2, 2021 at 16:29
  • $\begingroup$ Thank you so much for the answer. I understood now. $\endgroup$
    – user14924
    Commented Apr 3, 2021 at 6:09
  • $\begingroup$ Awesome! If your question resolved could you do me a favor and check-mark the answer? Thanks! $\endgroup$
    – ryanhill1
    Commented Apr 3, 2021 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.