Closed Rakesh4G closed 4 years ago
test_quokka
): Tiny difference between a loaded image and its expected pixel values. I assume there is a small change in e.g. some JPEG routine that leads to slightly different output values. Or it's just some float inaccuracy. I'll have to make that test a bit more tolerant.test_quokka_square
): Same as in the first test.test_pad
): That's a bug in numpy 1.17. It will likely be fixed in numpy 1.17.2. In master the test is currently deactivated.test_pool
): Looks like a small deviation for very large floats, probably with dtype float128. I expect the test would run through if float(value)
in the line where it fails was simply replaced by np.float128(value)
. I will change that in the tests.test_Rot90
): Looks like the same problem as in the fourth test. In master there is already np.float128(value)
instead of float(value)
in use.The first and second test are now a little bit looser in master and should run through. The float128(value)
was already in master. So, in theory all tests should now succeed.
The first and second test are now a little bit looser in master and should run through. The
float128(value)
was already in master. So, in theory all tests should now succeed.
Thanks. I will align my code to these changes and test.
The first and second test are now a little bit looser in master and should run through. The
float128(value)
was already in master. So, in theory all tests should now succeed.
Hi @aleju , After moving to latest commit from 0.2.9, I am getting new error message while running install tests
pytest: error: unrecognized arguments: --xdoctest
running install tests ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...] pytest: error: unrecognized arguments: --xdoctest inifile: /build/source/pytest.ini rootdir: /build/source
Please suggest. Thanks.
What command are you executing? I assume it contains --xdoctest-modules
.
You need the xdoctest
package to run the tests with --xdoctest-modules
, which verifies that all examples in the library's docstrings run without errors and produce the expected outputs. You can however remove the --xdoctest-modules
argument, then only the unittests are run, which should be enough to verify that the library works correctly.
Hi @aleju ,
initially i was just using pytest command.
now I have modified the pytest.ini
from
addopts = -p pytester -p no:doctest --xdoctest --xdoctest-global-exec="import imgaug as ia\nfrom imgaug import augmenters as iaa"
to
addopts = -p pytester -p no:doctest"
### But now it is stuck after 79%
`running install tests ============================= test session starts ============================== platform linux -- Python 3.7.4, pytest-5.1.0, py-1.8.0, pluggy-0.12.0 rootdir: /build/source, inifile: pytest.ini collected 3097 items
test/test_dtypes.py .................................................... [ 1%] ................................................................... [ 3%] test/test_imgaug.py .................................................... [ 5%] .... [ 5%] test/test_multicore.py ............................ [ 6%] test/test_parameters.py ................................................ [ 8%] ........................................................................ [ 10%] ........................................................................ [ 12%] ........................................................................ [ 15%] ....................................... [ 16%] test/test_random.py .................................................... [ 18%] ........................................................................ [ 20%] ........................... [ 21%] test/augmentables/test_batches.py ...... [ 21%] test/augmentables/test_bbs.py .......................................... [ 22%] .............................................................. [ 24%] test/augmentables/test_heatmaps.py ......................... [ 25%] test/augmentables/test_kps.py .......................................... [ 26%] ............................... [ 27%] test/augmentables/test_lines.py ........................................ [ 29%] ........................................................................ [ 31%] ........................................................................ [ 33%] .......................... [ 34%] test/augmentables/test_normalization.py ...................... [ 35%] test/augmentables/test_polys.py ........................................ [ 36%] ........................................................................ [ 39%] ........................................................................ [ 41%] ................................................................... [ 43%] test/augmentables/test_segmaps.py ...................................... [ 44%] ... [ 44%] test/augmentables/test_utils.py ................... [ 45%] test/augmenters/test_arithmetic.py ..................................... [ 46%] ........................................................................ [ 48%] ...................................... [ 50%] test/augmenters/test_blend.py .......................................... [ 51%] .................................... [ 52%] test/augmenters/test_blur.py ........................................... [ 54%] ......... [ 54%] test/augmenters/test_color.py .......................................... [ 55%] ........................................................ [ 57%] test/augmenters/test_contrast.py ....................................... [ 58%] ........................... [ 59%] test/augmenters/test_convolutional.py .................................. [ 60%] ........... [ 61%] test/augmenters/test_edges.py ...................... [ 61%] test/augmenters/test_flip.py ........................................... [ 63%] ............................................... [ 64%] test/augmenters/test_geometric.py ...................................... [ 65%] ........................................................................ [ 68%] ........................................................................ [ 70%] ........................................................................ [ 72%] ........................................................................ [ 75%] ............. [ 75%] test/augmenters/test_meta.py ........................................... [ 77%] ........................................................................ [ 79%]
`
Please suggest.
Thanks.
I usually use the command python -m pytest test/ --verbose --xdoctest-modules -s --durations=20
which shows exactly which tests were executed, not just the files.
I can't tell exactly where it hangs as there is no corresponding output. Even if there was, it would probably be hard to debug it from the distance.
My guess would be that it is somehow connected to multiprocessing (though it is weird that the tests of multicore.py
all passed). I would try commenting out the tests test_augment_batches_background
and test_augment_batches_with_many_different_augmenters
in test_meta.py
and see if it then works. But that would just show in which test it fails, not in which line and especially what the root cause of the issue is.
Hi @aleju , Please find last output of imgaug unit test. imgaug_nix_hang_state.txt
test/augmenters/test_meta.py::TestAugmenter::test_localize_random_state PASSED test/augmenters/test_meta.py::TestAugmenter::test_reseed PASSED test/augmenters/test_meta.py::TestAugmenter::test_reseed_deterministic_too PASSED test/augmenters/test_meta.py::TestAugmenter::test_reseed_with_rng PASSED test/augmenters/test_meta.py::TestAugmenter::test_reseed_with_seed PASSED test/augmenters/test_meta.py::TestAugmenter_augment_batches::test_augment_batches_background PASSED test/augmenters/test_meta.py::TestAugmenter_augment_batches::test_augment_batches_batch_with_array_of_images PASSED test/augmenters/test_meta.py::TestAugmenter_augment_batches::test_augment_batches_batch_with_list_of_images PASSED test/augmenters/test_meta.py::TestAugmenter_augment_batches::test_augment_batches_invalid_datatype PASSED test/augmenters/test_meta.py::TestAugmenter_augment_batches::test_augment_batches_list_of_arrays_deprecated PASSED test/augmenters/test_meta.py::TestAugmenter_augment_batches::test_augment_batches_list_of_empty_list_deprecated PASSED test/augmenters/test_meta.py::TestAugmenter_augment_batches::test_augment_batches_list_of_invalid_datatype PASSED test/augmenters/test_meta.py::TestAugmenter_augment_batches::test_augment_batches_list_of_list_of_arrays_deprecated PASSED test/augmenters/test_meta.py::TestAugmenter_augment_batches::test_augment_batches_list_of_list_of_invalid_datatype PASSED
Please note that we donot have support for xdoctest on NixOS at present so I am removing --xdoctest-modules
from above command.
Thanks.
Hm, I thought that command showed the name of test currently being executed, but apparently it does so only after the test has fully run through. It also doesn't follow the order in which the tests were defined in the file. That makes things a bit harder. At least I can see that it fails at TestAugmenter_augment_batches
, which is what I suspected initially. It succeeds with test_augment_batches_background
, but test_augment_batches_with_many_different_augmenters
is not shown as passed, which makes that test the most likely cause of the problem.
I would try now python -m pytest ./test/augmenters/test_meta.py::TestAugmenter_augment_batches::test_augment_batches_with_many_different_augmenters --verbose --xdoctest-modules -s --durations=20
to only exectute the mentioned test and see if that command hangs. If that is the case, I would change within the test test_augment_batches_with_many_different_augmenters
in test/augmenters/test_meta.py
for aug in augs:
nb_changed = 0
to
for aug in augs:
print(aug.name)
nb_changed = 0
and then run the above pytest
command again. It should usually print something. In case it doesn't, it would mean that it only prints once the test fully ran through, which it never does here. In that case I would start with the following steps below.
Step 1: Remove the block
iaa.Lambda(
func_images=lambda images, random_state, parents, hooks: images,
func_keypoints=lambda keypoints_on_images, random_state,
parents, hooks: keypoints_on_images,
name="Lambda-nochange"
),
iaa.AssertLambda(
func_images=lambda images, random_state, parents, hooks: True,
func_keypoints=lambda keypoints_on_images, random_state,
parents, hooks: True,
name="AssertLambda-nochange"
),
from the test. Lambda functions can sometimes cause problems in connections with multiprocessing. Try the pytest
command again.
Step 2:
If the test still hangs, I would then also remove iaa.Convolve(...)
, iaa.Sharpen(...)
, iaa.Emboss(...)
, iaa.EdgeDetect(...)
and iaa.DirectedEdgeDetect(...)
. In older commits of master these still use lambda functions in the background and could also cause issues. Try pytest
again.
Step 3:
Try to remove the remaining augmenters one by one, running pytest
again each time, until the culprit is found.
Btw, how long do you wait for the test to finish? It does take a few seconds on my machine.
Hm, I thought that command showed the name of test currently being executed, but apparently it does so only after the test has fully run through. It also doesn't follow the order in which the tests were defined in the file. That makes things a bit harder. At least I can see that it fails at
TestAugmenter_augment_batches
, which is what I suspected initially. It succeeds withtest_augment_batches_background
, buttest_augment_batches_with_many_different_augmenters
is not shown as passed, which makes that test the most likely cause of the problem.
Hi @aleju ,
I have taken latest 0.3.0 changes.
As per my observation the execution order is alphabetic here.
Yes, it is test_augment_batches_with_many_different_augmenters
is the one which is stuck.
But behaviour is different when executed differently.
I mean if try to run
test/augmenters/test_meta.py::TestAugmenter_augment_batches::test_augment_batches_with_many_different_augmenters
- Pass
test/augmenters/test_meta.py::TestAugmenter_augment_batches
- Pass
test/augmenters/test_meta.py
- Pass
Pass logs : imgaug_test_meta_py_pass.txt
test/augmenters
- Hangs on test_augment_batches_with_many_different_augmenters
based on assumption that tests are run in alphabetic order.
I had waited for more than 1 hour and test is still stuck.
Please suggest.
Thanks.
Hi @aleju , Another input in case it helps:
I had tried to run all files under augmenters in two orders:
Original Order : Hang on test_augment_batches_with_many_different_augmenters
python -m pytest ./test/augmenters/test_arithmetic.py ./test/augmenters/test_blend.py ./test/augmenters/test_blur.py ./test/augmenters/test_color.py ./test/augmenters/test_contrast.py ./test/augmenters/test_convolutional.py ./test/augmenters/test_edges.py ./test/augmenters/test_flip.py ./test/augmenters/test_geometric.py ./test/augmenters/test_meta.py ./test/augmenters/test_mixed_files.py ./test/augmenters/test_overlay.py ./test/augmenters/test_pooling.py ./test/augmenters/test_segmentation.py ./test/augmenters/test_size.py ./test/augmenters/test_weather.py --verbose -s --durations=20
test_meta.py moved to front: PASS
python -m pytest ./test/augmenters/test_meta.py ./test/augmenters/test_arithmetic.py ./test/augmenters/test_blend.py ./test/augmenters/test_blur.py ./test/augmenters/test_color.py ./test/augmenters/test_contrast.py ./test/augmenters/test_convolutional.py ./test/augmenters/test_edges.py ./test/augmenters/test_flip.py ./test/augmenters/test_geometric.py ./test/augmenters/test_mixed_files.py ./test/augmenters/test_overlay.py ./test/augmenters/test_pooling.py ./test/augmenters/test_segmentation.py ./test/augmenters/test_size.py ./test/augmenters/test_weather.py --verbose -s --durations=20
Result with test_meta.py moved to front:
-- Docs: https://docs.pytest.org/en/latest/warnings.html ========================== slowest 20 test durations =========================== 15.17s call test/augmenters/test_meta.py::TestAugmenter_augment_batches::test_augment_batches_with_many_different_augmenters 6.01s call test/augmenters/test_mixed_files.py::test_keypoint_augmentation 4.82s call test/augmenters/test_mixed_files.py::test_determinism 3.33s call test/augmenters/test_geometric.py::test_AffineCv2 2.38s call test/augmenters/test_geometric.py::TestPiecewiseAffine::test_other_dtypes_uint_int 2.11s call test/augmenters/test_meta.py::TestAugmenter_augment_batches::test_augment_batches_background 1.37s call test/augmenters/test_geometric.py::TestPiecewiseAffine::test_nb_cols_is_list_affects_images 1.18s call test/augmenters/test_meta.py::TestAugmenter::test_augment_keypoints_aligned_despite_nongeometric_image_ops 1.12s call test/augmenters/test_geometric.py::TestPiecewiseAffine::test_other_dtypes_float 1.12s call test/augmenters/test_geometric.py::TestPiecewiseAffine::test_nb_rows_is_list_affects_images 1.07s call test/augmenters/test_geometric.py::TestPiecewiseAffine::test_scale_is_list 1.00s call test/augmenters/test_mixed_files.py::test_dtype_preservation 1.00s call test/augmenters/test_mixed_files.py::test_unusual_channel_numbers 0.97s call test/augmenters/test_arithmetic.py::TestAdd::test_uint8_every_possible_value 0.92s call test/augmenters/test_blur.py::TestGaussianBlur::test_sigma_is_tuple 0.67s call test/augmenters/test_blend.py::TestAlpha::test_images_factor_is_tuple 0.60s call test/augmenters/test_geometric.py::TestAffine_other_dtypes::test_rotate_skimage_order_not_0_uint_int 0.59s call test/augmenters/test_flip.py::TestFlipud::test_polygons_p_is_050 0.59s call test/augmenters/test_flip.py::TestFliplr::test_polygons_p_is_050 0.59s call test/augmenters/test_geometric.py::TestAffine_translate::test_image_translate_by_axiswise_uniform_distributions ============ 1869 passed, 2 skipped, 1 warnings in 91.77s (0:01:31) ============
So it might be due to improper/in-complete clean-up from one of the previous file's execution.
Thanks.
I had waited for more than 1 hour and test is still stuck.
Yes, that is way beyond the expected timeframe. On my machine it takes a few seconds. On a slow laptop maybe 30s.
The observed hanging is very weird. Among all test files, I think only test_multicore.py
and test_meta.py
use the multiprocessing module and latter one is not run in your case. So there shouldn't be anything messing up the multiprocessing stuff. Most augmenters also don't cache any data. Only very few do and the cached data consists only of numpy arrays. No explicit cleanup should be necessary there either... That increases the probability that it is somehow caused by something that numpy or OpenCV do internally or by NixOS behaving slightly different compared to what python's multiprocessing expects.
Some things I would do here to pinpoint the problem:
1) Run each of the test commands that you mentioned a handful of times to ensure that the results are consistent.
2) In the command that you ran that hangs, move test_meta.py
one step earlier in the list of executed files and see if the command then succeeds. Repeat until it succeeds. Run each command a handful of times to exclude that its up to random chance when it hangs.
3) In test_meta.py
, function test_augment_batches_with_many_different_augmenters()
in list augs = [(...)]
comment out all augmenters and see if the test succeeds. Then reactivate each one of them one by one until it fails and see which augmenter that is. Also then check if that is the only augmenter that makes it fail.
4) In test_meta.py
in test_augment_batches_with_many_different_augmenters()
add import cv2; cv2.setNumThreads(1)
at the very start of the function and see if the hanging stops.
5) Upgrade numpy to 1.17 if that hasn't been done yet. Otherwise downgrade from 1.17 to 1.16 and see if it works then. 1.17 introduced various changes to the random number sampling.
I have now seen similar behaviour. In my case it was caused by an exception in a subprocess that for some reason was not raised into the main process, even though multiprocessing
should do that. ctrl+c
showed the error however.
Can you copy-paste the following code block into a file, run it and post the output. If it hangs again, ctrl+c
and post the full stacktrace -- it might contain two separate errors.
import six.moves as sm
import numpy as np
import imgaug as ia
import imgaug.augmenters as iaa
for background in [False, True]:
image = np.array([[0, 0, 1, 1, 1],
[0, 0, 1, 1, 1],
[0, 1, 1, 1, 1]], dtype=np.uint8)
keypoint = ia.Keypoint(x=2, y=1)
keypoints = [ia.KeypointsOnImage([keypoint], shape=image.shape + (1,))]
def _lambda_func_images(images, random_state, parents, hooks):
return images
def _lambda_func_keypoints(keypoints_on_images, random_state,
parents, hooks):
return keypoints_on_images
def _assertlambda_func_images(images, random_state, parents, hooks):
return True
def _assertlambda_func_keypoints(keypoints_on_images, random_state, parents, hooks):
return True
augs = [
iaa.Sequential([iaa.Fliplr(1.0), iaa.Flipud(1.0)]),
iaa.SomeOf(1, [iaa.Fliplr(1.0), iaa.Flipud(1.0)]),
iaa.OneOf([iaa.Fliplr(1.0), iaa.Flipud(1.0)]),
iaa.Sometimes(1.0, iaa.Fliplr(1)),
iaa.WithColorspace("HSV", children=iaa.Add((-50, 50))),
iaa.WithChannels([0], iaa.Add((-50, 50))),
iaa.Noop(name="Noop-nochange"),
iaa.Lambda(
func_images=_lambda_func_images,
func_keypoints=_lambda_func_keypoints,
name="Lambda-nochange"
),
iaa.AssertLambda(
func_images=_assertlambda_func_images,
func_keypoints=_assertlambda_func_keypoints,
name="AssertLambda-nochange"
),
iaa.AssertShape(
(None, 64, 64, 3),
check_keypoints=False,
name="AssertShape-nochange"
),
iaa.Resize((0.5, 0.9)),
iaa.CropAndPad(px=(-50, 50)),
iaa.Pad(px=(1, 50)),
iaa.Crop(px=(1, 50)),
iaa.Fliplr(1.0),
iaa.Flipud(1.0),
iaa.Superpixels(p_replace=(0.25, 1.0), n_segments=(16, 128)),
iaa.ChangeColorspace(to_colorspace="GRAY"),
iaa.Grayscale(alpha=(0.1, 1.0)),
iaa.GaussianBlur(1.0),
iaa.AverageBlur(5),
iaa.MedianBlur(5),
iaa.Convolve(np.array([[0, 1, 0],
[1, -4, 1],
[0, 1, 0]])),
iaa.Sharpen(alpha=(0.1, 1.0), lightness=(0.8, 1.2)),
iaa.Emboss(alpha=(0.1, 1.0), strength=(0.8, 1.2)),
iaa.EdgeDetect(alpha=(0.1, 1.0)),
iaa.DirectedEdgeDetect(alpha=(0.1, 1.0), direction=(0.0, 1.0)),
iaa.Add((-50, 50)),
iaa.AddElementwise((-50, 50)),
iaa.AdditiveGaussianNoise(scale=(0.1, 1.0)),
iaa.Multiply((0.6, 1.4)),
iaa.MultiplyElementwise((0.6, 1.4)),
iaa.Dropout((0.3, 0.5)),
iaa.CoarseDropout((0.3, 0.5), size_percent=(0.05, 0.2)),
iaa.Invert(0.5),
iaa.Affine(
scale=(0.7, 1.3),
translate_percent=(-0.1, 0.1),
rotate=(-20, 20),
shear=(-20, 20),
order=ia.ALL,
mode=ia.ALL,
cval=(0, 255)),
iaa.PiecewiseAffine(scale=(0.1, 0.3)),
iaa.ElasticTransformation(alpha=0.5)
]
nb_iterations = 100
image = ia.quokka(size=(64, 64))
batches = [ia.Batch(images=[np.copy(image)],
keypoints=[keypoints[0].deepcopy()])
for _ in sm.xrange(nb_iterations)]
for aug in augs:
print("[bg=%s] Running %s..." % (background, aug.name))
nb_changed = 0
batches_aug = list(aug.augment_batches(batches, background=background))
for batch_aug in batches_aug:
image_aug = batch_aug.images_aug[0]
if (image.shape != image_aug.shape
or not np.array_equal(image, image_aug)):
nb_changed += 1
if nb_changed > 10:
break
if "-nochange" not in aug.name:
assert nb_changed > 0
else:
assert nb_changed == 0
Hi @aleju ,
For me it is stuck at :
---- [bg=True] Running UnnamedChangeColorspace... [bg=True] Running UnnamedGrayscale... [bg=True] Running UnnamedGaussianBlur...
Thanks.
@aleju Any news on this?
Sorry, didn't have much time the last couple of days, so this issue was delayed a bit. Based on the outputs my best guess is that OpenCV causes issues when being executed in a subprocess, as the method that hangs uses OpenCV. (Which would also mean that any user trying to call OpenCV in a subprocess might encounter this issue, even without using imgaug.)
I have seen something like that before and it was fixed using cv2.setNumThreads(0)
. Can you try the two code blocks below and see if any of them works? Also, did ctrl+c
work and produce any outputs?
With setNumThreads(0)
:
import six.moves as sm
import numpy as np
import imgaug as ia
import imgaug.augmenters as iaa
import os
import platform
import cv2
cv2.setNumThreads(0)
print(os.name)
print(platform.system())
print(platform.release())
for iteration, background in enumerate([False, False, False,
True, True, True]):
image = np.array([[0, 0, 1, 1, 1],
[0, 0, 1, 1, 1],
[0, 1, 1, 1, 1]], dtype=np.uint8)
keypoint = ia.Keypoint(x=2, y=1)
keypoints = [ia.KeypointsOnImage([keypoint], shape=image.shape + (1,))]
def _lambda_func_images(images, random_state, parents, hooks):
return images
def _lambda_func_keypoints(keypoints_on_images, random_state,
parents, hooks):
return keypoints_on_images
def _assertlambda_func_images(images, random_state, parents, hooks):
return True
def _assertlambda_func_keypoints(keypoints_on_images, random_state, parents, hooks):
return True
augs = [
iaa.Sequential([iaa.Fliplr(1.0), iaa.Flipud(1.0)]),
iaa.SomeOf(1, [iaa.Fliplr(1.0), iaa.Flipud(1.0)]),
iaa.OneOf([iaa.Fliplr(1.0), iaa.Flipud(1.0)]),
iaa.Sometimes(1.0, iaa.Fliplr(1)),
iaa.WithColorspace("HSV", children=iaa.Add((-50, 50))),
iaa.WithChannels([0], iaa.Add((-50, 50))),
iaa.Noop(name="Noop-nochange"),
iaa.Lambda(
func_images=_lambda_func_images,
func_keypoints=_lambda_func_keypoints,
name="Lambda-nochange"
),
iaa.AssertLambda(
func_images=_assertlambda_func_images,
func_keypoints=_assertlambda_func_keypoints,
name="AssertLambda-nochange"
),
iaa.AssertShape(
(None, 64, 64, 3),
check_keypoints=False,
name="AssertShape-nochange"
),
iaa.Resize((0.5, 0.9)),
iaa.CropAndPad(px=(-50, 50)),
iaa.Pad(px=(1, 50)),
iaa.Crop(px=(1, 50)),
iaa.Fliplr(1.0),
iaa.Flipud(1.0),
iaa.Superpixels(p_replace=(0.25, 1.0), n_segments=(16, 128)),
iaa.ChangeColorspace(to_colorspace="GRAY"),
iaa.Grayscale(alpha=(0.1, 1.0)),
iaa.GaussianBlur(1.0),
iaa.AverageBlur(5),
iaa.MedianBlur(5),
iaa.Convolve(np.array([[0, 1, 0],
[1, -4, 1],
[0, 1, 0]])),
iaa.Sharpen(alpha=(0.1, 1.0), lightness=(0.8, 1.2)),
iaa.Emboss(alpha=(0.1, 1.0), strength=(0.8, 1.2)),
iaa.EdgeDetect(alpha=(0.1, 1.0)),
iaa.DirectedEdgeDetect(alpha=(0.1, 1.0), direction=(0.0, 1.0)),
iaa.Add((-50, 50)),
iaa.AddElementwise((-50, 50)),
iaa.AdditiveGaussianNoise(scale=(0.1, 1.0)),
iaa.Multiply((0.6, 1.4)),
iaa.MultiplyElementwise((0.6, 1.4)),
iaa.Dropout((0.3, 0.5)),
iaa.CoarseDropout((0.3, 0.5), size_percent=(0.05, 0.2)),
iaa.Invert(0.5),
iaa.Affine(
scale=(0.7, 1.3),
translate_percent=(-0.1, 0.1),
rotate=(-20, 20),
shear=(-20, 20),
order=ia.ALL,
mode=ia.ALL,
cval=(0, 255)),
iaa.PiecewiseAffine(scale=(0.1, 0.3)),
iaa.ElasticTransformation(alpha=0.5)
]
nb_iterations = 100
image = ia.quokka(size=(64, 64))
batches = [ia.Batch(images=[np.copy(image)],
keypoints=[keypoints[0].deepcopy()])
for _ in sm.xrange(nb_iterations)]
for aug in augs:
print("[#%d bg=%s] Running %s..." % (iteration, background, aug.name))
nb_changed = 0
batches_aug = list(aug.augment_batches(batches, background=background))
for batch_aug in batches_aug:
image_aug = batch_aug.images_aug[0]
if (image.shape != image_aug.shape
or not np.array_equal(image, image_aug)):
nb_changed += 1
if nb_changed > 10:
break
if "-nochange" not in aug.name:
assert nb_changed > 0
else:
assert nb_changed == 0
With set_start_method("spawn")
(this may take 5mins or so to finish):
import six.moves as sm
import numpy as np
import imgaug as ia
import imgaug.augmenters as iaa
import os
import platform
import multiprocessing
def main():
print(os.name)
print(platform.system())
print(platform.release())
multiprocessing.set_start_method("spawn")
for iteration, background in enumerate([False, False, False,
True, True, True]):
image = np.array([[0, 0, 1, 1, 1],
[0, 0, 1, 1, 1],
[0, 1, 1, 1, 1]], dtype=np.uint8)
keypoint = ia.Keypoint(x=2, y=1)
keypoints = [ia.KeypointsOnImage([keypoint], shape=image.shape + (1,))]
augs = [
iaa.Sequential([iaa.Fliplr(1.0), iaa.Flipud(1.0)]),
iaa.SomeOf(1, [iaa.Fliplr(1.0), iaa.Flipud(1.0)]),
iaa.OneOf([iaa.Fliplr(1.0), iaa.Flipud(1.0)]),
iaa.Sometimes(1.0, iaa.Fliplr(1)),
iaa.WithColorspace("HSV", children=iaa.Add((-50, 50))),
iaa.WithChannels([0], iaa.Add((-50, 50))),
iaa.Noop(name="Noop-nochange"),
iaa.Lambda(
func_images=_lambda_func_images,
func_keypoints=_lambda_func_keypoints,
name="Lambda-nochange"
),
#iaa.AssertLambda(
# func_images=_assertlambda_func_images,
# func_keypoints=_assertlambda_func_keypoints,
# name="AssertLambda-nochange"
#),
#iaa.AssertShape(
# (None, 64, 64, 3),
# check_keypoints=False,
# name="AssertShape-nochange"
#),
iaa.Resize((0.5, 0.9)),
iaa.CropAndPad(px=(-50, 50)),
iaa.Pad(px=(1, 50)),
iaa.Crop(px=(1, 50)),
iaa.Fliplr(1.0),
iaa.Flipud(1.0),
iaa.Superpixels(p_replace=(0.25, 1.0), n_segments=(16, 128)),
iaa.ChangeColorspace(to_colorspace="GRAY"),
iaa.Grayscale(alpha=(0.1, 1.0)),
iaa.GaussianBlur(1.0),
iaa.AverageBlur(5),
iaa.MedianBlur(5),
iaa.Convolve(np.array([[0, 1, 0],
[1, -4, 1],
[0, 1, 0]])),
iaa.Sharpen(alpha=(0.1, 1.0), lightness=(0.8, 1.2)),
iaa.Emboss(alpha=(0.1, 1.0), strength=(0.8, 1.2)),
iaa.EdgeDetect(alpha=(0.1, 1.0)),
iaa.DirectedEdgeDetect(alpha=(0.1, 1.0), direction=(0.0, 1.0)),
iaa.Add((-50, 50)),
iaa.AddElementwise((-50, 50)),
iaa.AdditiveGaussianNoise(scale=(0.1, 1.0)),
iaa.Multiply((0.6, 1.4)),
iaa.MultiplyElementwise((0.6, 1.4)),
iaa.Dropout((0.3, 0.5)),
iaa.CoarseDropout((0.3, 0.5), size_percent=(0.05, 0.2)),
iaa.Invert(0.5),
iaa.Affine(
scale=(0.7, 1.3),
translate_percent=(-0.1, 0.1),
rotate=(-20, 20),
shear=(-20, 20),
order=ia.ALL,
mode=ia.ALL,
cval=(0, 255)),
iaa.PiecewiseAffine(scale=(0.1, 0.3)),
iaa.ElasticTransformation(alpha=0.5)
]
nb_iterations = 100
image = ia.quokka(size=(64, 64))
batches = [ia.Batch(images=[np.copy(image)],
keypoints=[keypoints[0].deepcopy()])
for _ in sm.xrange(nb_iterations)]
for aug in augs:
print("[#%d bg=%s] Running %s..." % (iteration, background, aug.name))
nb_changed = 0
batches_aug = list(aug.augment_batches(batches, background=background))
for batch_aug in batches_aug:
image_aug = batch_aug.images_aug[0]
if (image.shape != image_aug.shape
or not np.array_equal(image, image_aug)):
nb_changed += 1
if nb_changed > 10:
break
if "-nochange" not in aug.name:
assert nb_changed > 0
else:
assert nb_changed == 0
def _lambda_func_images(images, random_state, parents, hooks):
return images
def _lambda_func_keypoints(keypoints_on_images, random_state,
parents, hooks):
return keypoints_on_images
def _assertlambda_func_images(images, random_state, parents, hooks):
return True
def _assertlambda_func_keypoints(keypoints_on_images, random_state, parents, hooks):
return True
if __name__ == "__main__":
main()
Thanks @aleju , I will update you after trying the above mentioned changes.
Hi @aleju , Please find attached the output of above two executions (Block1 and Block2).
Block1 was stuck, but Block2 ran without any issues.
block1_debug_output.txt block2_debug_output.txt
Also i did not get anything after pressing ctrl+c in my environment.
Thanks, Rakesh
Hi @aleju , Did you a get a chance to look into this? Thanks.
Yes... but as far as I can see, while the second set of tests ran through, it doesn't seem like the library can identify that it is running in NixOS and then conditionally use spawn
mode for multiprocessing
. The spawn
mode seems to be too slow to activate it for all systems (and probably also needs too much memory), so that simple solution isn't an option.
The first set of tests further hang at a different augmenter this time than previously and that augmenter does not use OpenCV but instead scikit-image. It might be that scikit-image uses OpenCV in the background, but I didn't see it when looking through the code. That makes it fairly unlikely that it is an OpenCV issue and more likely that it is a problem or slight behaviour change in the multiprocessing
component in NixOS.
Basically I will have to install the OS on an old laptop and see if I can find the issue and fix it in a way that other systems are not affected. That's fairly time intensive and has a high risk of no succeeding, which is why I postponed that so far.
Hi @aleju , Thanks. If you can suggest the change needed to get this going (what and where), then we can patch it specific for NixOS in our derivations. This will make it usable for us as well.
FYI, we are successfully using imgaug on NixOS environments with no problems. It's just the tests here failing.
FYI, we are successfully using imgaug on NixOS environments with no problems. It's just the tests here failing.
Only the tests involving multiprocessing
are failing. If you don't use any multicore augmentation (i.e. augment_batch(..., background=True)
or <augmenter>.pool()
or imgaug.multicore.Pool
), everything should work fine. Even when using these components it might work in real life applications, as the hanging seems to happen unpredictably, so it is unclear what actually causes it.
If you can suggest the change needed to get this going (what and where), then we can patch it specific for NixOS in our derivations. This will make it usable for us as well.
Do you mean patching NixOS or a fork of imgaug? I had hoped that os.name
, platform.system()
or platform.release()
would contain the string NixOS
somewhere, so that I can switch to spawn method for that OS. It wouldn't be a great solution as it doesn't really fix the underlying issue but simply avoids it, but at least it would work for now.
@aleju thanks for all the help to the NixOS community! Really appreciate your efforts. Just chiming in that platform.uname()
may be a good option:
>>> platform.uname()
uname_result(system='Linux', node='lensman', release='4.19.84', version='#1-NixOS SMP Tue Nov 12 18:21:46 UTC 2019', machine='x86_64', processor='')
Ah, didn't know about platform.uname().version
. Thanks for pointing that out.
This adjusted test might work then and shouldn't break anything for other OS:
import six.moves as sm
import numpy as np
import imgaug as ia
import imgaug.augmenters as iaa
import os
import platform
import multiprocessing
def main():
print(os.name)
print(platform.system())
print(platform.release())
print(platform.version())
if "NixOS" in platform.version():
multiprocessing.set_start_method("spawn")
for iteration, background in enumerate([False, False, False,
True, True, True]):
image = np.array([[0, 0, 1, 1, 1],
[0, 0, 1, 1, 1],
[0, 1, 1, 1, 1]], dtype=np.uint8)
keypoint = ia.Keypoint(x=2, y=1)
keypoints = [ia.KeypointsOnImage([keypoint], shape=image.shape + (1,))]
augs = [
iaa.Sequential([iaa.Fliplr(1.0), iaa.Flipud(1.0)]),
iaa.SomeOf(1, [iaa.Fliplr(1.0), iaa.Flipud(1.0)]),
iaa.OneOf([iaa.Fliplr(1.0), iaa.Flipud(1.0)]),
iaa.Sometimes(1.0, iaa.Fliplr(1)),
iaa.WithColorspace("HSV", children=iaa.Add((-50, 50))),
iaa.WithChannels([0], iaa.Add((-50, 50))),
iaa.Noop(name="Noop-nochange"),
iaa.Lambda(
func_images=_lambda_func_images,
func_keypoints=_lambda_func_keypoints,
name="Lambda-nochange"
),
#iaa.AssertLambda(
# func_images=_assertlambda_func_images,
# func_keypoints=_assertlambda_func_keypoints,
# name="AssertLambda-nochange"
#),
#iaa.AssertShape(
# (None, 64, 64, 3),
# check_keypoints=False,
# name="AssertShape-nochange"
#),
iaa.Resize((0.5, 0.9)),
iaa.CropAndPad(px=(-50, 50)),
iaa.Pad(px=(1, 50)),
iaa.Crop(px=(1, 50)),
iaa.Fliplr(1.0),
iaa.Flipud(1.0),
iaa.Superpixels(p_replace=(0.25, 1.0), n_segments=(16, 128)),
iaa.ChangeColorspace(to_colorspace="GRAY"),
iaa.Grayscale(alpha=(0.1, 1.0)),
iaa.GaussianBlur(1.0),
iaa.AverageBlur(5),
iaa.MedianBlur(5),
iaa.Convolve(np.array([[0, 1, 0],
[1, -4, 1],
[0, 1, 0]])),
iaa.Sharpen(alpha=(0.1, 1.0), lightness=(0.8, 1.2)),
iaa.Emboss(alpha=(0.1, 1.0), strength=(0.8, 1.2)),
iaa.EdgeDetect(alpha=(0.1, 1.0)),
iaa.DirectedEdgeDetect(alpha=(0.1, 1.0), direction=(0.0, 1.0)),
iaa.Add((-50, 50)),
iaa.AddElementwise((-50, 50)),
iaa.AdditiveGaussianNoise(scale=(0.1, 1.0)),
iaa.Multiply((0.6, 1.4)),
iaa.MultiplyElementwise((0.6, 1.4)),
iaa.Dropout((0.3, 0.5)),
iaa.CoarseDropout((0.3, 0.5), size_percent=(0.05, 0.2)),
iaa.Invert(0.5),
iaa.Affine(
scale=(0.7, 1.3),
translate_percent=(-0.1, 0.1),
rotate=(-20, 20),
shear=(-20, 20),
order=ia.ALL,
mode=ia.ALL,
cval=(0, 255)),
iaa.PiecewiseAffine(scale=(0.1, 0.3)),
iaa.ElasticTransformation(alpha=0.5)
]
nb_iterations = 100
image = ia.quokka(size=(64, 64))
batches = [ia.Batch(images=[np.copy(image)],
keypoints=[keypoints[0].deepcopy()])
for _ in sm.xrange(nb_iterations)]
for aug in augs:
print("[#%d bg=%s] Running %s..." % (iteration, background, aug.name))
nb_changed = 0
batches_aug = list(aug.augment_batches(batches, background=background))
for batch_aug in batches_aug:
image_aug = batch_aug.images_aug[0]
if (image.shape != image_aug.shape
or not np.array_equal(image, image_aug)):
nb_changed += 1
if nb_changed > 10:
break
if "-nochange" not in aug.name:
assert nb_changed > 0
else:
assert nb_changed == 0
def _lambda_func_images(images, random_state, parents, hooks):
return images
def _lambda_func_keypoints(keypoints_on_images, random_state,
parents, hooks):
return keypoints_on_images
def _assertlambda_func_images(images, random_state, parents, hooks):
return True
def _assertlambda_func_keypoints(keypoints_on_images, random_state, parents, hooks):
return True
if __name__ == "__main__":
main()
Thanks @aleju @tbenst .
I have tried the code snippet shared above. This works fine without any issues on my system. debug_output_with_NixOS_check.txt
`running install tests posix Linux 4.19.80
[#0 bg=False] Running UnnamedSequential... [#0 bg=False] Running UnnamedSomeOf... [#0 bg=False] Running UnnamedOneOf... .. .. [#4 bg=True] Running UnnamedElasticTransformation... [#5 bg=True] Running UnnamedSequential... [#5 bg=True] Running UnnamedSomeOf... [#5 bg=True] Running UnnamedOneOf... [#5 bg=True] Running UnnamedSometimes... [#5 bg=True] Running UnnamedWithColorspace... [#5 bg=True] Running UnnamedWithChannels... [#5 bg=True] Running Noop-nochange... [#5 bg=True] Running Lambda-nochange... [#5 bg=True] Running UnnamedResize... [#5 bg=True] Running UnnamedCropAndPad... [#5 bg=True] Running UnnamedPad... [#5 bg=True] Running UnnamedCrop... [#5 bg=True] Running UnnamedFliplr... [#5 bg=True] Running UnnamedFlipud... [#5 bg=True] Running UnnamedSuperpixels... [#5 bg=True] Running UnnamedChangeColorspace... [#5 bg=True] Running UnnamedGrayscale... [#5 bg=True] Running UnnamedGaussianBlur... [#5 bg=True] Running UnnamedAverageBlur... [#5 bg=True] Running UnnamedMedianBlur... [#5 bg=True] Running UnnamedConvolve... [#5 bg=True] Running UnnamedSharpen... [#5 bg=True] Running UnnamedEmboss... [#5 bg=True] Running UnnamedEdgeDetect... [#5 bg=True] Running UnnamedDirectedEdgeDetect... [#5 bg=True] Running UnnamedAdd... [#5 bg=True] Running UnnamedAddElementwise... [#5 bg=True] Running UnnamedAdditiveGaussianNoise... [#5 bg=True] Running UnnamedMultiply... [#5 bg=True] Running UnnamedMultiplyElementwise... [#5 bg=True] Running UnnamedDropout... [#5 bg=True] Running UnnamedCoarseDropout... [#5 bg=True] Running UnnamedInvert... [#5 bg=True] Running UnnamedAffine... [#5 bg=True] Running UnnamedPiecewiseAffine... [#5 bg=True] Running UnnamedElasticTransformation... pythonCatchConflictsPhase pythonRemoveBinBytecodePhase pythonImportsCheckPhase Executing pythonImportsCheckPhase pytestcachePhase`
I just merged a patch into master that hopefully fixes the issue. Can you check if the tests run successfully with that version?
I just merged a patch into master that hopefully fixes the issue. Can you check if the tests run successfully with that version?
Thanks. @aleju . I will check and update the outcome.
Thanks @aleju . Tests are executed without any issues on this version.
Thanks @aleju . Tests are executed without any issues on this version.
Hi @aleju , I am again facing this issue. I am debugging on my end, in case I have missed anything. Thanks.
Hi @aleju , sorry for inconvenience. But last time when i reported there was some problem on my branch that caused weird behaviour.
The current state is from master:
When the tests started we get this error:
test/test_multicore.py::TestPool::test_augmentations_with_seed_match Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/nix/store/drr8qcgiccfc5by09r5zc30flgwh1mbx-python3-3.7.5/lib/python3.7/multiprocessing/spawn.py", line 105, in spawn_main
exitcode = _main(fd)
File "/nix/store/drr8qcgiccfc5by09r5zc30flgwh1mbx-python3-3.7.5/lib/python3.7/multiprocessing/spawn.py", line 115, in _main
self = reduction.pickle.load(from_parent)
File "/build/imgaug-c268d368f9caeb46d8df4fe73f8f7c988c97dcba/imgaug/multicore.py", line 48, in <module>
_switch_to_spawn_if_nixos()
File "/build/imgaug-c268d368f9caeb46d8df4fe73f8f7c988c97dcba/imgaug/multicore.py", line 45, in _switch_to_spawn_if_nixos
multiprocessing.set_start_method("spawn")
File "/nix/store/drr8qcgiccfc5by09r5zc30flgwh1mbx-python3-3.7.5/lib/python3.7/multiprocessing/context.py", line 242, in set_start_method
raise RuntimeError('context has already been set')
RuntimeError: context has already been set
I locally patched this with following two changes:
in **imgaug/multicore.py** replace "multiprocessing.set_start_method(\"spawn\")" with "multiprocessing.set_start_method(\"spawn\",force=True)"
in **test/test_multicore.py** replace "mock_ssm.assert_called_once_with(\"spawn\")" with mock_ssm.assert_called_once_with(\"spawn\",force=True)"
After this change hang issue has disappeared for augmenter tests.
I have attached the detailed error as attachment img_aug_erros.txt. But now i am getting two test failures:
========================== slowest 20 test durations ===========================
11.24s call test/augmenters/test_meta.py::TestAugmenter_augment_batches::test_augment_batches_with_many_different_augmenters
6.29s call test/augmenters/test_mixed_files.py::test_keypoint_augmentation
4.93s call test/augmenters/test_mixed_files.py::test_determinism
4.45s call test/augmenters/test_meta.py::TestAugmenter_augment_batches::test_augment_batches_background
4.07s call test/augmenters/test_geometric.py::test_AffineCv2
3.38s call test/test_multicore.py::TestPool::test_inputs_not_lost
2.78s call test/augmenters/test_geometric.py::TestPiecewiseAffine::test_other_dtypes_uint_int
2.65s call test/test_multicore.py::TestPool::test_augmentations_with_seed_match_for_images_and_keypoints
2.47s call test/test_multicore.py::TestPool::test_augmentations_with_seed_match
2.40s call test/test_parameters.py::Test_draw_distributions_graph::test_basic_functionality
1.71s call test/augmenters/test_geometric.py::TestPiecewiseAffine::test_nb_cols_is_list_affects_images
1.62s call test/test_multicore.py::TestPool::test_augmentations_without_seed_differ
1.60s call test/test_multicore.py::TestPool::test_augmentations_without_seed_differ_for_images_and_keypoints
1.59s call test/augmenters/test_meta.py::TestAugmenter_augment_batches::test_augment_batches_batch_with_list_of_images
1.58s call test/augmenters/test_meta.py::TestAugmenter_augment_batches::test_augment_batches_batch_with_array_of_images
1.41s call test/augmenters/test_geometric.py::TestPiecewiseAffine::test_other_dtypes_float
1.36s call test/augmenters/test_geometric.py::TestPiecewiseAffine::test_nb_rows_is_list_affects_images
1.35s call test/test_parameters.py::TestIterativeNoiseAggregator::test_value_is_stochastic_max_list_as_iter_evaluate_counts
1.28s call test/augmenters/test_arithmetic.py::TestAdd::test_uint8_every_possible_value
1.21s call test/augmenters/test_meta.py::TestAugmenter::test_augment_keypoints_aligned_despite_nongeometric_image_ops
====== 2 failed, 4472 passed, 4 skipped, 1 warnings in 147.60s (0:02:27) =======
Seems like #526 should help this along? Shall we retest?
Hi @CMCDragonkai, @aleju ,
Tested the changes on my system with https://github.com/aleju/imgaug/pull/526/commits/5c2fa03ee44fb8e4995c46066da4adda9a44f2ef on #526 ,
Local patches not needed anymore for:
in **imgaug/multicore.py** replace "multiprocessing.set_start_method(\"spawn\")" with "multiprocessing.set_start_method(\"spawn\",force=True)"
in **test/test_multicore.py** replace "mock_ssm.assert_called_once_with(\"spawn\")" with mock_ssm.assert_called_once_with(\"spawn\",force=True)"
Thanks.
Sorry, didn't see that there were two new errors.
I just pushed an update to #526 that should fix both issues.
And yes, #526 is supposed to do the same as force=True
, just in a bit more elegant way.
Thanks @aleju , finally with this fix imgaug is building on NixOS with all the test case passing. @CMCDragonkai
test/test_dtypes.py::Test_change_dtype_::test_clip_and_round
/build/imgaug-c3d99a420efc45652a1264920dc20378a54b1325/imgaug/imgaug.py:308: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3,and in 3.9 it will stop working
return isinstance(val, collections.Iterable)
-- Docs: https://docs.pytest.org/en/latest/warnings.html
========================== slowest 20 test durations ===========================
70.03s call test/augmenters/test_meta.py::TestAugmenter_augment_batches::test_augment_batches_with_many_different_augmenters
6.25s call test/augmenters/test_mixed_files.py::test_keypoint_augmentation
4.84s call test/augmenters/test_mixed_files.py::test_determinism
4.29s call test/augmenters/test_meta.py::TestAugmenter_augment_batches::test_augment_batches_background
4.08s call test/augmenters/test_geometric.py::test_AffineCv2
3.27s call test/test_multicore.py::TestPool::test_inputs_not_lost
2.72s call test/augmenters/test_geometric.py::TestPiecewiseAffine::test_other_dtypes_uint_int
2.44s call test/test_multicore.py::TestPool::test_augmentations_with_seed_match
2.43s call test/test_multicore.py::TestPool::test_augmentations_with_seed_match_for_images_and_keypoints
2.39s call test/test_parameters.py::Test_draw_distributions_graph::test_basic_functionality
1.77s call test/test_multicore.py::TestBatchLoader::test_basic_functionality
1.67s call test/test_multicore.py::TestPool::test_augmentations_without_seed_differ_for_images_and_keypoints
1.65s call test/test_multicore.py::TestPool::test_augmentations_without_seed_differ
1.61s call test/augmenters/test_geometric.py::TestPiecewiseAffine::test_nb_cols_is_list_affects_images
1.57s call test/augmenters/test_meta.py::TestAugmenter_augment_batches::test_augment_batches_batch_with_array_of_images
1.56s call test/augmenters/test_meta.py::TestAugmenter_augment_batches::test_augment_batches_batch_with_list_of_images
1.39s call test/augmenters/test_geometric.py::TestPiecewiseAffine::test_other_dtypes_float
1.37s call test/test_parameters.py::TestIterativeNoiseAggregator::test_value_is_stochastic_max_list_as_iter_evaluate_counts
1.32s call test/augmenters/test_geometric.py::TestPiecewiseAffine::test_nb_rows_is_list_affects_images
1.29s call test/augmenters/test_arithmetic.py::TestAdd::test_uint8_every_possible_value
=========== 4504 passed, 4 skipped, 1 warnings in 207.00s (0:03:27) ============
pythonCatchConflictsPhase
pythonRemoveBinBytecodePhase
pythonImportsCheckPhase
Executing pythonImportsCheckPhase
pytestcachePhase
/nix/store/s10vs4sa37qbznx50xhzh03fw0qy70mn-python3.7-imgaug-0.3.0
That's good to hear. I merged the patch to master.
Nixos fix is now merged to upstream. Closing this issue. Thanks again @aleju
Hi Team,
I was trying to enable the test cases for pythonPackages.imgaug https://github.com/NixOS/nixpkgs/pull/67494
During this process i am able to execute the test cases but facing AssertionError and this is causing 5 failures. Summary of test run:
============ **5 failed, 383 passed, 3 warnings in 199.71s (0:03:19)** =============
detailed log : imgaug_test_failures.txt
Please suggest. Thanks.