Exemplo n.º 1
0
    def __init__(self, path):
        # type: (str) -> None
        """
        Class constructor.

        :param path: The folder in which to download MNIST.
        """
        super(MNIST_TRAIN, self).__init__()

        self.path = path

        self.normal_class = None

        # Get train and test split
        self.train_split = datasets.MNIST(self.path, train=True, download=True, transform=None)
        self.test_split = datasets.MNIST(self.path, train=False, download=True, transform=None)

        # Shuffle training indexes to build a validation set (see val())
        train_idx = np.arange(len(self.train_split))
        np.random.shuffle(train_idx)
        self.shuffled_train_idx = train_idx

        # Transform zone
        self.train_transform = transforms.Compose([ToFloatTensor2D()])
        self.val_transform = transforms.Compose([ToFloatTensor2D()])
        self.test_transform = transforms.Compose([ToFloat32(), OCToFloatTensor2D()])
        self.transform = None

        # Other utilities
        self.mode = None
        self.length = None
        self.val_idxs = None
Exemplo n.º 2
0
    def __init__(self,
                 path,
                 n_class=10,
                 select=None,
                 select_novel_classes=None):

        # type: (str) -> None
        """
        Class constructor.
        :param path: The folder in which to download MNIST.

        """
        super(FMNIST, self).__init__()

        self.path = path
        self.n_class = n_class
        self.normal_class = None
        self.select = select

        if select_novel_classes != None:
            self.select_novel_classes = [
                int(novel_class) for novel_class in select_novel_classes
            ]
        else:
            self.select_novel_classes = None

        self.name = 'fmnist'

        # Get train and test split
        self.train_split = datasets.FashionMNIST(self.path,
                                                 train=True,
                                                 download=True,
                                                 transform=None)
        self.test_split = datasets.FashionMNIST(self.path,
                                                train=False,
                                                download=True,
                                                transform=None)

        # Shuffle training indexes to build a validation set (see val())
        train_idx = np.arange(len(self.train_split))
        np.random.shuffle(train_idx)
        self.shuffled_train_idx = train_idx

        # Transform zone
        self.val_transform = transforms.Compose([ToFloatTensor2D()])
        self.train_transform = transforms.Compose([ToFloatTensor2D()])
        self.test_transform = transforms.Compose(
            [ToFloat32(), OCToFloatTensor2D()])
        self.transform = None

        # Other utilities
        self.mode = None
        self.length = None

        # val idx in normal class (all possible classes)
        self.val_idxs = None
        # train idx in normal class
        self.train_idxs = None
        # test idx with 50%->90% normal class(50% -> 10% novelty)
        self.test_idxs = None