@@ -184,13 +184,13 @@ def load(self, device="cpu"):
184
184
return args , kwargs
185
185
186
186
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" )
191
191
192
192
193
- def _parse_image_size (size , * , name = "size" ):
193
+ def _parse_spatial_size (size , * , name = "size" ):
194
194
if size == "random" :
195
195
return tuple (torch .randint (15 , 33 , (2 ,)).tolist ())
196
196
elif isinstance (size , int ) and size > 0 :
@@ -246,11 +246,11 @@ def load(self, device):
246
246
@dataclasses .dataclass
247
247
class ImageLoader (TensorLoader ):
248
248
color_space : features .ColorSpace
249
- image_size : Tuple [int , int ] = dataclasses .field (init = False )
249
+ spatial_size : Tuple [int , int ] = dataclasses .field (init = False )
250
250
num_channels : int = dataclasses .field (init = False )
251
251
252
252
def __post_init__ (self ):
253
- self .image_size = self .shape [- 2 :]
253
+ self .spatial_size = self .shape [- 2 :]
254
254
self .num_channels = self .shape [- 3 ]
255
255
256
256
@@ -277,7 +277,7 @@ def make_image_loader(
277
277
dtype = torch .float32 ,
278
278
constant_alpha = True ,
279
279
):
280
- size = _parse_image_size (size )
280
+ size = _parse_spatial_size (size )
281
281
num_channels = get_num_channels (color_space )
282
282
283
283
def fn (shape , dtype , device ):
@@ -295,7 +295,7 @@ def fn(shape, dtype, device):
295
295
296
296
def make_image_loaders (
297
297
* ,
298
- sizes = DEFAULT_IMAGE_SIZES ,
298
+ sizes = DEFAULT_SPATIAL_SIZES ,
299
299
color_spaces = (
300
300
features .ColorSpace .GRAY ,
301
301
features .ColorSpace .GRAY_ALPHA ,
@@ -316,7 +316,7 @@ def make_image_loaders(
316
316
@dataclasses .dataclass
317
317
class BoundingBoxLoader (TensorLoader ):
318
318
format : features .BoundingBoxFormat
319
- image_size : Tuple [int , int ]
319
+ spatial_size : Tuple [int , int ]
320
320
321
321
322
322
def randint_with_tensor_bounds (arg1 , arg2 = None , ** kwargs ):
@@ -331,7 +331,7 @@ def randint_with_tensor_bounds(arg1, arg2=None, **kwargs):
331
331
).reshape (low .shape )
332
332
333
333
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 ):
335
335
if isinstance (format , str ):
336
336
format = features .BoundingBoxFormat [format ]
337
337
if format not in {
@@ -341,7 +341,7 @@ def make_bounding_box_loader(*, extra_dims=(), format, image_size="random", dtyp
341
341
}:
342
342
raise pytest .UsageError (f"Can't make bounding box in format { format } " )
343
343
344
- image_size = _parse_image_size ( image_size , name = "image_size " )
344
+ spatial_size = _parse_spatial_size ( spatial_size , name = "spatial_size " )
345
345
346
346
def fn (shape , dtype , device ):
347
347
* extra_dims , num_coordinates = shape
@@ -350,10 +350,10 @@ def fn(shape, dtype, device):
350
350
351
351
if any (dim == 0 for dim in extra_dims ):
352
352
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
354
354
)
355
355
356
- height , width = image_size
356
+ height , width = spatial_size
357
357
358
358
if format == features .BoundingBoxFormat .XYXY :
359
359
x1 = torch .randint (0 , width // 2 , extra_dims )
@@ -375,10 +375,10 @@ def fn(shape, dtype, device):
375
375
parts = (cx , cy , w , h )
376
376
377
377
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
379
379
)
380
380
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 )
382
382
383
383
384
384
make_bounding_box = from_loader (make_bounding_box_loader )
@@ -388,11 +388,11 @@ def make_bounding_box_loaders(
388
388
* ,
389
389
extra_dims = DEFAULT_EXTRA_DIMS ,
390
390
formats = tuple (features .BoundingBoxFormat ),
391
- image_size = "random" ,
391
+ spatial_size = "random" ,
392
392
dtypes = (torch .float32 , torch .int64 ),
393
393
):
394
394
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 )
396
396
397
397
398
398
make_bounding_boxes = from_loaders (make_bounding_box_loaders )
@@ -475,7 +475,7 @@ class MaskLoader(TensorLoader):
475
475
476
476
def make_detection_mask_loader (size = "random" , * , num_objects = "random" , extra_dims = (), dtype = torch .uint8 ):
477
477
# 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 )
479
479
num_objects = int (torch .randint (1 , 11 , ())) if num_objects == "random" else num_objects
480
480
481
481
def fn (shape , dtype , device ):
@@ -489,7 +489,7 @@ def fn(shape, dtype, device):
489
489
490
490
491
491
def make_detection_mask_loaders (
492
- sizes = DEFAULT_IMAGE_SIZES ,
492
+ sizes = DEFAULT_SPATIAL_SIZES ,
493
493
num_objects = (1 , 0 , "random" ),
494
494
extra_dims = DEFAULT_EXTRA_DIMS ,
495
495
dtypes = (torch .uint8 ,),
@@ -503,7 +503,7 @@ def make_detection_mask_loaders(
503
503
504
504
def make_segmentation_mask_loader (size = "random" , * , num_categories = "random" , extra_dims = (), dtype = torch .uint8 ):
505
505
# 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 )
507
507
num_categories = int (torch .randint (1 , 11 , ())) if num_categories == "random" else num_categories
508
508
509
509
def fn (shape , dtype , device ):
@@ -518,7 +518,7 @@ def fn(shape, dtype, device):
518
518
519
519
def make_segmentation_mask_loaders (
520
520
* ,
521
- sizes = DEFAULT_IMAGE_SIZES ,
521
+ sizes = DEFAULT_SPATIAL_SIZES ,
522
522
num_categories = (1 , 2 , "random" ),
523
523
extra_dims = DEFAULT_EXTRA_DIMS ,
524
524
dtypes = (torch .uint8 ,),
@@ -532,7 +532,7 @@ def make_segmentation_mask_loaders(
532
532
533
533
def make_mask_loaders (
534
534
* ,
535
- sizes = DEFAULT_IMAGE_SIZES ,
535
+ sizes = DEFAULT_SPATIAL_SIZES ,
536
536
num_objects = (1 , 0 , "random" ),
537
537
num_categories = (1 , 2 , "random" ),
538
538
extra_dims = DEFAULT_EXTRA_DIMS ,
@@ -559,7 +559,7 @@ def make_video_loader(
559
559
extra_dims = (),
560
560
dtype = torch .uint8 ,
561
561
):
562
- size = _parse_image_size (size )
562
+ size = _parse_spatial_size (size )
563
563
num_frames = int (torch .randint (1 , 5 , ())) if num_frames == "random" else num_frames
564
564
565
565
def fn (shape , dtype , device ):
@@ -576,7 +576,7 @@ def fn(shape, dtype, device):
576
576
577
577
def make_video_loaders (
578
578
* ,
579
- sizes = DEFAULT_IMAGE_SIZES ,
579
+ sizes = DEFAULT_SPATIAL_SIZES ,
580
580
color_spaces = (
581
581
features .ColorSpace .GRAY ,
582
582
features .ColorSpace .RGB ,
0 commit comments