def test_list_of_two_dtypes_both_different(self): dtypes = [ np.dtype("int8"), np.dtype("uint8") ] iadt.gate_dtypes(dtypes, ["int8", "uint8"], [])
def test_list_of_two_arrays_different_dtypes(self): arrays = [ np.zeros((1, 1, 3), dtype=np.int8), np.zeros((1, 1, 3), dtype=np.uint8) ] iadt.gate_dtypes(arrays, ["int8", "uint8"], [])
def test_list_of_two_dtypes_both_different_one_disallowed(self): dtypes = [np.dtype("int8"), np.dtype("uint8")] with self.assertRaises(ValueError) as context: iadt.gate_dtypes(dtypes, ["int8"], ["uint8"]) assert "Got dtype 'uint8', which" in str(context.exception)
def test_single_array_disallowed(self): arr = np.zeros((1, 1, 3), dtype=np.int8) with self.assertRaises(ValueError) as context: iadt.gate_dtypes(arr, ["uint8"], ["int8"]) assert "Got dtype 'int8'" in str(context.exception)
def test_single_dtype_disallowed(self): dtype = np.dtype("int8") with self.assertRaises(ValueError) as context: iadt.gate_dtypes(dtype, ["uint8"], ["int8"]) assert "Got dtype 'int8', which" in str(context.exception)
def test_list_of_two_dtypes_both_same(self): dtypes = [ np.dtype("int8"), np.dtype("int8") ] iadt.gate_dtypes(dtypes, ["int8"], [])
def test_list_of_two_arrays_same_dtypes_one_disallowed(self): arrays = [ np.zeros((1, 1, 3), dtype=np.int8), np.zeros((1, 1, 3), dtype=np.uint8) ] with self.assertRaises(ValueError) as context: iadt.gate_dtypes(arrays, ["int8"], ["uint8"]) assert "Got dtype 'uint8', which" in str(context.exception)
def test_dtype_not_in_allowed_or_disallowed(self): dtypes = [np.dtype("int8"), np.dtype("float32")] with warnings.catch_warnings(record=True) as caught_warnings: warnings.simplefilter("always") iadt.gate_dtypes(dtypes, ["int8"], ["uint8"]) assert len(caught_warnings) == 1 assert ("Got dtype 'float32', which" in str(caught_warnings[-1].message))
def _augment_images(self, images, random_state, parents, hooks): iadt.gate_dtypes(images, allowed=["float32"], disallowed=[ "bool", "uint8", "uint16", "int8", "int16", "float16", "uint32", "uint64", "uint128", "uint256", "int32", "int64", "int128", "int256", "float64", "float96", "float128", "float256" ], augmenter=self) converted_images = numpy.clip(images, self.min, self.max) return converted_images
def test_single_dtype_disallowed_augmenter_set(self): class _DummyAugmenter(object): def __init__(self): self.name = "foo" dtype = np.dtype("int8") dummy_augmenter = _DummyAugmenter() with self.assertRaises(ValueError) as context: iadt.gate_dtypes(dtype, ["uint8"], ["int8"], augmenter=dummy_augmenter) assert "Got dtype 'int8' in augmenter 'foo'" in str(context.exception)
def _augment_images(self, images, random_state, parents, hooks): iadt.gate_dtypes(images, allowed=["uint8"], disallowed=[ "bool", "float32", "uint16", "int8", "int16", "float16", "uint32", "uint64", "uint128", "uint256", "int32", "int64", "int128", "int256", "float64", "float96", "float128", "float256" ], augmenter=self) converted_images = images.astype(numpy.float32) / 255. return converted_images
def test_dtype_not_in_allowed_or_disallowed_augmenter_set(self): class _DummyAugmenter(object): def __init__(self): self.name = "foo" dtypes = [np.dtype("int8"), np.dtype("float32")] dummy_augmenter = _DummyAugmenter() with warnings.catch_warnings(record=True) as caught_warnings: warnings.simplefilter("always") iadt.gate_dtypes(dtypes, ["int8"], ["uint8"], augmenter=dummy_augmenter) assert len(caught_warnings) == 1 assert ("Got dtype 'float32' in augmenter 'foo'" in str(caught_warnings[-1].message))
def _augment_images(self, images, random_state, parents, hooks): iadt.gate_dtypes(images, allowed=["float32"], disallowed=[ "bool", "uint8", "uint16", "int8", "int16", "float16", "uint32", "uint64", "uint128", "uint256", "int32", "int64", "int128", "int256", "float64", "float96", "float128", "float256" ], augmenter=self) if isinstance(images, numpy.ndarray): assert len(images.shape) == len(self.transpose) elif isinstance(images, list): assert len(images[0].shape) + 1 == len(self.transpose) converted_images = numpy.transpose(images, self.transpose) return converted_images
def _augment_images(self, images, random_state, parents, hooks): iadt.gate_dtypes(images, allowed=["float32"], disallowed=[ "bool", "uint8", "uint16", "int8", "int16", "float16", "uint32", "uint64", "uint128", "uint256", "int32", "int64", "int128", "int256", "float64", "float96", "float128", "float256" ], augmenter=self) converted_images = images * 255 converted_images = numpy.rint(converted_images) converted_images = numpy.clip(converted_images, 0, 255) converted_images = converted_images.astype(numpy.uint8) return converted_images
def test_single_array_allowed(self): arr = np.zeros((1, 1, 3), dtype=np.int8) iadt.gate_dtypes(arr, ["int8"], [])
def test_list_of_single_array(self): arr = np.zeros((1, 1, 3), dtype=np.int8) iadt.gate_dtypes([arr], ["int8"], [])
def test_single_dtype_name(self): dtype = "int8" iadt.gate_dtypes(dtype, ["int8"], [])
def test_single_dtype_function(self): dtype = np.int8 iadt.gate_dtypes(dtype, ["int8"], [])
def test_single_dtype_allowed(self): dtype = np.dtype("int8") iadt.gate_dtypes(dtype, ["int8"], [])