@@ -459,7 +459,7 @@ def __getitem__(self, index: int) -> dict[str, Any]:
459459
460460 Returns dict with:
461461 - 'image': np.ndarray or Tensor of shape (C, H, W).
462- - 'segmentations ' (if enabled): segmentation masks with depth dimension removed.
462+ - 'masks ' (if enabled): segmentation masks with depth dimension removed.
463463 - 'image_labels': dict of annotator -> label tensor.
464464 """
465465 if index >= len (self ):
@@ -482,10 +482,10 @@ def __getitem__(self, index: int) -> dict[str, Any]:
482482
483483 # Apply albumentations if present
484484 if self .alb_transform :
485- aug_result = self .apply_alb_transform (img , sliced_segs )
485+ aug_result = self .apply_alb_transform (img , { 'masks' : sliced_segs } )
486486 img = aug_result ['image' ]
487487 result ['image' ] = img
488- sliced_segs = aug_result [ 'segmentations' ]
488+ sliced_segs = aug_result . get ( 'masks' , {})
489489
490490 segmentations_processed , seg_labels_out = self ._process_segmentations (sliced_segs , seg_labels ,
491491 output_shape = img .shape [1 :])
@@ -497,9 +497,9 @@ def __getitem__(self, index: int) -> dict[str, Any]:
497497 if isinstance (segmentations_processed [author ], (Tensor , np .ndarray )):
498498 segmentations_processed [author ] = segmentations_processed [author ].squeeze (1 )
499499
500- result ['segmentations ' ] = segmentations_processed
500+ result ['masks ' ] = segmentations_processed
501501 if seg_labels_out :
502- result ['seg_labels ' ] = seg_labels_out
502+ result ['mask_labels ' ] = seg_labels_out
503503
504504 # Process image-level labels
505505 result ['image_labels' ] = self ._extract_image_labels (annotations )
@@ -520,22 +520,22 @@ def __getitem__(self, index: int) -> dict[str, Any]:
520520 def apply_alb_transform (
521521 self ,
522522 img : np .ndarray ,
523- segmentations : dict [str , np . ndarray ],
523+ targets : dict [str , Any ],
524524 ) -> dict [str , Any ]:
525525 """Apply 2D albumentations transform to a single-slice image and masks.
526526
527- Uses the same approach as ImageDataset: treats the data as 2D.
528-
529527 Args:
530528 img: Image array of shape (C, 1, H, W) or (C, H, W).
531- segmentations : Dict of author -> mask arrays of shape (#instances, 1, H, W) or (#instances , H, W).
529+ targets : Dict with optional key ``'masks'``: author -> array (#instances, 1, H, W).
532530
533531 Returns:
534- Dict with transformed 'image' and 'segmentations' .
532+ Dict with transformed `` 'image'`` and ``'masks'`` .
535533 """
536534 if self .alb_transform is None :
537535 raise ValueError ("alb_transform is not set" )
538536
537+ segmentations = targets .get ('masks' , {})
538+
539539 # Squeeze depth=1 if present
540540 orig_dim = img .ndim
541541 if orig_dim == 4 :
@@ -578,10 +578,10 @@ def apply_alb_transform(
578578 if orig_dim == 4 :
579579 aug_img = aug_img [:, np .newaxis , :, :]
580580
581- return {
582- 'image' : aug_img ,
583- 'segmentations' : aug_segmentations ,
584- }
581+ result : dict [ str , Any ] = { 'image' : aug_img }
582+ if aug_segmentations :
583+ result [ 'masks' ] = aug_segmentations
584+ return result
585585
586586 def __repr__ (self ) -> str :
587587 base = super ().__repr__ ()
0 commit comments