def test_float_faithful_to_large_values(self): dts = ["float16", "float32", "float64", "float128"] values = [ [0.01, 0.1, 1.0, 10.0**1, 10.0**2], # float16 [0.01, 0.1, 1.0, 10.0**1, 10.0**2, 10.0**4, 10.0**6], # float32 [0.01, 0.1, 1.0, 10.0**1, 10.0**2, 10.0**6, 10.0**10], # float64 [0.01, 0.1, 1.0, 10.0**1, 10.0**2, 10.0**7, 10.0**11], # float128 ] for dt, values_i in zip(dts, values): for value in values_i: with self.subTest(dtype=dt, value=value): dt = np.dtype(dt) minv, center, maxv = -value, 0.0, value atol = 1e-4 if dt.name == "float16" else 1e-8 arr = np.array([[minv, center, maxv]], dtype=dt) arr_flipped = fliplib.fliplr(arr) expected = np.array([[maxv, center, minv]], dtype=dt) assert arr_flipped.dtype.name == dt.name assert arr_flipped.shape == (1, 3) assert np.allclose(arr_flipped, expected, rtol=0, atol=atol)
def test_bool_faithful(self): arr = np.array([[False, False, True]], dtype=bool) arr_flipped = fliplib.fliplr(arr) expected = np.array([[True, False, False]], dtype=bool) assert arr_flipped.dtype.name == "bool" assert arr_flipped.shape == (1, 3) assert np.array_equal(arr_flipped, expected)
def flip(img, point): img = aug.fliplr(img) length = len(point) idxs = np.arange(0, length, 2) point[idxs] = -point[idxs] return img, point
def test__fliplr_cv2_called_mocked(self, mock_cv2, mock_sliced): for dtype in ["uint8", "uint16", "int8", "int16"]: mock_cv2.reset_mock() mock_sliced.reset_mock() arr = np.zeros((1, 1), dtype=dtype) _ = fliplib.fliplr(arr) mock_cv2.assert_called_once_with(arr) assert mock_sliced.call_count == 0
def test__fliplr_sliced_called_mocked(self, mock_cv2, mock_sliced): for dtype in ["bool", "uint32", "uint64", "int32", "int64", "float16", "float32", "float64", "float128"]: mock_cv2.reset_mock() mock_sliced.reset_mock() arr = np.zeros((1, 1), dtype=dtype) _ = fliplib.fliplr(arr) assert mock_cv2.call_count == 0 mock_sliced.assert_called_once_with(arr)
def test_float_faithful_to_min_max(self): dts = ["float16", "float32", "float64", "float128"] for dt in dts: with self.subTest(dtype=dt): dt = np.dtype(dt) minv, center, maxv = iadt.get_value_range_of_dtype(dt) center = int(center) atol = 1e-4 if dt.name == "float16" else 1e-8 arr = np.array([[minv, center, maxv]], dtype=dt) arr_flipped = fliplib.fliplr(arr) expected = np.array([[maxv, center, minv]], dtype=dt) assert arr_flipped.dtype.name == dt.name assert arr_flipped.shape == (1, 3) assert np.allclose(arr_flipped, expected, rtol=0, atol=atol)
def test_uint_int_faithful(self): dts = ["uint8", "uint16", "uint32", "uint64", "int8", "int16", "int32", "int64"] for dt in dts: with self.subTest(dtype=dt): dt = np.dtype(dt) minv, center, maxv = iadt.get_value_range_of_dtype(dt) center = int(center) arr = np.array([[minv, center, maxv]], dtype=dt) arr_flipped = fliplib.fliplr(arr) expected = np.array([[maxv, center, minv]], dtype=dt) assert arr_flipped.dtype.name == dt.name assert arr_flipped.shape == (1, 3) assert np.array_equal(arr_flipped, expected)
def transform(tile, rot, lr): t = Rot90(rot).augment_image(tile) if lr: t = fliplr(t) return t
def _augment_batch_(self, batch, random_state, parents, hooks): for i, images in enumerate(batch.images): batch.images[i] = fliplr(batch.images[i]) return batch