def inverse(self): if not self._can_invert(): raise InvertibleError('Cannot invert a transformation before it is applied' ' (size of image before padding unknown).') padding = self.padding if isinstance(padding, int): pad_left = pad_right = pad_top = pad_bottom = padding elif isinstance(padding, Sequence) and len(padding) == 2: pad_left = pad_right = padding[0] pad_top = pad_bottom = padding[1] elif isinstance(padding, Sequence) and len(padding) == 4: pad_left = padding[0] pad_top = padding[1] pad_right = padding[2] pad_bottom = padding[3] else: raise Exception(f'Argument mismatch: padding={padding}') size = (self._img_h, self._img_w) location = (pad_top, pad_left) inverse = Crop(location=location, size=size) inverse._img_h = pad_top + self._img_h + pad_bottom inverse._img_w = pad_left + self._img_w + pad_right return inverse
def inverse(self): if not self._can_invert(): raise InvertibleError( 'Cannot invert a random transformation before it is applied.') matrix_inv = _invert_affine_matrix(self._matrix) return Affine(matrix_inv)
def inverse(self): if not self._can_invert(): raise InvertibleError('Cannot invert a transformation before it is applied' ' (size before resizing is unknown).') inverse = Resize(size=(self._img_h, self._img_w), interpolation=self.interpolation) inverse._img_h, inverse.tw = self.size return inverse
def inverse(self): if not self._can_invert(): raise InvertibleError( 'Cannot invert a random transformation before it is applied.') return Compose(transforms=[ self.transforms[i].inverse() for i in self._order[::-1] ])
def inverse(self): if not self._can_invert(): raise InvertibleError('Cannot invert a random transformation before it is applied.') return T.Lambda( lambd=lambda x: x, tf_inv=self._transform, repr_str='ColorJitterInverse()' )
def inverse(self): try: return LinearTransformation( transformation_matrix=self.transformation_matrix.inverse(), mean_vector=(-1.0) * self.mean_vector @ self.transformation_matrix ) except RuntimeError: raise InvertibleError( f'{self.__repr__()} is not invertible because the transformation matrix singular.')
def inverse(self): transforms_inv = [] for t in self.transforms[::-1]: if not isinstance(t, Invertible): raise InvertibleError( f'{t} ({t.__class__.__name__}) is not an invertible object' ) transforms_inv.append(t.inverse()) return Compose(transforms=transforms_inv)
def inverse(self): if not self._can_invert(): raise InvertibleError('Cannot invert a random transformation before it is applied') crop = Crop( location=(self._tl_i, self._tl_j), size=self.size, ) crop._img_h, crop._img_w = self._img_h, self._img_w return crop.inverse()
def inverse(self): if not self._can_invert(): raise InvertibleError('Cannot invert a transformation before it is applied' ' (size before cropping is unknown).') inverse = CenterCrop(size=(self._img_h, self._img_w)) # center crop with bigger crop size is like padding th, tw = self.size inverse._img_w = tw inverse._img_h = th return inverse
def inverse(self): if not self._can_invert(): raise InvertibleError('Cannot invert a transformation before it is applied' ' (size before cropping is unknown).') five_crop = self._five_crop five_crop_flip = self._five_crop_flip return T.Lambda( lambd=lambda imgs: five_crop.inverse()(imgs[:5]) + self._flip(five_crop_flip.inverse()(imgs[5:])), tf_inv=lambda imgs: five_crop.inverse().invert(imgs[:5]) + five_crop_flip.inverse().invert( self._flip(imgs[5:])), repr_str='TenCropInverse()', )
def inverse(self): if not self._can_invert(): raise InvertibleError( 'Cannot invert a random transformation before it is applied.') rot = Rotation( angle=-self._angle, resample=self.resample, expand=self.expand, center=self.center, ) rot._img_h, rot._img_w = self._img_h, self._img_w return rot
def inverse(self): if (self._img_h is None or self._img_w is None) and self.expand: raise InvertibleError( 'Cannot invert a transformation before it is applied' ' (size of image before expanded rotation unknown).' ) # note: the size could be computed rot = Rotation( angle=-self.angle, resample=self.resample, expand=self.expand, center=self.center, ) rot._img_h, rot._img_w = self._img_h, self._img_w return rot
def inverse(self): if not self._can_invert(): raise InvertibleError('Cannot invert a transformation before it is applied' ' (size before cropping is unknown).') padding = ( self.tl_j, self.tl_i, self._img_w - self.crop_w - self.tl_j, self._img_h - self.crop_h - self.tl_i, ) inverse = Pad(padding=padding) inverse._img_w = self.crop_w inverse._img_h = self.crop_h return inverse
def inverse(self): if self.tf_inv is None: raise InvertibleError( 'Cannot invert transformation, tf_inv_builder is None') if isinstance(self.tf_inv, Invertible): return self.tf_inv else: repr_str = repr(self).split('()')[0] suffix = 'Inverse' if suffix in repr_str: repr_str = repr_str[:-len(suffix)] else: repr_str += suffix + '()' return Lambda( lambd=self.tf_inv, tf_inv=self.lambd, repr_str=repr_str, )
def inverse(self): if not self._can_invert(): raise InvertibleError('Cannot invert a transformation before it is applied' ' (size before the cropping is unknown).') crop_h, crop_w = self.size pad_w = self._img_w - crop_w pad_h = self._img_h - crop_h pad_tl = (0, 0, pad_w, pad_h) pad_tr = (pad_w, 0, 0, pad_h) pad_bl = (0, pad_h, pad_w, 0) pad_br = (pad_w, pad_h, 0, 0) half_w = (self._img_w - crop_w) // 2 half_h = (self._img_h - crop_h) // 2 pad_center = (half_w, half_h, self._img_w - crop_w - half_w, self._img_h - crop_h - half_h) tfs = [] for padding in [pad_tl, pad_tr, pad_bl, pad_br, pad_center]: tf = T.Pad(padding) tf._img_h = crop_h tf._img_w = crop_w tfs.append(tf) def invert_crops(crops): tl, tr, bl, br, center = crops return [tf(img) for tf, img in zip(tfs, [tl, tr, bl, br, center])] def invert_invert_crops(crops): tl, tr, bl, br, center = crops return [tf.inverse()(img) for tf, img in zip(tfs, [tl, tr, bl, br, center])] return T.Lambda( lambd=invert_crops, tf_inv=invert_invert_crops, repr_str=f'FiveCropInverse()', )
def inverse(self): if not self._can_invert(): raise InvertibleError( 'Cannot invert a random transformation before it is applied.') return self._transform.inverse()
def inverse(self): if not isinstance(self.transform, Invertible): raise InvertibleError( f'{self.transform} ({self.transform.__class__.__name__}) is not an invertible object' ) return self.transform.inverse()