import os.path
from glob import glob

from torch.utils import Dataset

from PIL import Image

class DatasetFolder(Dataset):
    def __init__(self, root, pattern, transform=None, target_transform=None):
        # classes, class_to_idx = find_classes(root)
        samples = glob(pattern)

        self.loader = loader
        self.samples = samples

        self.transform = transform
        self.target_transform = target_transform

    def __getitem__(self, index):
        """
        Args:
            index (int): Index

        Returns:
            tuple: (sample, target) where target is class_index of the target class.
        """
        path, target = self.samples[index]
        sample = self.loader(path)
        if self.transform is not None:
            sample = self.transform(sample)
        if self.target_transform is not None:
            target = self.target_transform(target)

        return sample, target

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


def pil_loader(path):
    # open path as file to avoid ResourceWarning (https://github.com/python-pillow/Pillow/issues/835)
    with open(path, 'rb') as f:
        img = Image.open(f)
        return img.convert('RGB')

27ccffb2db2e07e26f325ed28561b76806cab669
<mask token>


class DatasetFolder(Dataset):

    def __init__(self, root, pattern, transform=None, target_transform=None):
        samples = glob(pattern)
        self.loader = loader
        self.samples = samples
        self.transform = transform
        self.target_transform = target_transform
    <mask token>
    <mask token>


<mask token>

<mask token>


class DatasetFolder(Dataset):

    def __init__(self, root, pattern, transform=None, target_transform=None):
        samples = glob(pattern)
        self.loader = loader
        self.samples = samples
        self.transform = transform
        self.target_transform = target_transform
    <mask token>

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


<mask token>

<mask token>


class DatasetFolder(Dataset):

    def __init__(self, root, pattern, transform=None, target_transform=None):
        samples = glob(pattern)
        self.loader = loader
        self.samples = samples
        self.transform = transform
        self.target_transform = target_transform

    def __getitem__(self, index):
        """
        Args:
            index (int): Index

        Returns:
            tuple: (sample, target) where target is class_index of the target class.
        """
        path, target = self.samples[index]
        sample = self.loader(path)
        if self.transform is not None:
            sample = self.transform(sample)
        if self.target_transform is not None:
            target = self.target_transform(target)
        return sample, target

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


<mask token>

import os.path
from glob import glob
from torch.utils import Dataset
from PIL import Image


class DatasetFolder(Dataset):

    def __init__(self, root, pattern, transform=None, target_transform=None):
        samples = glob(pattern)
        self.loader = loader
        self.samples = samples
        self.transform = transform
        self.target_transform = target_transform

    def __getitem__(self, index):
        """
        Args:
            index (int): Index

        Returns:
            tuple: (sample, target) where target is class_index of the target class.
        """
        path, target = self.samples[index]
        sample = self.loader(path)
        if self.transform is not None:
            sample = self.transform(sample)
        if self.target_transform is not None:
            target = self.target_transform(target)
        return sample, target

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


def pil_loader(path):
    with open(path, 'rb') as f:
        img = Image.open(f)
        return img.convert('RGB')

import os.path
from glob import glob

from torch.utils import Dataset

from PIL import Image

class DatasetFolder(Dataset):
    def __init__(self, root, pattern, transform=None, target_transform=None):
        # classes, class_to_idx = find_classes(root)
        samples = glob(pattern)

        self.loader = loader
        self.samples = samples

        self.transform = transform
        self.target_transform = target_transform

    def __getitem__(self, index):
        """
        Args:
            index (int): Index

        Returns:
            tuple: (sample, target) where target is class_index of the target class.
        """
        path, target = self.samples[index]
        sample = self.loader(path)
        if self.transform is not None:
            sample = self.transform(sample)
        if self.target_transform is not None:
            target = self.target_transform(target)

        return sample, target

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


def pil_loader(path):
    # open path as file to avoid ResourceWarning (https://github.com/python-pillow/Pillow/issues/835)
    with open(path, 'rb') as f:
        img = Image.open(f)
        return img.convert('RGB')
