MCPcopy Create free account
hub / github.com/OpenGVLab/HumanBench / AugInput

Class AugInput

PATH/core/data/transforms/seg_transforms_dev.py:610–682  ·  view source on GitHub ↗

Input that can be used with :meth:`Augmentation.__call__`. This is a standard implementation for the majority of use cases. This class provides the standard attributes **"image", "boxes", "sem_seg"** defined in :meth:`__init__` and they may be needed by different augmentations.

Source from the content-addressed store, hash-verified

608
609
610class AugInput:
611 """
612 Input that can be used with :meth:`Augmentation.__call__`.
613 This is a standard implementation for the majority of use cases.
614 This class provides the standard attributes **"image", "boxes", "sem_seg"**
615 defined in :meth:`__init__` and they may be needed by different augmentations.
616 Most augmentation policies do not need attributes beyond these three.
617
618 After applying augmentations to these attributes (using :meth:`AugInput.transform`),
619 the returned transforms can then be used to transform other data structures that users have.
620
621 Examples:
622 ::
623 input = AugInput(image, boxes=boxes)
624 tfms = augmentation(input)
625 transformed_image = input.image
626 transformed_boxes = input.boxes
627 transformed_other_data = tfms.apply_other(other_data)
628
629 An extended project that works with new data types may implement augmentation policies
630 that need other inputs. An algorithm may need to transform inputs in a way different
631 from the standard approach defined in this class. In those rare situations, users can
632 implement a class similar to this class, that satify the following condition:
633
634 * The input must provide access to these data in the form of attribute access
635 (``getattr``). For example, if an :class:`Augmentation` to be applied needs "image"
636 and "sem_seg" arguments, its input must have the attribute "image" and "sem_seg".
637 * The input must have a ``transform(tfm: Transform) -> None`` method which
638 in-place transforms all its attributes.
639 """
640
641 # TODO maybe should support more builtin data types here
642 def __init__(
643 self,
644 image: np.ndarray,
645 *,
646 boxes: Optional[np.ndarray] = None,
647 sem_seg: Optional[np.ndarray] = None,
648 ):
649 """
650 Args:
651 image (ndarray): (H,W) or (H,W,C) ndarray of type uint8 in range [0, 255], or
652 floating point in range [0, 1] or [0, 255]. The meaning of C is up
653 to users.
654 boxes (ndarray or None): Nx4 float32 boxes in XYXY_ABS mode
655 sem_seg (ndarray or None): HxW uint8 semantic segmentation mask. Each element
656 is an integer label of pixel.
657 """
658 _check_img_dtype(image)
659 self.image = image
660 self.boxes = boxes
661 self.sem_seg = sem_seg
662
663 def transform(self, tfm: Transform) -> None:
664 """
665 In-place transform all attributes of this class.
666
667 By "in-place", it means after calling this method, accessing an attribute such

Callers 1

apply_augmentationsFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected