def test_different_modes(self): """Test ClassificationDataset object for different modes""" test_dataset_config = { 'name': 'CIFAR10', 'version': 'default', 'mode': 'test' } train_dataset_config = { 'name': 'CIFAR10', 'version': 'default', 'mode': 'train' } test_dataset = get_classification_dataset(BaseImageDataset)( DATA_ROOT, [test_dataset_config]) train_dataset = get_classification_dataset(BaseImageDataset)( DATA_ROOT, [train_dataset_config]) self.assertTrue(len(test_dataset.items) != len(train_dataset.items))
def test_dataset_with_signal_transform(self): """Checks dataset with signal transform""" dataset = get_classification_dataset(BaseImageDataset)( DATA_ROOT, self.dataset_config, signal_transform=self.signal_transform, target_transform=self.target_transform) instance = dataset[0] self.assertEqual(instance['signal'].shape, (3, 30, 30))
def test_dataset_no_transform(self): """Checks dataset using no transform""" dataset = get_classification_dataset(BaseImageDataset)( DATA_ROOT, self.dataset_config) instance = dataset[0] self.assertEqual(instance['item'].path, '/data/CIFAR10/processed/images/50000.png') self.assertTrue(isinstance(instance['signal'], torch.Tensor)) self.assertEqual(instance['label'], [3])
def test_fraction(self): """Test creating ClassificationDataset object using fraction < 1""" dataset_config = { 'name': 'CIFAR10', 'version': 'default', 'mode': 'test' } fraction = 0.5 dataset = get_classification_dataset(BaseImageDataset)( DATA_ROOT, [dataset_config], fraction=fraction) self.assertEqual(5000, len(dataset.items))