def test_one_of_weight(self): for weight in [[1.0, 0.0], torch.tensor([1.0, 0.0])]: with self.subTest(weight=weight): trafo0 = Mirror((0, )) trafo1 = Mirror((1, )) comp = OneOf(trafo0, trafo1, weights=weight) out = comp(**self.batch) expected_out = trafo0(**self.batch) self.assertTrue(out["data"].allclose(expected_out["data"]))
def test_dropout_compose(self): compose = DropoutCompose(self.transforms[0], dropout=0.0) outp = compose(**self.batch) expected = Mirror(dims=(0, ), prob=1.)(**self.batch) self.assertTrue((expected["data"] == outp["data"]).all()) compose = DropoutCompose(self.transforms[0], dropout=1.0) outp = compose(**self.batch) self.assertTrue((self.batch["data"] == outp["data"]).all())
def test_dropout_compose(self): compose = DropoutCompose(self.transforms[0], dropout=0.0) self.assertEqual(len(compose.transform_order), 1) outp = compose(**self.batch) expected = Mirror(dims=(0, ))(**self.batch) self.assertTrue((expected["data"] == outp["data"]).all()) compose = DropoutCompose(self.transforms, dropout=1.0) outp = compose(**self.batch) self.assertEqual(len(compose.transform_order), 2) self.assertTrue((self.batch["data"] == outp["data"]).all())
def test_compose_shuffle(self): compose = Compose([Mirror(dims=(0, ))] * 10, shuffle=True) random.seed(0) outp = compose(**self.batch) order = list(range(len(compose.transforms))) expected_order = copy.deepcopy(order) random.seed(0) random.shuffle(expected_order) self.assertEqual(compose.transform_order, expected_order) self.assertNotEqual(expected_order, order)
def test_compose_single(self): single_compose = Compose(self.transforms[0]) outp = single_compose(**self.batch) expected = Mirror(dims=(0, ))(**self.batch) self.assertTrue((expected["data"] == outp["data"]).all())
def setUp(self) -> None: self.batch = {"data": torch.rand(1, 1, 10, 10)} self.transforms = [Mirror(dims=(0, )), Mirror(dims=(0, ))]
def test_one_of_weight_error(self): with self.assertRaises(ValueError): trafo = Mirror((0, )) comp = OneOf(trafo, trafo, weights=[0.33, 0.33, 0.33])
def test_one_of_no_weight(self): trafo = Mirror((0, )) comp = OneOf(trafo, trafo) out = comp(**self.batch) expected_out = trafo(**self.batch) self.assertTrue(out["data"].allclose(expected_out["data"]))