Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
200 views
in Technique[技术] by (71.8m points)

python - Load the dataset in Pytorch

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

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

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...