Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I cannot upload my dataset into Pytorch.

I am using the following code:

import pandas as pd
import torch
from torch.utils.data import Dataset
from skimage import io
import torchvision.transforms as transforms


class CatsAndDogsDataset(Dataset):
    def __init__(self, csv_file, root_dir, transform=None):
        self.annotations = pd.read_csv(csv_file)
        self.root_dir = root_dir
        self.transform = transform
    def __len__(self):
        return len(self.annotations) #24 images
    def __getitem__(self, index):
        img_path = os.path.join(self.root_dir, self.annotatoins.iloc[index, 0])
        image = io.imread(img_path)
        y_label = torch.tensor(int(self.annotations.iloc[index, 1]))
        
        if self.transform:
            image = self.transform(image)
        
        return (image, y_label)

dataset = CatsAndDogsDataset(csv_file = 'C:/***/Dataset/PetImages/Shuffled', root_dir = 'C:/***/Dataset/PetImages/Shuffled', 
                     transform = transforms.ToTensor())

and I keep receiving the error in form of: PermissionError: [Errno 13] Permission denied: 'C:/***/Dataset/PetImages/Shuffled'

Here I have two questions:

  1. When I have been trying to upload a similar dataset without defining the class and simply using cv2.imread function, there was no problems with permission. So why does this error pops up?

  2. How can I upload the dataset using this method?

Thank you in advance!

Regards

question from:https://stackoverflow.com/questions/66054314/load-the-dataset-in-pytorch

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
210 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...