@@ -184,13 +184,13 @@ def load(self, device="cpu"):
184184 return args , kwargs
185185
186186
187- DEFAULT_SQUARE_IMAGE_SIZE = 15
188- DEFAULT_LANDSCAPE_IMAGE_SIZE = (7 , 33 )
189- DEFAULT_PORTRAIT_IMAGE_SIZE = (31 , 9 )
190- DEFAULT_IMAGE_SIZES = (DEFAULT_LANDSCAPE_IMAGE_SIZE , DEFAULT_PORTRAIT_IMAGE_SIZE , DEFAULT_SQUARE_IMAGE_SIZE , "random" )
187+ DEFAULT_SQUARE_SPATIAL_SIZE = 15
188+ DEFAULT_LANDSCAPE_SPATIAL_SIZE = (7 , 33 )
189+ DEFAULT_PORTRAIT_SPATIAL_SIZE = (31 , 9 )
190+ DEFAULT_SPATIAL_SIZES = (DEFAULT_LANDSCAPE_SPATIAL_SIZE , DEFAULT_PORTRAIT_SPATIAL_SIZE , DEFAULT_SQUARE_SPATIAL_SIZE , "random" )
191191
192192
193- def _parse_image_size (size , * , name = "size" ):
193+ def _parse_spatial_size (size , * , name = "size" ):
194194 if size == "random" :
195195 return tuple (torch .randint (15 , 33 , (2 ,)).tolist ())
196196 elif isinstance (size , int ) and size > 0 :
@@ -246,11 +246,11 @@ def load(self, device):
246246@dataclasses .dataclass
247247class ImageLoader (TensorLoader ):
248248 color_space : features .ColorSpace
249- image_size : Tuple [int , int ] = dataclasses .field (init = False )
249+ spatial_size : Tuple [int , int ] = dataclasses .field (init = False )
250250 num_channels : int = dataclasses .field (init = False )
251251
252252 def __post_init__ (self ):
253- self .image_size = self .shape [- 2 :]
253+ self .spatial_size = self .shape [- 2 :]
254254 self .num_channels = self .shape [- 3 ]
255255
256256
@@ -277,7 +277,7 @@ def make_image_loader(
277277 dtype = torch .float32 ,
278278 constant_alpha = True ,
279279):
280- size = _parse_image_size (size )
280+ size = _parse_spatial_size (size )
281281 num_channels = get_num_channels (color_space )
282282
283283 def fn (shape , dtype , device ):
@@ -295,7 +295,7 @@ def fn(shape, dtype, device):
295295
296296def make_image_loaders (
297297 * ,
298- sizes = DEFAULT_IMAGE_SIZES ,
298+ sizes = DEFAULT_SPATIAL_SIZES ,
299299 color_spaces = (
300300 features .ColorSpace .GRAY ,
301301 features .ColorSpace .GRAY_ALPHA ,
@@ -316,7 +316,7 @@ def make_image_loaders(
316316@dataclasses .dataclass
317317class BoundingBoxLoader (TensorLoader ):
318318 format : features .BoundingBoxFormat
319- image_size : Tuple [int , int ]
319+ spatial_size : Tuple [int , int ]
320320
321321
322322def randint_with_tensor_bounds (arg1 , arg2 = None , ** kwargs ):
@@ -331,7 +331,7 @@ def randint_with_tensor_bounds(arg1, arg2=None, **kwargs):
331331 ).reshape (low .shape )
332332
333333
334- def make_bounding_box_loader (* , extra_dims = (), format , image_size = "random" , dtype = torch .float32 ):
334+ def make_bounding_box_loader (* , extra_dims = (), format , spatial_size = "random" , dtype = torch .float32 ):
335335 if isinstance (format , str ):
336336 format = features .BoundingBoxFormat [format ]
337337 if format not in {
@@ -341,7 +341,7 @@ def make_bounding_box_loader(*, extra_dims=(), format, image_size="random", dtyp
341341 }:
342342 raise pytest .UsageError (f"Can't make bounding box in format { format } " )
343343
344- image_size = _parse_image_size ( image_size , name = "image_size " )
344+ spatial_size = _parse_spatial_size ( spatial_size , name = "spatial_size " )
345345
346346 def fn (shape , dtype , device ):
347347 * extra_dims , num_coordinates = shape
@@ -350,10 +350,10 @@ def fn(shape, dtype, device):
350350
351351 if any (dim == 0 for dim in extra_dims ):
352352 return features .BoundingBox (
353- torch .empty (* extra_dims , 4 , dtype = dtype , device = device ), format = format , spatial_size = image_size
353+ torch .empty (* extra_dims , 4 , dtype = dtype , device = device ), format = format , spatial_size = spatial_size
354354 )
355355
356- height , width = image_size
356+ height , width = spatial_size
357357
358358 if format == features .BoundingBoxFormat .XYXY :
359359 x1 = torch .randint (0 , width // 2 , extra_dims )
@@ -375,10 +375,10 @@ def fn(shape, dtype, device):
375375 parts = (cx , cy , w , h )
376376
377377 return features .BoundingBox (
378- torch .stack (parts , dim = - 1 ).to (dtype = dtype , device = device ), format = format , spatial_size = image_size
378+ torch .stack (parts , dim = - 1 ).to (dtype = dtype , device = device ), format = format , spatial_size = spatial_size
379379 )
380380
381- return BoundingBoxLoader (fn , shape = (* extra_dims , 4 ), dtype = dtype , format = format , image_size = image_size )
381+ return BoundingBoxLoader (fn , shape = (* extra_dims , 4 ), dtype = dtype , format = format , spatial_size = spatial_size )
382382
383383
384384make_bounding_box = from_loader (make_bounding_box_loader )
@@ -388,11 +388,11 @@ def make_bounding_box_loaders(
388388 * ,
389389 extra_dims = DEFAULT_EXTRA_DIMS ,
390390 formats = tuple (features .BoundingBoxFormat ),
391- image_size = "random" ,
391+ spatial_size = "random" ,
392392 dtypes = (torch .float32 , torch .int64 ),
393393):
394394 for params in combinations_grid (extra_dims = extra_dims , format = formats , dtype = dtypes ):
395- yield make_bounding_box_loader (** params , image_size = image_size )
395+ yield make_bounding_box_loader (** params , spatial_size = spatial_size )
396396
397397
398398make_bounding_boxes = from_loaders (make_bounding_box_loaders )
@@ -475,7 +475,7 @@ class MaskLoader(TensorLoader):
475475
476476def make_detection_mask_loader (size = "random" , * , num_objects = "random" , extra_dims = (), dtype = torch .uint8 ):
477477 # This produces "detection" masks, i.e. `(*, N, H, W)`, where `N` denotes the number of objects
478- size = _parse_image_size (size )
478+ size = _parse_spatial_size (size )
479479 num_objects = int (torch .randint (1 , 11 , ())) if num_objects == "random" else num_objects
480480
481481 def fn (shape , dtype , device ):
@@ -489,7 +489,7 @@ def fn(shape, dtype, device):
489489
490490
491491def make_detection_mask_loaders (
492- sizes = DEFAULT_IMAGE_SIZES ,
492+ sizes = DEFAULT_SPATIAL_SIZES ,
493493 num_objects = (1 , 0 , "random" ),
494494 extra_dims = DEFAULT_EXTRA_DIMS ,
495495 dtypes = (torch .uint8 ,),
@@ -503,7 +503,7 @@ def make_detection_mask_loaders(
503503
504504def make_segmentation_mask_loader (size = "random" , * , num_categories = "random" , extra_dims = (), dtype = torch .uint8 ):
505505 # This produces "segmentation" masks, i.e. `(*, H, W)`, where the category is encoded in the values
506- size = _parse_image_size (size )
506+ size = _parse_spatial_size (size )
507507 num_categories = int (torch .randint (1 , 11 , ())) if num_categories == "random" else num_categories
508508
509509 def fn (shape , dtype , device ):
@@ -518,7 +518,7 @@ def fn(shape, dtype, device):
518518
519519def make_segmentation_mask_loaders (
520520 * ,
521- sizes = DEFAULT_IMAGE_SIZES ,
521+ sizes = DEFAULT_SPATIAL_SIZES ,
522522 num_categories = (1 , 2 , "random" ),
523523 extra_dims = DEFAULT_EXTRA_DIMS ,
524524 dtypes = (torch .uint8 ,),
@@ -532,7 +532,7 @@ def make_segmentation_mask_loaders(
532532
533533def make_mask_loaders (
534534 * ,
535- sizes = DEFAULT_IMAGE_SIZES ,
535+ sizes = DEFAULT_SPATIAL_SIZES ,
536536 num_objects = (1 , 0 , "random" ),
537537 num_categories = (1 , 2 , "random" ),
538538 extra_dims = DEFAULT_EXTRA_DIMS ,
@@ -559,7 +559,7 @@ def make_video_loader(
559559 extra_dims = (),
560560 dtype = torch .uint8 ,
561561):
562- size = _parse_image_size (size )
562+ size = _parse_spatial_size (size )
563563 num_frames = int (torch .randint (1 , 5 , ())) if num_frames == "random" else num_frames
564564
565565 def fn (shape , dtype , device ):
@@ -576,7 +576,7 @@ def fn(shape, dtype, device):
576576
577577def make_video_loaders (
578578 * ,
579- sizes = DEFAULT_IMAGE_SIZES ,
579+ sizes = DEFAULT_SPATIAL_SIZES ,
580580 color_spaces = (
581581 features .ColorSpace .GRAY ,
582582 features .ColorSpace .RGB ,
0 commit comments