Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_five_crop,test_ten_crop,test_max_value,test_linear_transformatio… #3975

Closed
wants to merge 0 commits into from
Closed

Conversation

harishsdev
Copy link
Contributor

Port test/test_transforms.py to pytest for below transforms

test_five_crop
test_ten_crop
test_max_value
test_linear_transformation
test_autoaugment
test_center_crop
test_center_crop_2
test_color_jitter

PR for :#3945

@harishsdev
Copy link
Contributor Author

This PR is for #3945

Group G

test_five_crop
test_ten_crop
test_max_value
test_linear_transformation

Group D

test_autoaugment
test_center_crop
test_center_crop_2
test_color_jitter

Copy link
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @harishsdev , I made a quick review.

Could you please move these new tests functions at the end of the file, as asked in #3958 (comment)?

Also there seem to be a new untitled new file with 1999 new lines, we'll need to remove this one :)

Comment on lines 262 to 263
for policy in transforms.AutoAugmentPolicy:
for fill in [None, 85, (128, 128, 128)]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need to parametrize over policy and fill instead of having nested for loops

Comment on lines 67 to 68
for should_vflip in [True, False]:
for single_dim in [True, False]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should parametrize here too

transforms.ToPILImage(),
transforms.CenterCrop((oheight, owidth)),
transforms.ToTensor(), ])(img)
assert_equal(result.sum(), 0,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as this is just an integer comparison, we should just use assert a == b as per the instructions in #3945 (comment)

Also I see above that the formatting is a bit odd:

         transforms.ToTensor(), ])(img)

Please make sure to preserve the original formatting :)

Comment on lines 1791 to 1793
@pytest.mark.parametrize(should_vflip, [True, False])
@pytest.mark.parametrize(single_dim, [True, False])
def test_ten_crop(should_vflip,single_dim):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be:

Suggested change
@pytest.mark.parametrize(should_vflip, [True, False])
@pytest.mark.parametrize(single_dim, [True, False])
def test_ten_crop(should_vflip,single_dim):
@pytest.mark.parametrize('should_vflip', [True, False])
@pytest.mark.parametrize('single_dim', [True, False])
def test_ten_crop(should_vflip, single_dim):

Please make sure to read the instructions at #3945 (comment) and you can take inspiration from https://github.com/pytorch/vision/pull/3907/files to see how to parametrize tests.

Also I really recommend to try your changes locally before you push: it will be much easier for you to see what works and what doesn't work

@harishsdev
Copy link
Contributor Author

PR for:-#3945

Group B
test_accimage_crop
test_accimage_pil_to_tensor
test_accimage_resize
test_accimage_to_tensor

Group C
test_affine

@harishsdev
Copy link
Contributor Author

@NicolasHug Thanks you very much for your patience,It gives to motivation while working on this opensource issues,I have raised Single PR for add B,C,D,G Groups,please help to merge them,Thanks for supporting

@NicolasHug
Copy link
Member

@harishsdev thanks for the PR but please consider submitting only 2 groups per PR to keep the review managable, as asked in #3945

Also, the test are failing with:

test/test_transforms.py:1777: in <module>
    @pytest.mark.parametrize(pt, [(16, 16), (20, 16), (20, 20)])
E   NameError: name 'pt' is not defined

This is the same issue that I already pointed out in #3975 (comment)

Please don't hesitate to ask for specific help, but first I kindly ask that you try running the tests locally before pushing changes, as it will make this process much faster. We have contributing guidelines here: https://github.com/pytorch/vision/blob/master/CONTRIBUTING.md with instructions on how to run the test.

@harishsdev
Copy link
Contributor Author

@NicolasHug Please Help

Thanks for your inputs,As per torchvision documentation we have two tests,
please help to set up local machine setup for running CI tests

1.code formatting
2.unit testing

1.for code formatting and typing i use

flake8 --config=setup.cfg .

This Gives no error


2.Unit testing :-

(practice) PS D:\contrib\19283975\exp\vision> pytest test -vvv
==================================================== test session starts ====================================================
platform win32 -- Python 3.8.8, pytest-6.2.3, py-1.10.0, pluggy-0.13.1 -- c:\users\harish\anaconda3\envs\practice\python.exe
cachedir: .pytest_cache
rootdir: D:\contrib\19283975\exp\vision
plugins: cov-2.11.1, pythonpath-0.7.3, typeguard-2.12.0
collected 43 items / 23 errors / 20 selected

========================================================== ERRORS ===========================================================
__________________________________________ ERROR collecting test/test_datasets.py ___________________________________________
test\test_datasets.py:17: in
import datasets_utils
test\datasets_utils.py:21: in
from common_utils import get_tmp_dir, disable_console_output
test\common_utils.py:20: in
from _assert_utils import assert_equal
test_assert_utils.py:11: in
assert_equal = functools.partial(torch.testing.assert_close, rtol=0, atol=0)
E AttributeError: module 'torch.testing' has no attribute 'assert_close'
______________________________________ ERROR collecting test/test_datasets_download.py ______________________________________
test\test_datasets_download.py:25: in
from common_utils import get_tmp_dir
test\common_utils.py:20: in
from _assert_utils import assert_equal
test_assert_utils.py:11: in
assert_equal = functools.partial(torch.testing.assert_close, rtol=0, atol=0)
E AttributeError: module 'torch.testing' has no attribute 'assert_close'
______________________________________ ERROR collecting test/test_datasets_samplers.py ______________________________________
test\test_datasets_samplers.py:16: in
from common_utils import get_tmp_dir
test\common_utils.py:20: in
from _assert_utils import assert_equal
test_assert_utils.py:11: in
assert_equal = functools.partial(torch.testing.assert_close, rtol=0, atol=0)
E AttributeError: module 'torch.testing' has no attribute 'assert_close'
_______________________________________ ERROR collecting test/test_datasets_utils.py ________________________________________
test\test_datasets_utils.py:14: in
from common_utils import get_tmp_dir, call_args_to_kwargs_only
test\common_utils.py:20: in
from _assert_utils import assert_equal
test_assert_utils.py:11: in
assert_equal = functools.partial(torch.testing.assert_close, rtol=0, atol=0)
E AttributeError: module 'torch.testing' has no attribute 'assert_close'
____________________________________ ERROR collecting test/test_datasets_video_utils.py _____________________________________
test\test_datasets_video_utils.py:9: in
from common_utils import get_tmp_dir
test\common_utils.py:20: in
from _assert_utils import assert_equal
test_assert_utils.py:11: in
assert_equal = functools.partial(torch.testing.assert_close, rtol=0, atol=0)
E AttributeError: module 'torch.testing' has no attribute 'assert_close'
__________________________________ ERROR collecting test/test_datasets_video_utils_opt.py ___________________________________
test\test_datasets_video_utils_opt.py:3: in
import test_datasets_video_utils
:991: in _find_and_load
???
:975: in _find_and_load_unlocked
???
:671: in _load_unlocked
???
c:\users\harish\anaconda3\envs\practice\lib\site-packages_pytest\assertion\rewrite.py:170: in exec_module
exec(co, module.dict)
test\test_datasets_video_utils.py:9: in
from common_utils import get_tmp_dir
test\common_utils.py:20: in
from _assert_utils import assert_equal
test_assert_utils.py:11: in
assert_equal = functools.partial(torch.testing.assert_close, rtol=0, atol=0)
E AttributeError: module 'torch.testing' has no attribute 'assert_close'
______________________________________ ERROR collecting test/test_functional_tensor.py ______________________________________
test\test_functional_tensor.py:17: in
from common_utils import (
test\common_utils.py:20: in
from _assert_utils import assert_equal
test_assert_utils.py:11: in
assert_equal = functools.partial(torch.testing.assert_close, rtol=0, atol=0)
E AttributeError: module 'torch.testing' has no attribute 'assert_close'
____________________________________________ ERROR collecting test/test_image.py ____________________________________________
test\test_image.py:12: in
from common_utils import get_tmp_dir, needs_cuda, cpu_only
test\common_utils.py:20: in
from _assert_utils import assert_equal
test_assert_utils.py:11: in
assert_equal = functools.partial(torch.testing.assert_close, rtol=0, atol=0)
E AttributeError: module 'torch.testing' has no attribute 'assert_close'
__________________________________________ ERROR collecting test/test_internet.py ___________________________________________
test\test_internet.py:15: in
from common_utils import get_tmp_dir
test\common_utils.py:20: in
from _assert_utils import assert_equal
test_assert_utils.py:11: in
assert_equal = functools.partial(torch.testing.assert_close, rtol=0, atol=0)
E AttributeError: module 'torch.testing' has no attribute 'assert_close'
_____________________________________________ ERROR collecting test/test_io.py ______________________________________________
test\test_io.py:12: in
from common_utils import get_tmp_dir
test\common_utils.py:20: in
from _assert_utils import assert_equal
test_assert_utils.py:11: in
assert_equal = functools.partial(torch.testing.assert_close, rtol=0, atol=0)
E AttributeError: module 'torch.testing' has no attribute 'assert_close'
___________________________________________ ERROR collecting test/test_io_opt.py ____________________________________________
test\test_io_opt.py:3: in
import test_io
:991: in _find_and_load
???
:975: in _find_and_load_unlocked
???
:671: in _load_unlocked
???
c:\users\harish\anaconda3\envs\practice\lib\site-packages_pytest\assertion\rewrite.py:170: in exec_module
exec(co, module.dict)
test\test_io.py:12: in
from common_utils import get_tmp_dir
test\common_utils.py:20: in
from _assert_utils import assert_equal
test_assert_utils.py:11: in
assert_equal = functools.partial(torch.testing.assert_close, rtol=0, atol=0)
E AttributeError: module 'torch.testing' has no attribute 'assert_close'
___________________________________________ ERROR collecting test/test_models.py ____________________________________________
test\test_models.py:4: in
from common_utils import TestCase, map_nested_tensor_object, freeze_rng_state, set_rng_seed
test\common_utils.py:20: in
from _assert_utils import assert_equal
test_assert_utils.py:11: in
assert_equal = functools.partial(torch.testing.assert_close, rtol=0, atol=0)
E AttributeError: module 'torch.testing' has no attribute 'assert_close'
________________________________ ERROR collecting test/test_models_detection_anchor_utils.py ________________________________
test\test_models_detection_anchor_utils.py:2: in
from common_utils import TestCase
test\common_utils.py:20: in
from _assert_utils import assert_equal
test_assert_utils.py:11: in
assert_equal = functools.partial(torch.testing.assert_close, rtol=0, atol=0)
E AttributeError: module 'torch.testing' has no attribute 'assert_close'
___________________________________ ERROR collecting test/test_models_detection_utils.py ____________________________________
test\test_models_detection_utils.py:7: in
from _assert_utils import assert_equal
test_assert_utils.py:11: in
assert_equal = functools.partial(torch.testing.assert_close, rtol=0, atol=0)
E AttributeError: module 'torch.testing' has no attribute 'assert_close'
____________________________________________ ERROR collecting test/test_onnx.py _____________________________________________
test\test_onnx.py:9: in
from common_utils import set_rng_seed
test\common_utils.py:20: in
from _assert_utils import assert_equal
test_assert_utils.py:11: in
assert_equal = functools.partial(torch.testing.assert_close, rtol=0, atol=0)
E AttributeError: module 'torch.testing' has no attribute 'assert_close'
_____________________________________________ ERROR collecting test/test_ops.py _____________________________________________
test\test_ops.py:1: in
from common_utils import needs_cuda, cpu_only, cpu_and_gpu
test\common_utils.py:20: in
from _assert_utils import assert_equal
test_assert_utils.py:11: in
assert_equal = functools.partial(torch.testing.assert_close, rtol=0, atol=0)
E AttributeError: module 'torch.testing' has no attribute 'assert_close'
______________________________________ ERROR collecting test/test_quantized_models.py _______________________________________
test\test_quantized_models.py:2: in
from common_utils import TestCase, map_nested_tensor_object
test\common_utils.py:20: in
from _assert_utils import assert_equal
test_assert_utils.py:11: in
assert_equal = functools.partial(torch.testing.assert_close, rtol=0, atol=0)
E AttributeError: module 'torch.testing' has no attribute 'assert_close'
_________________________________________ ERROR collecting test/test_transforms.py __________________________________________
test\test_transforms.py:25: in
from common_utils import cycle_over, int_dtypes, float_dtypes
test\common_utils.py:20: in
from _assert_utils import assert_equal
test_assert_utils.py:11: in
assert_equal = functools.partial(torch.testing.assert_close, rtol=0, atol=0)
E AttributeError: module 'torch.testing' has no attribute 'assert_close'
______________________________________ ERROR collecting test/test_transforms_tensor.py ______________________________________
test\test_transforms_tensor.py:12: in
from common_utils import (
test\common_utils.py:20: in
from _assert_utils import assert_equal
test_assert_utils.py:11: in
assert_equal = functools.partial(torch.testing.assert_close, rtol=0, atol=0)
E AttributeError: module 'torch.testing' has no attribute 'assert_close'
______________________________________ ERROR collecting test/test_transforms_video.py _______________________________________
test\test_transforms_video.py:7: in
from _assert_utils import assert_equal
test_assert_utils.py:11: in
assert_equal = functools.partial(torch.testing.assert_close, rtol=0, atol=0)
E AttributeError: module 'torch.testing' has no attribute 'assert_close'
____________________________________________ ERROR collecting test/test_utils.py ____________________________________________
test\test_utils.py:12: in
from _assert_utils import assert_equal
test_assert_utils.py:11: in
assert_equal = functools.partial(torch.testing.assert_close, rtol=0, atol=0)
E AttributeError: module 'torch.testing' has no attribute 'assert_close'
________________________________________ ERROR collecting test/test_video_reader.py _________________________________________
test\test_video_reader.py:13: in
from common_utils import PY39_SKIP
test\common_utils.py:20: in
from _assert_utils import assert_equal
test_assert_utils.py:11: in
assert_equal = functools.partial(torch.testing.assert_close, rtol=0, atol=0)
E AttributeError: module 'torch.testing' has no attribute 'assert_close'
__________________________________________ ERROR collecting test/test_videoapi.py ___________________________________________
test\test_videoapi.py:10: in
from common_utils import PY39_SKIP
test\common_utils.py:20: in
from _assert_utils import assert_equal
test_assert_utils.py:11: in
assert_equal = functools.partial(torch.testing.assert_close, rtol=0, atol=0)
E AttributeError: module 'torch.testing' has no attribute 'assert_close'
===================================================== warnings summary ======================================================
c:\users\harish\anaconda3\envs\practice\lib\site-packages\pyreadline\py3k_compat.py:8
c:\users\harish\anaconda3\envs\practice\lib\site-packages\pyreadline\py3k_compat.py:8: 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(x, collections.Callable)

torchvision_init_.py:26
D:\contrib\19283975\exp\vision\torchvision_init_.py:26: UserWarning: You are importing torchvision within its own root folder (D:\contrib\19283975\exp\vision). This is not expected to work and may give errors. Please exit the torchvision project source and relaunch your python interpreter.
warnings.warn(message.format(os.getcwd()))

-- Docs: https://docs.pytest.org/en/stable/warnings.html
================================================== short test summary info ==================================================
ERROR test/test_datasets.py - AttributeError: module 'torch.testing' has no attribute 'assert_close'
ERROR test/test_datasets_download.py - AttributeError: module 'torch.testing' has no attribute 'assert_close'
ERROR test/test_datasets_samplers.py - AttributeError: module 'torch.testing' has no attribute 'assert_close'
ERROR test/test_datasets_utils.py - AttributeError: module 'torch.testing' has no attribute 'assert_close'
ERROR test/test_datasets_video_utils.py - AttributeError: module 'torch.testing' has no attribute 'assert_close'
ERROR test/test_datasets_video_utils_opt.py - AttributeError: module 'torch.testing' has no attribute 'assert_close'
ERROR test/test_functional_tensor.py - AttributeError: module 'torch.testing' has no attribute 'assert_close'
ERROR test/test_image.py - AttributeError: module 'torch.testing' has no attribute 'assert_close'
ERROR test/test_internet.py - AttributeError: module 'torch.testing' has no attribute 'assert_close'
ERROR test/test_io.py - AttributeError: module 'torch.testing' has no attribute 'assert_close'
ERROR test/test_io_opt.py - AttributeError: module 'torch.testing' has no attribute 'assert_close'
ERROR test/test_models.py - AttributeError: module 'torch.testing' has no attribute 'assert_close'
ERROR test/test_models_detection_anchor_utils.py - AttributeError: module 'torch.testing' has no attribute 'assert_close'
ERROR test/test_models_detection_utils.py - AttributeError: module 'torch.testing' has no attribute 'assert_close'
ERROR test/test_onnx.py - AttributeError: module 'torch.testing' has no attribute 'assert_close'
ERROR test/test_ops.py - AttributeError: module 'torch.testing' has no attribute 'assert_close'
ERROR test/test_quantized_models.py - AttributeError: module 'torch.testing' has no attribute 'assert_close'
ERROR test/test_transforms.py - AttributeError: module 'torch.testing' has no attribute 'assert_close'
ERROR test/test_transforms_tensor.py - AttributeError: module 'torch.testing' has no attribute 'assert_close'
ERROR test/test_transforms_video.py - AttributeError: module 'torch.testing' has no attribute 'assert_close'
ERROR test/test_utils.py - AttributeError: module 'torch.testing' has no attribute 'assert_close'
ERROR test/test_video_reader.py - AttributeError: module 'torch.testing' has no attribute 'assert_close'
ERROR test/test_videoapi.py - AttributeError: module 'torch.testing' has no attribute 'assert_close'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 23 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================== 2 warnings, 23 errors in 11.42s ==============================================

@NicolasHug
Copy link
Member

You likely have an old version of pytorch. You can update with conda install pytorch -c pytorch-nightly -c conda-forge

Also running pytest test -vvv will not be the most effective way to test your changes. As you're only touching one file, you should be able to just do pytest test/test_transforms.py -vvv and even filter some more with -k.

@harishsdev harishsdev closed this Jun 6, 2021
@NicolasHug NicolasHug mentioned this pull request Jun 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants