[SOLVED] The code has been updated: I wish to create an image dataset for self supervised learning, where I have a dataset of 1000 unlabelled images (.jpg files). I wish to create 4000 labelled images for rotation angle detection pre-task.

For each image , I wish to create 4 labelled images with rotation of 0, 90, 180, or 270 degrees and assign corresponding pseudo-labels (0,90,180 and 270) to them.

The images are in .jpg format in the file "/content/unsup_f".


import torch
import torchvision.transforms.functional as F
from torch.utils.data import Dataset, DataLoader
from PIL import Image
from torchvision import transforms as T
from torchvision.datasets import ImageFolder

class RotationDataset(Dataset):
    def __init__(self, dataset, degrees):
        self.dataset = dataset
        self.degrees = degrees

    def __len__(self):
        return len(self.dataset) * len(self.degrees)

    def __getitem__(self, index):
        img_index = index // len(self.degrees)
        img, _ = self.dataset[img_index]
        degree_index = index % len(self.degrees)
        degree = self.degrees[degree_index]
        rotated_img = F.rotate(img, degree)
        label = torch.tensor(degrees[degree_index])
        return rotated_img, label

trans_comp = T.Compose([

unlabelled_dataset = ImageFolder(root='/content/unsup_f', transform=trans_comp)

# Example usage

    degrees = [0, 90, 180, 270]
rotated_dataset = RotationDataset(unlabelled_dataset, degrees)

dataloader = DataLoader(rotated_dataset, batch_size=1, shuffle=True)

I tried to create this class but was not able to do so. can someone help.


FileNotFoundError: Found no valid file for the classes .ipynb_checkpoints. Supported extensions are: .jpg, .jpeg, .png, .ppm, .bmp, .pgm, .tif, .tiff, .webp
  • $\begingroup$ @IyaLee I think Imageloader requires classes; because the images are in correct .jpg format. $\endgroup$ Commented Mar 22, 2023 at 17:59
  • $\begingroup$ I actually solved the problem. I have updated my question. $\endgroup$ Commented Mar 22, 2023 at 21:34


Your Answer

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

Browse other questions tagged or ask your own question.