Instantiate a :class:`Transform` object to be used given the input image. Subclasses should implement this method. The :class:`ImageAugmentor` often has random policies which generate deterministic transform. Any of those random policies should happen inside this me
(self, img)
| 125 | __repr__ = __str__ |
| 126 | |
| 127 | def get_transform(self, img): |
| 128 | """ |
| 129 | Instantiate a :class:`Transform` object to be used given the input image. |
| 130 | Subclasses should implement this method. |
| 131 | |
| 132 | The :class:`ImageAugmentor` often has random policies which generate deterministic transform. |
| 133 | Any of those random policies should happen inside this method and instantiate |
| 134 | an actual deterministic transform to be performed. |
| 135 | The returned :class:`Transform` object should perform deterministic transforms |
| 136 | through its :meth:`apply_*` method. |
| 137 | |
| 138 | In this way, the returned :class:`Transform` object can be used to transform not only the |
| 139 | input image, but other images or coordinates associated with the image. |
| 140 | |
| 141 | Args: |
| 142 | img (ndarray): see notes of this class on the requirements. |
| 143 | |
| 144 | Returns: |
| 145 | Transform |
| 146 | """ |
| 147 | # This should be an abstract method |
| 148 | # But we provide an implementation that uses the old interface, |
| 149 | # for backward compatibility |
| 150 | log_once("The old augmentor interface was deprecated. " |
| 151 | "Please implement {} with `get_transform` instead!".format(self.__class__.__name__), |
| 152 | "warning") |
| 153 | |
| 154 | def legacy_augment_coords(self, coords, p): |
| 155 | try: |
| 156 | return self._augment_coords(coords, p) |
| 157 | except AttributeError: |
| 158 | pass |
| 159 | try: |
| 160 | return self.augment_coords(coords, p) |
| 161 | except AttributeError: |
| 162 | pass |
| 163 | return coords # this is the old default |
| 164 | |
| 165 | p = None # the default return value for this method |
| 166 | try: |
| 167 | p = self._get_augment_params(img) |
| 168 | except AttributeError: |
| 169 | pass |
| 170 | try: |
| 171 | p = self.get_augment_params(img) |
| 172 | except AttributeError: |
| 173 | pass |
| 174 | |
| 175 | from .transform import BaseTransform, TransformFactory |
| 176 | if isinstance(p, BaseTransform): # some old augs return Transform already |
| 177 | return p |
| 178 | |
| 179 | return TransformFactory(name="LegacyConversion -- " + str(self), |
| 180 | apply_image=lambda img: self._augment(img, p), |
| 181 | apply_coords=lambda coords: legacy_augment_coords(self, coords, p)) |
| 182 | |
| 183 | def augment(self, img): |
| 184 | """ |
no test coverage detected