@@ -541,80 +541,6 @@ def test__transform_image_mask(self, fill, mocker):
541541 fn .assert_has_calls (calls )
542542
543543
544- class TestRandomRotation :
545- def test_assertions (self ):
546- with pytest .raises (ValueError , match = "is a single number, it must be positive" ):
547- transforms .RandomRotation (- 0.7 )
548-
549- for d in [[- 0.7 ], [- 0.7 , 0 , 0.7 ]]:
550- with pytest .raises (ValueError , match = "degrees should be a sequence of length 2" ):
551- transforms .RandomRotation (d )
552-
553- with pytest .raises (TypeError , match = "Got inappropriate fill arg" ):
554- transforms .RandomRotation (12 , fill = "abc" )
555-
556- with pytest .raises (TypeError , match = "center should be a sequence of length" ):
557- transforms .RandomRotation (12 , center = 12 )
558-
559- with pytest .raises (ValueError , match = "center should be a sequence of length" ):
560- transforms .RandomRotation (12 , center = [1 , 2 , 3 ])
561-
562- def test__get_params (self ):
563- angle_bound = 34
564- transform = transforms .RandomRotation (angle_bound )
565-
566- params = transform ._get_params (None )
567- assert - angle_bound <= params ["angle" ] <= angle_bound
568-
569- angle_bounds = [12 , 34 ]
570- transform = transforms .RandomRotation (angle_bounds )
571-
572- params = transform ._get_params (None )
573- assert angle_bounds [0 ] <= params ["angle" ] <= angle_bounds [1 ]
574-
575- @pytest .mark .parametrize ("degrees" , [23 , [0 , 45 ], (0 , 45 )])
576- @pytest .mark .parametrize ("expand" , [False , True ])
577- @pytest .mark .parametrize ("fill" , [0 , [1 , 2 , 3 ], (2 , 3 , 4 )])
578- @pytest .mark .parametrize ("center" , [None , [2.0 , 3.0 ]])
579- def test__transform (self , degrees , expand , fill , center , mocker ):
580- interpolation = InterpolationMode .BILINEAR
581- transform = transforms .RandomRotation (
582- degrees , interpolation = interpolation , expand = expand , fill = fill , center = center
583- )
584-
585- if isinstance (degrees , (tuple , list )):
586- assert transform .degrees == [float (degrees [0 ]), float (degrees [1 ])]
587- else :
588- assert transform .degrees == [float (- degrees ), float (degrees )]
589-
590- fn = mocker .patch ("torchvision.transforms.v2.functional.rotate" )
591- inpt = mocker .MagicMock (spec = datapoints .Image )
592- # vfdev-5, Feature Request: let's store params as Transform attribute
593- # This could be also helpful for users
594- # Otherwise, we can mock transform._get_params
595- torch .manual_seed (12 )
596- _ = transform (inpt )
597- torch .manual_seed (12 )
598- params = transform ._get_params (inpt )
599-
600- fill = transforms ._utils ._convert_fill_arg (fill )
601- fn .assert_called_once_with (inpt , ** params , interpolation = interpolation , expand = expand , fill = fill , center = center )
602-
603- @pytest .mark .parametrize ("angle" , [34 , - 87 ])
604- @pytest .mark .parametrize ("expand" , [False , True ])
605- def test_boundingbox_spatial_size (self , angle , expand ):
606- # Specific test for BoundingBox.rotate
607- bbox = datapoints .BoundingBox (
608- torch .tensor ([1 , 2 , 3 , 4 ]), format = datapoints .BoundingBoxFormat .XYXY , spatial_size = (32 , 32 )
609- )
610- img = datapoints .Image (torch .rand (1 , 3 , 32 , 32 ))
611-
612- out_img = img .rotate (angle , expand = expand )
613- out_bbox = bbox .rotate (angle , expand = expand )
614-
615- assert out_img .spatial_size == out_bbox .spatial_size
616-
617-
618544class TestRandomCrop :
619545 def test_assertions (self ):
620546 with pytest .raises (ValueError , match = "Please provide only two dimensions" ):
0 commit comments