22
33import pytest
44import torch
5- from common_utils import assert_equal , make_bounding_boxes , make_image , make_keypoints , make_segmentation_mask , make_video
5+ from common_utils import (
6+ assert_equal ,
7+ make_bounding_boxes ,
8+ make_image ,
9+ make_keypoints ,
10+ make_segmentation_mask ,
11+ make_video ,
12+ )
613from PIL import Image
714
815from torchvision import tv_tensors
@@ -49,7 +56,26 @@ def test_bbox_dim_error():
4956 tv_tensors .BoundingBoxes (data_3d , format = "XYXY" , canvas_size = (32 , 32 ))
5057
5158
52- @pytest .mark .parametrize ("data" , [torch .randint (0 , 32 , size = (5 , 2 )), [[0 , 0 ,], [2 , 2 ,]], [1 , 2 ,]])
59+ @pytest .mark .parametrize (
60+ "data" ,
61+ [
62+ torch .randint (0 , 32 , size = (5 , 2 )),
63+ [
64+ [
65+ 0 ,
66+ 0 ,
67+ ],
68+ [
69+ 2 ,
70+ 2 ,
71+ ],
72+ ],
73+ [
74+ 1 ,
75+ 2 ,
76+ ],
77+ ],
78+ )
5379def test_keypoints_instance (data ):
5480 kpoint = tv_tensors .KeyPoints (data , canvas_size = (32 , 32 ))
5581 assert isinstance (kpoint , tv_tensors .KeyPoints )
@@ -82,9 +108,9 @@ def test_new_requires_grad(data, input_requires_grad, expected_requires_grad):
82108 assert tv_tensor .requires_grad is expected_requires_grad
83109
84110
85- @pytest .mark .parametrize ("make_input" , [
86- make_image , make_bounding_boxes , make_segmentation_mask , make_video , make_keypoints
87- ] )
111+ @pytest .mark .parametrize (
112+ "make_input" , [ make_image , make_bounding_boxes , make_segmentation_mask , make_video , make_keypoints ]
113+ )
88114def test_isinstance (make_input ):
89115 assert isinstance (make_input (), torch .Tensor )
90116
@@ -96,9 +122,9 @@ def test_wrapping_no_copy():
96122 assert image .data_ptr () == tensor .data_ptr ()
97123
98124
99- @pytest .mark .parametrize ("make_input" , [
100- make_image , make_bounding_boxes , make_segmentation_mask , make_video , make_keypoints
101- ] )
125+ @pytest .mark .parametrize (
126+ "make_input" , [ make_image , make_bounding_boxes , make_segmentation_mask , make_video , make_keypoints ]
127+ )
102128def test_to_wrapping (make_input ):
103129 dp = make_input ()
104130
@@ -108,9 +134,9 @@ def test_to_wrapping(make_input):
108134 assert dp_to .dtype is torch .float64
109135
110136
111- @pytest .mark .parametrize ("make_input" , [
112- make_image , make_bounding_boxes , make_segmentation_mask , make_video , make_keypoints
113- ] )
137+ @pytest .mark .parametrize (
138+ "make_input" , [ make_image , make_bounding_boxes , make_segmentation_mask , make_video , make_keypoints ]
139+ )
114140@pytest .mark .parametrize ("return_type" , ["Tensor" , "TVTensor" ])
115141def test_to_tv_tensor_reference (make_input , return_type ):
116142 tensor = torch .rand ((3 , 16 , 16 ), dtype = torch .float64 )
@@ -124,9 +150,9 @@ def test_to_tv_tensor_reference(make_input, return_type):
124150 assert type (tensor ) is torch .Tensor
125151
126152
127- @pytest .mark .parametrize ("make_input" , [
128- make_image , make_bounding_boxes , make_segmentation_mask , make_video , make_keypoints
129- ] )
153+ @pytest .mark .parametrize (
154+ "make_input" , [ make_image , make_bounding_boxes , make_segmentation_mask , make_video , make_keypoints ]
155+ )
130156@pytest .mark .parametrize ("return_type" , ["Tensor" , "TVTensor" ])
131157def test_clone_wrapping (make_input , return_type ):
132158 dp = make_input ()
@@ -138,9 +164,9 @@ def test_clone_wrapping(make_input, return_type):
138164 assert dp_clone .data_ptr () != dp .data_ptr ()
139165
140166
141- @pytest .mark .parametrize ("make_input" , [
142- make_image , make_bounding_boxes , make_segmentation_mask , make_video , make_keypoints
143- ] )
167+ @pytest .mark .parametrize (
168+ "make_input" , [ make_image , make_bounding_boxes , make_segmentation_mask , make_video , make_keypoints ]
169+ )
144170@pytest .mark .parametrize ("return_type" , ["Tensor" , "TVTensor" ])
145171def test_requires_grad__wrapping (make_input , return_type ):
146172 dp = make_input (dtype = torch .float )
@@ -155,9 +181,9 @@ def test_requires_grad__wrapping(make_input, return_type):
155181 assert dp_requires_grad .requires_grad
156182
157183
158- @pytest .mark .parametrize ("make_input" , [
159- make_image , make_bounding_boxes , make_segmentation_mask , make_video , make_keypoints
160- ] )
184+ @pytest .mark .parametrize (
185+ "make_input" , [ make_image , make_bounding_boxes , make_segmentation_mask , make_video , make_keypoints ]
186+ )
161187@pytest .mark .parametrize ("return_type" , ["Tensor" , "TVTensor" ])
162188def test_detach_wrapping (make_input , return_type ):
163189 dp = make_input (dtype = torch .float ).requires_grad_ (True )
@@ -212,9 +238,9 @@ def test_force_subclass_with_metadata(return_type):
212238 tv_tensors .set_return_type ("tensor" )
213239
214240
215- @pytest .mark .parametrize ("make_input" , [
216- make_image , make_bounding_boxes , make_segmentation_mask , make_video , make_keypoints
217- ] )
241+ @pytest .mark .parametrize (
242+ "make_input" , [ make_image , make_bounding_boxes , make_segmentation_mask , make_video , make_keypoints ]
243+ )
218244@pytest .mark .parametrize ("return_type" , ["Tensor" , "TVTensor" ])
219245def test_other_op_no_wrapping (make_input , return_type ):
220246 dp = make_input ()
@@ -226,9 +252,9 @@ def test_other_op_no_wrapping(make_input, return_type):
226252 assert type (output ) is (type (dp ) if return_type == "TVTensor" else torch .Tensor )
227253
228254
229- @pytest .mark .parametrize ("make_input" , [
230- make_image , make_bounding_boxes , make_segmentation_mask , make_video , make_keypoints
231- ] )
255+ @pytest .mark .parametrize (
256+ "make_input" , [ make_image , make_bounding_boxes , make_segmentation_mask , make_video , make_keypoints ]
257+ )
232258@pytest .mark .parametrize (
233259 "op" ,
234260 [
@@ -245,9 +271,9 @@ def test_no_tensor_output_op_no_wrapping(make_input, op):
245271 assert type (output ) is not type (dp )
246272
247273
248- @pytest .mark .parametrize ("make_input" , [
249- make_image , make_bounding_boxes , make_segmentation_mask , make_video , make_keypoints
250- ] )
274+ @pytest .mark .parametrize (
275+ "make_input" , [ make_image , make_bounding_boxes , make_segmentation_mask , make_video , make_keypoints ]
276+ )
251277@pytest .mark .parametrize ("return_type" , ["Tensor" , "TVTensor" ])
252278def test_inplace_op_no_wrapping (make_input , return_type ):
253279 dp = make_input ()
0 commit comments