Reading vector information instead when trying to read filename to create custom dataset
Using python v 3.7.3, pytorch v 0.4.1, windows 10, running code on Jupyter

I am pretty new to programming and deep learning, and creating a new dataset by combining 2 existing datasets.  I am trying to read the filenames of the images but instead it is returning the vector information.  Here is a snippet of the output (imgname is the path, names should just be the filename eg vinegar_41):

imgname: C:\Users\User\Documents\Dataset\train\vinegar\vinegar_41.png

 names:  [[[128 128 128]
  [128 128 128]
  [128 128 128]
  ...
  [128 128 128]
  [128 128 128]
  [128 128 128]]

 [[128 128 128]
  [128 128 128]
  [128 128 128]
  ...
  [128 128 128]
  [128 128 128]
  [128 128 128]]


Here is my code thus far:


__all__ = ['MyDataset']

class MyDataset(Dataset):

    def __init__(self, root, transform=None, target_transform=None):
        root = train_set
        print(root)
        root_list = os.listdir(root)
        print(root_list)
        for f in root_list:
            print('checkpoint')
            imgs = []
            for img in os.listdir(f):
                #print('\n image: ', img)
                imgname = (root + '\\' + f + '\\' + img)
                print('\n imgname:', imgname)
                open(imgname, 'r')
                if img.endswith('.png'):
                    names = cv2.imread(imgname)
                    imgs.append(names)
                    #print('\n imgs: ', imgs)
                    print('\n names: ', names)

                #Image.close()
        self.imgs = imgs
        self.transform = transform
        self.target_transform = target_transform

    def __getitem__(self, index):
        fn, label = self.imgs[index]
        img = PIL.Image.open(fn).convert('RGB')
        if self.transform is not None:
            img = self.transform(img)
        if self.target_transform is not None:
            label = self.transform(label)
        return img, label

    def __len__(self):
        return len(self.imgs)


I'm in over my head, but my project is due in a couple days, so any advice on how to make this work would be greatly appreciated.

from skimage import io


class MyDataset(Dataset):
    """My dataset."""

    def __init__(self, csv_file, root_dir, transform=None,
                 target_transform=None):
        """
        Args:
            csv_file (string): Path to the csv file with labels.
            root_dir (string): Directory with all the images.
            transform (callable, optional): Optional transform to be applied
                on a sample.
            target_transform (callable, optional): Optional transform to 
                be applied on a label.
        """
        self.label = pd.read_csv(csv_file)
        self.root_dir = root_dir
        self.transform = transform
        self.target_transform = target_transform

    def __len__(self):
        return len(self.label)

    def __getitem__(self, idx):
        img_name = os.path.join(self.root_dir, self.label.iloc[idx, 0])
        image = io.imread(img_name)
        sample = image
        lab = self.label.iloc[idx, 1]

        if self.transform is not None:
            img = self.transform(img)
        if self.target_transform is not None:
            lab = self.target_transform(lab)

        return sample, lab


The csv file should look like:

fname,label
image1.png,1
image2.png,0
image3.png,1
...
imagen.png,0

