Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions .github/workflows/test_pull_requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
#os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-latest, macos-latest, windows-latest]
# see supported versions at
# https://raw.githubusercontent.com/actions/python-versions/master/versions-manifest.json
Expand All @@ -36,16 +35,16 @@ jobs:
python-version: '3.10'
- os: macos-latest
python-version: '3.11'
#- os: windows-latest
# python-version: '3.7'
#- os: windows-latest
# python-version: '3.8'
#- os: windows-latest
# python-version: '3.9'
#- os: windows-latest
# python-version: '3.10'
#- os: windows-latest
# python-version: '3.11'
- os: windows-latest
python-version: '3.7'
- os: windows-latest
python-version: '3.8'
- os: windows-latest
python-version: '3.9'
- os: windows-latest
python-version: '3.10'
- os: windows-latest
python-version: '3.11'
env:
OS: ${{ matrix.os }}
PYTHON: ${{ matrix.python-version }}
Expand Down
12 changes: 6 additions & 6 deletions imgaug/augmenters/geometric.py
Original file line number Diff line number Diff line change
Expand Up @@ -3225,7 +3225,7 @@ def _augment_images_by_samples(self, images, samples):
image_warped = image_warped > 0.5
else:
# fill skimage.transform.warp output nan values with cval
image_warped = np.where(np.isnan(image_warped), cval, image_warped)
image_warped = np.where(np.isnan(image_warped), cval.astype(input_dtype), image_warped)

# warp seems to change everything to float64, including
# uint8, making this necessary
Expand Down Expand Up @@ -4799,7 +4799,7 @@ def _map_coordinates(self, image, dx, dy, order=1, cval=0, mode="constant"):
result = np.empty_like(image)

for c in sm.xrange(image.shape[2]):
remapped_flat = ndimage.interpolation.map_coordinates(
remapped_flat = ndimage.map_coordinates(
image[..., c],
(y_shifted.flatten(), x_shifted.flatten()),
order=order,
Expand Down Expand Up @@ -4888,7 +4888,6 @@ def generate(self, shapes, alphas, sigmas, random_state):
# somewhere by 2. It is fastes to multiply the (fewer) alphas, which
# we will have to multiply the shift maps with anyways.
alphas *= 2

# Configuration for each chunk.
# switch dx / dy, flip dx lr, flip dx ud, flip dy lr, flip dy ud
switch = [False, True]
Expand Down Expand Up @@ -4958,9 +4957,8 @@ def _flip(cls, dx, dy, flips):
# Added in 0.5.0.
@classmethod
def _mul_alpha(cls, dx, dy, alpha):
# performance drops for cv2.multiply here
dx = dx * alpha
dy = dy * alpha
dx = (dx * alpha).astype(dx.dtype)
dy = (dy * alpha).astype(dy.dtype)
return dx, dy

# Added in 0.5.0.
Expand All @@ -4971,6 +4969,8 @@ def _smoothen_(cls, dx, dy, sigma):
dy = blur_lib.blur_gaussian_(dy, sigma)
else:
ksize = int(round(2*sigma))
dx = np.ascontiguousarray(dx)
dy = np.ascontiguousarray(dy)
dx = cv2.blur(dx, (ksize, ksize), dst=dx)
dy = cv2.blur(dy, (ksize, ksize), dst=dy)
return dx, dy
Expand Down
12 changes: 6 additions & 6 deletions imgaug/imgaug.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
# to check if a dtype instance is among these dtypes, use e.g.
# `dtype.type in NP_FLOAT_TYPES` do not just use `dtype in NP_FLOAT_TYPES` as
# that would fail
NP_FLOAT_TYPES = set(np.sctypes["float"])
NP_INT_TYPES = set(np.sctypes["int"])
NP_UINT_TYPES = set(np.sctypes["uint"])
NP_FLOAT_TYPES = set([np.float16, np.float32, np.float64])
NP_INT_TYPES = set([np.int8, np.int16, np.int32, np.int64])
NP_UINT_TYPES = set([np.uint8, np.uint16, np.uint32, np.uint64])

IMSHOW_BACKEND_DEFAULT = "matplotlib"

Expand Down Expand Up @@ -697,13 +697,13 @@ def angle_between_vectors(v1, v2):

Examples
--------
>>> angle_between_vectors(np.float32([1, 0, 0]), np.float32([0, 1, 0]))
>>> angle_between_vectors(np.float32([1, 0, 0]), np.float32([0, 1, 0])).item()
1.570796...

>>> angle_between_vectors(np.float32([1, 0, 0]), np.float32([1, 0, 0]))
>>> angle_between_vectors(np.float32([1, 0, 0]), np.float32([1, 0, 0])).item()
0.0

>>> angle_between_vectors(np.float32([1, 0, 0]), np.float32([-1, 0, 0]))
>>> angle_between_vectors(np.float32([1, 0, 0]), np.float32([-1, 0, 0])).item()
3.141592...

"""
Expand Down
6 changes: 3 additions & 3 deletions imgaug/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ class Deterministic(StochasticParameter):
--------
>>> import imgaug.parameters as iap
>>> param = iap.Deterministic(10)
>>> param.draw_sample()
>>> param.draw_sample().item()
10

Will always sample the value 10.
Expand Down Expand Up @@ -2588,7 +2588,7 @@ def _draw_samples(self, size, random_state):
# result = np.float_power(samples, exponents)
# TODO why was float32 type here replaced with complex number
# formulation?
result = np.power(samples.astype(np.complex_), exponents).real
result = np.power(samples.astype(np.complex128), exponents).real
if result.dtype != samples_dtype:
result = result.astype(samples_dtype)

Expand Down Expand Up @@ -3558,7 +3558,7 @@ def _draw_samples_hw(self, height, width, random_state):
wn = wn.astype(np.float32)

# equivalent but slightly faster then:
# wn_freqs_mul = np.zeros(treal.shape, dtype=np.complex_)
# wn_freqs_mul = np.zeros(treal.shape, dtype=np.complex128)
# wn_freqs_mul.real = wn[0]
# wn_freqs_mul.imag = wn[1]
# wn_inv = np.fft.ifft2(wn_freqs_mul).real
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

INSTALL_REQUIRES = [
"six",
#"numpy>=1.21 # opencv 3 does not support numpy 2
"numpy>=1.21,<2",
"numpy>=1.21",
"scipy",
"Pillow",
"matplotlib",
Expand Down
28 changes: 14 additions & 14 deletions test/augmentables/test_polys.py
Original file line number Diff line number Diff line change
Expand Up @@ -1778,26 +1778,26 @@ class TestPolygon_to_bounding_box(unittest.TestCase):
def test_square_polygon(self):
poly = ia.Polygon([(0, 0), (1, 0), (1, 1), (0, 1)])
bb = poly.to_bounding_box()
assert 0 - 1e-8 < bb.x1 < 0 + 1e-8
assert 0 - 1e-8 < bb.y1 < 0 + 1e-8
assert 1 - 1e-8 < bb.x2 < 1 + 1e-8
assert 1 - 1e-8 < bb.y2 < 1 + 1e-8
assert 0 - 1e-8 < float(bb.x1) < 0 + 1e-8
assert 0 - 1e-8 < float(bb.y1) < 0 + 1e-8
assert 1 - 1e-8 < float(bb.x2) < 1 + 1e-8
assert 1 - 1e-8 < float(bb.y2) < 1 + 1e-8

def test_triangular_polygon(self):
poly = ia.Polygon([(0.5, 0), (1, 1), (0, 1)])
bb = poly.to_bounding_box()
assert 0 - 1e-8 < bb.x1 < 0 + 1e-8
assert 0 - 1e-8 < bb.y1 < 0 + 1e-8
assert 1 - 1e-8 < bb.x2 < 1 + 1e-8
assert 1 - 1e-8 < bb.y2 < 1 + 1e-8
assert 0 - 1e-8 < float(bb.x1) < 0 + 1e-8
assert 0 - 1e-8 < float(bb.y1) < 0 + 1e-8
assert 1 - 1e-8 < float(bb.x2) < 1 + 1e-8
assert 1 - 1e-8 < float(bb.y2) < 1 + 1e-8

def test_triangular_polygon2(self):
poly = ia.Polygon([(0.5, 0.5), (2, 0.1), (1, 1)])
bb = poly.to_bounding_box()
assert 0.5 - 1e-8 < bb.x1 < 0.5 + 1e-8
assert 0.1 - 1e-8 < bb.y1 < 0.1 + 1e-8
assert 2.0 - 1e-8 < bb.x2 < 2.0 + 1e-8
assert 1.0 - 1e-8 < bb.y2 < 1.0 + 1e-8
assert 0.5 - 1e-8 < float(bb.x1) < 0.5 + 1e-8
assert 0.1 - 1e-8 < float(bb.y1) < 0.1 + 1e-8
assert 2.0 - 1e-8 < float(bb.x2) < 2.0 + 1e-8
assert 1.0 - 1e-8 < float(bb.y2) < 1.0 + 1e-8


class TestPolygon_to_line_string(unittest.TestCase):
Expand Down Expand Up @@ -1878,8 +1878,8 @@ def test_square_polygon(self):
poly = poly.change_first_point_by_index(start_idx)

for (x_exp, y_exp), (x_obs, y_obs) in zip(exterior, poly.exterior):
assert x_exp - 1e-8 < x_obs < x_exp + 1e-8
assert y_exp - 1e-8 < y_obs < y_exp + 1e-8
assert (x_exp - 1e-8) < float(x_obs) < (x_exp + 1e-8)
assert (y_exp - 1e-8) < float(y_obs) < (y_exp + 1e-8)

def test_polygon_with_zero_points(self):
poly_shapely = shapely.geometry.Polygon([])
Expand Down
6 changes: 4 additions & 2 deletions test/augmenters/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6253,13 +6253,15 @@ def test_other_dtypes_p_is_one_with_min_value(self):

def test_other_dtypes_p_is_one_with_max_value(self):
# with p=1.0 and max_value
aug = iaa.Invert(p=1.0, max_value=16)
dtypes = [np.uint8, np.uint16, np.uint32,
np.int8, np.int16, np.int32,
np.float16, np.float32]
for dtype in dtypes:
min_value, _center_value, _max_value = iadt.get_value_range_of_dtype(dtype)
max_value = 16

max_value = 16 if dtype != np.float16 else 15
aug = iaa.Invert(p=1.0, max_value=max_value)

kind = np.dtype(dtype).kind
center_value = min_value + 0.5 * (max_value - min_value)
image_min = np.full((3, 3), min_value, dtype=dtype)
Expand Down
2 changes: 1 addition & 1 deletion test/augmenters/test_blend.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def _allclose(a, b):
assert img_blend.shape == (3, 3, c)
assert _allclose(
img_blend,
0.75*max_float_dt(v1) + 0.25*max_float_dt(v2)
0.75*v1 + 0.25*v2
)

img_fg = np.full((3, 3, 2), v1, dtype=dtype)
Expand Down
6 changes: 4 additions & 2 deletions test/augmenters/test_flip.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,8 +784,10 @@ def test__fliplr_sliced_3d_three_channels(self):
def test__fliplr_sliced_3d_four_channels(self):
self._test__fliplr_subfunc_n_channels(fliplib._fliplr_sliced, 4)

def test__fliplr_sliced_3d_513_channels(self):
self._test__fliplr_subfunc_n_channels(fliplib._fliplr_sliced, 513)
def test__fliplr_sliced_3d_256_channels(self):
# NOTE(erjel): Why this works:
# https://docs.opencv.org/4.10.0/d0/d86/tutorial_py_image_arithmetics.html
self._test__fliplr_subfunc_n_channels(fliplib._fliplr_sliced, 256)

@classmethod
def _test__fliplr_subfunc_n_channels(cls, func, nb_channels):
Expand Down
2 changes: 1 addition & 1 deletion test/augmenters/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -4496,7 +4496,7 @@ def test_arrays_become_lists_if_augmenter_changes_shapes(self):
heatmaps = (
np.copy(base_arr)[:, :, :, np.newaxis].astype(np.float32)
/ np.max(base_arr)
)
).astype(np.float32)
segmaps = np.copy(base_arr)[:, :, :, np.newaxis].astype(np.int32)

batch_aug = aug.augment(images=images, heatmaps=heatmaps,
Expand Down
4 changes: 2 additions & 2 deletions test/augmenters/test_size.py
Original file line number Diff line number Diff line change
Expand Up @@ -3026,7 +3026,7 @@ def test_pad_other_dtypes_float_by_int_without_keep_size(self):
iadt.get_value_range_of_dtype(dtype)

def _isclose(a, b):
atol = 1e-4 if dtype == np.float16 else 1e-8
atol = 1e-4 if np.dtype(dtype) == np.float16 else 1e-8
return np.isclose(a, b, atol=atol, rtol=0)

isize = np.dtype(dtype).itemsize
Expand Down Expand Up @@ -4126,7 +4126,7 @@ def test_other_dtypes_float(self):
iadt.get_value_range_of_dtype(dtype)

def _isclose(a, b):
atol = 1e-4 if dtype == np.float16 else 1e-8
atol = 1e-4 if np.dtype(dtype) == np.float16 else 1e-8
return np.isclose(a, b, atol=atol, rtol=0)

isize = np.dtype(dtype).itemsize
Expand Down
1 change: 1 addition & 0 deletions test/test_multicore.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,7 @@ def _batch_loader_load_func():


# Note that BatchLoader is deprecated
@unittest.skipIf(sys.platform.startswith("win"), "depreciated and hangs")
class TestBatchLoader(unittest.TestCase):
def setUp(self):
reseed()
Expand Down
4 changes: 2 additions & 2 deletions test/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3811,7 +3811,7 @@ def test_pairs(self):

assert (
base ** exponent - _eps(sample)
< sample <
< float(sample) <
base ** exponent + _eps(sample)
)
assert samples.dtype.kind == "f"
Expand Down Expand Up @@ -3841,7 +3841,7 @@ def test_pairs_both_deterministic(self):

assert (
base ** exponent - _eps(sample)
< sample <
< float(sample) <
base ** exponent + _eps(sample)
)
assert samples.dtype.kind == "f"
Expand Down
Loading