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:
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?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