detectron2.data.transforms¶
Related tutorial: Data Augmentation.
- class detectron2.data.transforms.Transform¶
基类:
objectBase class for implementations of deterministic transformations for image and other data structures. “Deterministic” requires that the output of all methods of this class are deterministic w.r.t their input arguments. Note that this is different from (random) data augmentations. To perform data augmentations in training, there should be a higher-level policy that generates these transform ops.
Each transform op may handle several data types, e.g.: image, coordinates, segmentation, bounding boxes, with its
apply_*methods. Some of them have a default implementation, but can be overwritten if the default isn’t appropriate. See documentation of each pre-definedapply_*methods for details. Note that The implementation of these method may choose to modify its input data in-place for efficient transformation.The class can be extended to support arbitrary new data types with its
register_type()method.- __repr__()¶
Produce something like: “MyTransform(field1={self.field1}, field2={self.field2})”
- apply_box(box: ndarray) ndarray¶
Apply the transform on an axis-aligned box. By default will transform the corner points and use their minimum/maximum to create a new axis-aligned box. Note that this default may change the size of your box, e.g. after rotations.
- 参数:
box (ndarray) – Nx4 floating point array of XYXY format in absolute coordinates.
- 返回:
ndarray – box after apply the transformation.
备注
The coordinates are not pixel indices. Coordinates inside an image of shape (H, W) are in range [0, W] or [0, H].
This function does not clip boxes to force them inside the image. It is up to the application that uses the boxes to decide.
- abstract apply_coords(coords: ndarray)¶
Apply the transform on coordinates.
- 参数:
coords (ndarray) – floating point array of shape Nx2. Each row is (x, y).
- 返回:
ndarray – coordinates after apply the transformation.
备注
The coordinates are not pixel indices. Coordinates inside an image of shape (H, W) are in range [0, W] or [0, H]. This function should correctly transform coordinates outside the image as well.
- abstract apply_image(img: ndarray)¶
Apply the transform on an image.
- 参数:
img (ndarray) – of shape NxHxWxC, or HxWxC or HxW. The array can be of type uint8 in range [0, 255], or floating point in range [0, 1] or [0, 255].
- 返回:
ndarray – image after apply the transformation.
- apply_polygons(polygons: list) list¶
Apply the transform on a list of polygons, each represented by a Nx2 array. By default will just transform all the points.
- 参数:
polygon (list[ndarray]) – each is a Nx2 floating point array of (x, y) format in absolute coordinates.
- 返回:
list[ndarray] – polygon after apply the transformation.
备注
The coordinates are not pixel indices. Coordinates on an image of shape (H, W) are in range [0, W] or [0, H].
- apply_segmentation(segmentation: ndarray) ndarray¶
Apply the transform on a full-image segmentation. By default will just perform “apply_image”.
- 参数:
segmentation (ndarray) – of shape HxW. The array should have integer
dtype. (or bool) –
- 返回:
ndarray – segmentation after apply the transformation.
- inverse() Transform¶
Create a transform that inverts the geometric changes (i.e. change of coordinates) of this transform.
Note that the inverse is meant for geometric changes only. The inverse of photometric transforms that do not change coordinates is defined to be a no-op, even if they may be invertible.
- 返回:
Transform
- classmethod register_type(data_type: str, func: Optional[Callable] = None)[源代码]¶
Register the given function as a handler that this transform will use for a specific data type.
- 参数:
data_type (str) – the name of the data type (e.g., box)
func (callable) – takes a transform and a data, returns the transformed data.
Examples:
# call it directly def func(flip_transform, voxel_data): return transformed_voxel_data HFlipTransform.register_type("voxel", func) # or, use it as a decorator @HFlipTransform.register_type("voxel") def func(flip_transform, voxel_data): return transformed_voxel_data # ... transform = HFlipTransform(...) transform.apply_voxel(voxel_data) # func will be called
- class detectron2.data.transforms.TransformList(transforms: List[Transform])¶
基类:
TransformMaintain a list of transform operations which will be applied in sequence. .. attribute:: transforms
- type:
list[Transform]
- __add__(other: TransformList) TransformList¶
- 参数:
other (TransformList) – transformation to add.
- 返回:
TransformList – list of transforms.
- __iadd__(other: TransformList) TransformList¶
- 参数:
other (TransformList) – transformation to add.
- 返回:
TransformList – list of transforms.
- __radd__(other: TransformList) TransformList¶
- 参数:
other (TransformList) – transformation to add.
- 返回:
TransformList – list of transforms.
- apply_coords(x)¶
- apply_image(x)¶
- inverse() TransformList¶
Invert each transform in reversed order.
- class detectron2.data.transforms.BlendTransform(src_image: ndarray, src_weight: float, dst_weight: float)¶
基类:
TransformTransforms pixel colors with PIL enhance functions.
- __init__(src_image: ndarray, src_weight: float, dst_weight: float)¶
Blends the input image (dst_image) with the src_image using formula:
src_weight * src_image + dst_weight * dst_image
- apply_image(img: ndarray, interp: Optional[str] = None) ndarray¶
Apply blend transform on the image(s).
- 参数:
img (ndarray) – of shape NxHxWxC, or HxWxC or HxW. The array can be of type uint8 in range [0, 255], or floating point in range [0, 1] or [0, 255].
interp (str) – keep this option for consistency, perform blend would not require interpolation.
- 返回:
ndarray – blended image(s).
- class detectron2.data.transforms.CropTransform(x0: int, y0: int, w: int, h: int, orig_w: Optional[int] = None, orig_h: Optional[int] = None)¶
基类:
Transform- __init__(x0: int, y0: int, w: int, h: int, orig_w: Optional[int] = None, orig_h: Optional[int] = None)¶
- 参数:
x0 (int) – crop the image(s) by img[y0:y0+h, x0:x0+w].
y0 (int) – crop the image(s) by img[y0:y0+h, x0:x0+w].
w (int) – crop the image(s) by img[y0:y0+h, x0:x0+w].
h (int) – crop the image(s) by img[y0:y0+h, x0:x0+w].
orig_w (int) – optional, the original width and height before cropping. Needed to make this transform invertible.
orig_h (int) – optional, the original width and height before cropping. Needed to make this transform invertible.
- apply_coords(coords: ndarray) ndarray¶
Apply crop transform on coordinates.
- 参数:
coords (ndarray) – floating point array of shape Nx2. Each row is (x, y).
- 返回:
ndarray – cropped coordinates.
- apply_image(img: ndarray) ndarray¶
Crop the image(s).
- 参数:
img (ndarray) – of shape NxHxWxC, or HxWxC or HxW. The array can be of type uint8 in range [0, 255], or floating point in range [0, 1] or [0, 255].
- 返回:
ndarray – cropped image(s).
- apply_polygons(polygons: list) list¶
Apply crop transform on a list of polygons, each represented by a Nx2 array. It will crop the polygon with the box, therefore the number of points in the polygon might change.
- 参数:
polygon (list[ndarray]) – each is a Nx2 floating point array of (x, y) format in absolute coordinates.
- 返回:
ndarray – cropped polygons.
- class detectron2.data.transforms.PadTransform(x0: int, y0: int, x1: int, y1: int, orig_w: Optional[int] = None, orig_h: Optional[int] = None, pad_value: float = 0, seg_pad_value: int = 0)¶
基类:
Transform- __init__(x0: int, y0: int, x1: int, y1: int, orig_w: Optional[int] = None, orig_h: Optional[int] = None, pad_value: float = 0, seg_pad_value: int = 0)¶
- 参数:
x0 – number of padded pixels on the left and top
y0 – number of padded pixels on the left and top
x1 – number of padded pixels on the right and bottom
y1 – number of padded pixels on the right and bottom
orig_w – optional, original width and height. Needed to make this transform invertible.
orig_h – optional, original width and height. Needed to make this transform invertible.
pad_value – the padding value to the image
seg_pad_value – the padding value to the segmentation mask
- apply_coords(coords)¶
- apply_image(img)¶
- apply_segmentation(img)¶
- class detectron2.data.transforms.GridSampleTransform(grid: ndarray, interp: str)¶
基类:
Transform- __init__(grid: ndarray, interp: str)¶
- 参数:
grid (ndarray) – grid has x and y input pixel locations which are used to compute output. Grid has values in the range of [-1, 1], which is normalized by the input height and width. The dimension is N x H x W x 2.
interp (str) – interpolation methods. Options include nearest and bilinear.
- apply_image(img: ndarray, interp: Optional[str] = None) ndarray¶
Apply grid sampling on the image(s).
- 参数:
img (ndarray) – of shape NxHxWxC, or HxWxC or HxW. The array can be of type uint8 in range [0, 255], or floating point in range [0, 1] or [0, 255].
interp (str) – interpolation methods. Options include nearest and bilinear.
- 返回:
ndarray – grid sampled image(s).
- class detectron2.data.transforms.HFlipTransform(width: int)¶
基类:
TransformPerform horizontal flip.
- apply_coords(coords: ndarray) ndarray¶
Flip the coordinates.
- 参数:
coords (ndarray) – floating point array of shape Nx2. Each row is (x, y).
- 返回:
ndarray – the flipped coordinates.
备注
The inputs are floating point coordinates, not pixel indices. Therefore they are flipped by (W - x, H - y), not (W - 1 - x, H - 1 - y).
- apply_image(img: ndarray) ndarray¶
Flip the image(s).
- 参数:
img (ndarray) – of shape HxW, HxWxC, or NxHxWxC. The array can be of type uint8 in range [0, 255], or floating point in range [0, 1] or [0, 255].
- 返回:
ndarray – the flipped image(s).
- apply_rotated_box(rotated_boxes)¶
Apply the horizontal flip transform on rotated boxes.
- 参数:
rotated_boxes (ndarray) – Nx5 floating point array of (x_center, y_center, width, height, angle_degrees) format in absolute coordinates.
- class detectron2.data.transforms.VFlipTransform(height: int)¶
基类:
TransformPerform vertical flip.
- apply_coords(coords: ndarray) ndarray¶
Flip the coordinates.
- 参数:
coords (ndarray) – floating point array of shape Nx2. Each row is (x, y).
- 返回:
ndarray – the flipped coordinates.
备注
The inputs are floating point coordinates, not pixel indices. Therefore they are flipped by (W - x, H - y), not (W - 1 - x, H - 1 - y).
- class detectron2.data.transforms.NoOpTransform¶
基类:
TransformA transform that does nothing.
- apply_rotated_box(x)¶
- class detectron2.data.transforms.ScaleTransform(h: int, w: int, new_h: int, new_w: int, interp: Optional[str] = None)¶
基类:
TransformResize the image to a target size.
- __init__(h: int, w: int, new_h: int, new_w: int, interp: Optional[str] = None)¶
- 参数:
h (int) – original image size.
w (int) – original image size.
new_h (int) – new image size.
new_w (int) – new image size.
interp (str) – interpolation methods. Options includes nearest, linear (3D-only), bilinear, bicubic (4D-only), and area. Details can be found in: https://pytorch.org/docs/stable/nn.functional.html
- apply_coords(coords: ndarray) ndarray¶
Compute the coordinates after resize.
- 参数:
coords (ndarray) – floating point array of shape Nx2. Each row is (x, y).
- 返回:
ndarray – resized coordinates.
- apply_image(img: ndarray, interp: Optional[str] = None) ndarray¶
Resize the image(s).
- 参数:
img (ndarray) – of shape NxHxWxC, or HxWxC or HxW. The array can be of type uint8 in range [0, 255], or floating point in range [0, 1] or [0, 255].
interp (str) – interpolation methods. Options includes nearest, linear (3D-only), bilinear, bicubic (4D-only), and area. Details can be found in: https://pytorch.org/docs/stable/nn.functional.html
- 返回:
ndarray – resized image(s).
- class detectron2.data.transforms.ExtentTransform(src_rect, output_size, interp=2, fill=0)¶
基类:
TransformExtracts a subregion from the source image and scales it to the output size.
The fill color is used to map pixels from the source rect that fall outside the source image.
See: https://pillow.readthedocs.io/en/latest/PIL.html#PIL.ImageTransform.ExtentTransform
- __init__(src_rect, output_size, interp=2, fill=0)¶
- 参数:
src_rect (x0, y0, x1, y1) – src coordinates
output_size (h, w) – dst image size
interp – PIL interpolation methods
fill – Fill color used when src_rect extends outside image
- apply_coords(coords)¶
- apply_image(img, interp=None)¶
- apply_segmentation(segmentation)¶
- class detectron2.data.transforms.ResizeTransform(h, w, new_h, new_w, interp=None)¶
基类:
TransformResize the image to a target size.
- __init__(h, w, new_h, new_w, interp=None)¶
- apply_coords(coords)¶
- apply_image(img, interp=None)¶
- apply_rotated_box(rotated_boxes)¶
Apply the resizing transform on rotated boxes. For details of how these (approximation) formulas are derived, please refer to
RotatedBoxes.scale().- 参数:
rotated_boxes (ndarray) – Nx5 floating point array of (x_center, y_center, width, height, angle_degrees) format in absolute coordinates.
- apply_segmentation(segmentation)¶
- inverse()¶
- class detectron2.data.transforms.RotationTransform(h, w, angle, expand=True, center=None, interp=None)¶
基类:
TransformThis method returns a copy of this image, rotated the given number of degrees counter clockwise around its center.
- __init__(h, w, angle, expand=True, center=None, interp=None)¶
- 参数:
h (int) – original image size
w (int) – original image size
angle (float) – degrees for rotation
expand (bool) – choose if the image should be resized to fit the whole rotated image (default), or simply cropped
center (tuple (width, height)) – coordinates of the rotation center if left to None, the center will be fit to the center of each image center has no effect if expand=True because it only affects shifting
interp – cv2 interpolation method, default cv2.INTER_LINEAR
- apply_coords(coords)¶
coords should be a N * 2 array-like, containing N couples of (x, y) points
- apply_image(img, interp=None)¶
img should be a numpy array, formatted as Height * Width * Nchannels
- apply_segmentation(segmentation)¶
- create_rotation_matrix(offset=0)¶
- inverse()¶
The inverse is to rotate it back with expand, and crop to get the original shape.
- class detectron2.data.transforms.ColorTransform(op)¶
基类:
TransformGeneric wrapper for any photometric transforms. These transformations should only affect the color space and
not the coordinate space of the image (e.g. annotation coordinates such as bounding boxes should not be changed)
- __init__(op)¶
- 参数:
op (Callable) – operation to be applied to the image, which takes in an ndarray and returns an ndarray.
- apply_coords(coords)¶
- apply_image(img)¶
- apply_segmentation(segmentation)¶
- inverse()¶
- class detectron2.data.transforms.PILColorTransform(op)¶
-
- Generic wrapper for PIL Photometric image transforms,
which affect the color space and not the coordinate space of the image
- __init__(op)¶
- 参数:
op (Callable) – operation to be applied to the image, which takes in a PIL Image and returns a transformed PIL Image. For reference on possible operations see: - https://pillow.readthedocs.io/en/stable/
- apply_image(img)¶
- class detectron2.data.transforms.Augmentation¶
基类:
objectAugmentation defines (often random) policies/strategies to generate
Transformfrom data. It is often used for pre-processing of input data.A “policy” that generates a
Transformmay, in the most general case, need arbitrary information from input data in order to determine what transforms to apply. Therefore, eachAugmentationinstance defines the arguments needed by itsget_transform()method. When called with the positional arguments, theget_transform()method executes the policy.Note that
Augmentationdefines the policies to create aTransform, but not how to execute the actual transform operations to those data. Its__call__()method will useAugInput.transform()to execute the transform.The returned Transform object is meant to describe deterministic transformation, which means it can be re-applied on associated data, e.g. the geometry of an image and its segmentation masks need to be transformed together. (If such re-application is not needed, then determinism is not a crucial requirement.)
- __call__(aug_input) Transform¶
Augment the given aug_input in-place, and return the transform that’s used.
This method will be called to apply the augmentation. In most augmentation, it is enough to use the default implementation, which calls
get_transform()using the inputs. But a subclass can overwrite it to have more complicated logic.- 参数:
aug_input (AugInput) – an object that has attributes needed by this augmentation (defined by
self.get_transform). Itstransformmethod will be called to in-place transform it.- 返回:
Transform – the transform that is applied on the input.
- __repr__()¶
Produce something like: “MyAugmentation(field1={self.field1}, field2={self.field2})”
- __str__()¶
Produce something like: “MyAugmentation(field1={self.field1}, field2={self.field2})”
- get_transform(*args) Transform¶
Execute the policy based on input data, and decide what transform to apply to inputs.
- 参数:
args – Any fixed-length positional arguments. By default, the name of the arguments should exist in the
AugInputto be used.- 返回:
Transform – Returns the deterministic transform to apply to the input.
Examples:
class MyAug: # if a policy needs to know both image and semantic segmentation def get_transform(image, sem_seg) -> T.Transform: pass tfm: Transform = MyAug().get_transform(image, sem_seg) new_image = tfm.apply_image(image)
备注
Users can freely use arbitrary new argument names in custom
get_transform()method, as long as they are available in the input data. In detectron2 we use the following convention:image: (H,W) or (H,W,C) ndarray of type uint8 in range [0, 255], or floating point in range [0, 1] or [0, 255].
boxes: (N,4) ndarray of float32. It represents the instance bounding boxes of N instances. Each is in XYXY format in unit of absolute coordinates.
sem_seg: (H,W) ndarray of type uint8. Each element is an integer label of pixel.
We do not specify convention for other types and do not include builtin
Augmentationthat uses other types in detectron2.
- class detectron2.data.transforms.AugmentationList(augs)¶
基类:
AugmentationApply a sequence of augmentations.
It has
__call__method to apply the augmentations.Note that
get_transform()method is impossible (will throw error if called) forAugmentationList, because in order to apply a sequence of augmentations, the kth augmentation must be applied first, to provide inputs needed by the (k+1)th augmentation.- __init__(augs)¶
- 参数:
augs (list[Augmentation or Transform]) –
- class detectron2.data.transforms.AugInput(image: ndarray, *, boxes: Optional[ndarray] = None, sem_seg: Optional[ndarray] = None)¶
基类:
objectInput that can be used with
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__init__()and they may be needed by different augmentations. Most augmentation policies do not need attributes beyond these three.After applying augmentations to these attributes (using
AugInput.transform()), the returned transforms can then be used to transform other data structures that users have.Examples:
input = AugInput(image, boxes=boxes) tfms = augmentation(input) transformed_image = input.image transformed_boxes = input.boxes transformed_other_data = tfms.apply_other(other_data)
An extended project that works with new data types may implement augmentation policies that need other inputs. An algorithm may need to transform inputs in a way different from the standard approach defined in this class. In those rare situations, users can implement a class similar to this class, that satify the following condition:
The input must provide access to these data in the form of attribute access (
getattr). For example, if anAugmentationto be applied needs “image” and “sem_seg” arguments, its input must have the attribute “image” and “sem_seg”.The input must have a
transform(tfm: Transform) -> Nonemethod which in-place transforms all its attributes.
- __init__(image: ndarray, *, boxes: Optional[ndarray] = None, sem_seg: Optional[ndarray] = None)¶
- 参数:
image (ndarray) – (H,W) or (H,W,C) ndarray of type uint8 in range [0, 255], or floating point in range [0, 1] or [0, 255]. The meaning of C is up to users.
boxes (ndarray or None) – Nx4 float32 boxes in XYXY_ABS mode
sem_seg (ndarray or None) – HxW uint8 semantic segmentation mask. Each element is an integer label of pixel.
- class detectron2.data.transforms.FixedSizeCrop(crop_size: Tuple[int], pad: bool = True, pad_value: float = 128.0, seg_pad_value: int = 255)¶
基类:
AugmentationIf crop_size is smaller than the input image size, then it uses a random crop of the crop size. If crop_size is larger than the input image size, then it pads the right and the bottom of the image to the crop size if pad is True, otherwise it returns the smaller image.
- __init__(crop_size: Tuple[int], pad: bool = True, pad_value: float = 128.0, seg_pad_value: int = 255)¶
- 参数:
crop_size – target image (height, width).
pad – if True, will pad images smaller than crop_size up to crop_size
pad_value – the padding value to the image.
seg_pad_value – the padding value to the segmentation mask.
- get_transform(image: ndarray) TransformList¶
- class detectron2.data.transforms.RandomApply(tfm_or_aug, prob=0.5)¶
基类:
AugmentationRandomly apply an augmentation with a given probability.
- __init__(tfm_or_aug, prob=0.5)¶
- 参数:
tfm_or_aug (Transform, Augmentation) – the transform or augmentation to be applied. It can either be a Transform or Augmentation instance.
prob (float) – probability between 0.0 and 1.0 that the wrapper transformation is applied
- get_transform(*args)¶
- class detectron2.data.transforms.RandomBrightness(intensity_min, intensity_max)¶
基类:
AugmentationRandomly transforms image brightness.
Brightness intensity is uniformly sampled in (intensity_min, intensity_max). - intensity < 1 will reduce brightness - intensity = 1 will preserve the input image - intensity > 1 will increase brightness
See: https://pillow.readthedocs.io/en/3.0.x/reference/ImageEnhance.html
- __init__(intensity_min, intensity_max)¶
- get_transform(image)¶
- class detectron2.data.transforms.RandomContrast(intensity_min, intensity_max)¶
基类:
AugmentationRandomly transforms image contrast.
Contrast intensity is uniformly sampled in (intensity_min, intensity_max). - intensity < 1 will reduce contrast - intensity = 1 will preserve the input image - intensity > 1 will increase contrast
See: https://pillow.readthedocs.io/en/3.0.x/reference/ImageEnhance.html
- __init__(intensity_min, intensity_max)¶
- get_transform(image)¶
- class detectron2.data.transforms.RandomCrop(crop_type: str, crop_size)¶
基类:
AugmentationRandomly crop a rectangle region out of an image.
- __init__(crop_type: str, crop_size)¶
- 参数:
“relative”: crop a (H * crop_size[0], W * crop_size[1]) region from an input image of size (H, W). crop size should be in (0, 1]
“relative_range”: uniformly sample two values from [crop_size[0], 1] and [crop_size[1]], 1], and use them as in “relative” crop type.
“absolute” crop a (crop_size[0], crop_size[1]) region from input image. crop_size must be smaller than the input image size.
“absolute_range”, for an input of size (H, W), uniformly sample H_crop in [crop_size[0], min(H, crop_size[1])] and W_crop in [crop_size[0], min(W, crop_size[1])]. Then crop a region (H_crop, W_crop).
- get_crop_size(image_size)¶
- 参数:
image_size (tuple) – height, width
- 返回:
crop_size (tuple) – height, width in absolute pixels
- get_transform(image)¶
- class detectron2.data.transforms.RandomExtent(scale_range, shift_range)¶
基类:
AugmentationOutputs an image by cropping a random “subrect” of the source image.
The subrect can be parameterized to include pixels outside the source image, in which case they will be set to zeros (i.e. black). The size of the output image will vary with the size of the random subrect.
- __init__(scale_range, shift_range)¶
- 参数:
output_size (h, w) – Dimensions of output image
scale_range (l, h) – Range of input-to-output size scaling factor
shift_range (x, y) – Range of shifts of the cropped subrect. The rect is shifted by [w / 2 * Uniform(-x, x), h / 2 * Uniform(-y, y)], where (w, h) is the (width, height) of the input image. Set each component to zero to crop at the image’s center.
- get_transform(image)¶
- class detectron2.data.transforms.RandomFlip(prob=0.5, *, horizontal=True, vertical=False)¶
基类:
AugmentationFlip the image horizontally or vertically with the given probability.
- __init__(prob=0.5, *, horizontal=True, vertical=False)¶
- 参数:
prob (float) – probability of flip.
horizontal (boolean) – whether to apply horizontal flipping
vertical (boolean) – whether to apply vertical flipping
- get_transform(image)¶
- class detectron2.data.transforms.RandomSaturation(intensity_min, intensity_max)¶
基类:
AugmentationRandomly transforms saturation of an RGB image. Input images are assumed to have ‘RGB’ channel order.
Saturation intensity is uniformly sampled in (intensity_min, intensity_max). - intensity < 1 will reduce saturation (make the image more grayscale) - intensity = 1 will preserve the input image - intensity > 1 will increase saturation
See: https://pillow.readthedocs.io/en/3.0.x/reference/ImageEnhance.html
- __init__(intensity_min, intensity_max)¶
- get_transform(image)¶
- class detectron2.data.transforms.RandomLighting(scale)¶
基类:
AugmentationThe “lighting” augmentation described in AlexNet, using fixed PCA over ImageNet. Input images are assumed to have ‘RGB’ channel order.
The degree of color jittering is randomly sampled via a normal distribution, with standard deviation given by the scale parameter.
- get_transform(image)¶
- class detectron2.data.transforms.RandomRotation(angle, expand=True, center=None, sample_style='range', interp=None)¶
基类:
AugmentationThis method returns a copy of this image, rotated the given number of degrees counter clockwise around the given center.
- __init__(angle, expand=True, center=None, sample_style='range', interp=None)¶
- 参数:
angle (list[float]) – If
sample_style=="range", a [min, max] interval from which to sample the angle (in degrees). Ifsample_style=="choice", a list of angles to sample fromexpand (bool) – choose if the image should be resized to fit the whole rotated image (default), or simply cropped
center (list[[float, float]]) – If
sample_style=="range", a [[minx, miny], [maxx, maxy]] relative interval from which to sample the center, [0, 0] being the top left of the image and [1, 1] the bottom right. Ifsample_style=="choice", a list of centers to sample from Default: None, which means that the center of rotation is the center of the image center has no effect if expand=True because it only affects shifting
- get_transform(image)¶
- class detectron2.data.transforms.Resize(shape, interp=2)¶
基类:
AugmentationResize image to a fixed target size
- __init__(shape, interp=2)¶
- 参数:
shape – (h, w) tuple or a int
interp – PIL interpolation method
- get_transform(image)¶
- class detectron2.data.transforms.ResizeScale(min_scale: float, max_scale: float, target_height: int, target_width: int, interp: int = 2)¶
基类:
AugmentationTakes target size as input and randomly scales the given target size between min_scale and max_scale. It then scales the input image such that it fits inside the scaled target box, keeping the aspect ratio constant. This implements the resize part of the Google’s ‘resize_and_crop’ data augmentation: https://github.com/tensorflow/tpu/blob/master/models/official/detection/utils/input_utils.py#L127
- class detectron2.data.transforms.ResizeShortestEdge(short_edge_length, max_size=9223372036854775807, sample_style='range', interp=2)¶
基类:
AugmentationResize the image while keeping the aspect ratio unchanged. It attempts to scale the shorter edge to the given short_edge_length, as long as the longer edge does not exceed max_size. If max_size is reached, then downscale so that the longer edge does not exceed max_size.
- __init__(short_edge_length, max_size=9223372036854775807, sample_style='range', interp=2)¶
- 参数:
short_edge_length (list[int]) – If
sample_style=="range", a [min, max] interval from which to sample the shortest edge length. Ifsample_style=="choice", a list of shortest edge lengths to sample from.max_size (int) – maximum allowed longest edge length.
sample_style (str) – either “range” or “choice”.
- static get_output_shape(oldh: int, oldw: int, short_edge_length: int, max_size: int) Tuple[int, int][源代码]¶
Compute the output size given input size and target short edge length.
- get_transform(image)¶
- class detectron2.data.transforms.RandomCrop_CategoryAreaConstraint(crop_type: str, crop_size, single_category_max_area: float = 1.0, ignored_category: Optional[int] = None)¶
基类:
AugmentationSimilar to
RandomCrop, but find a cropping window such that no single category occupies a ratio of more than single_category_max_area in semantic segmentation ground truth, which can cause unstability in training. The function attempts to find such a valid cropping window for at most 10 times.- __init__(crop_type: str, crop_size, single_category_max_area: float = 1.0, ignored_category: Optional[int] = None)¶
- 参数:
crop_type – same as in
RandomCropcrop_size – same as in
RandomCropsingle_category_max_area – the maximum allowed area ratio of a category. Set to 1.0 to disable
ignored_category – allow this category in the semantic segmentation ground truth to exceed the area ratio. Usually set to the category that’s ignored in training.
- get_transform(image, sem_seg)¶
- class detectron2.data.transforms.RandomResize(shape_list, interp=2)¶
基类:
AugmentationRandomly resize image to a target size in shape_list
- __init__(shape_list, interp=2)¶
- 参数:
shape_list – a list of shapes in (h, w)
interp – PIL interpolation method
- get_transform(image)¶
- class detectron2.data.transforms.MinIoURandomCrop(min_ious=(0.1, 0.3, 0.5, 0.7, 0.9), min_crop_size=0.3, mode_trials=1000, crop_trials=50)¶
基类:
AugmentationRandom crop the image & bboxes, the cropped patches have minimum IoU requirement with original image & bboxes, the IoU threshold is randomly selected from min_ious.
- 参数:
min_ious (tuple) – minimum IoU threshold for all intersections with
boxes (bounding) –
min_crop_size (float) – minimum crop’s size (i.e. h,w := a*h, a*w,
min_crop_size) (where a >=) –
mode_trials – number of trials for sampling min_ious threshold
crop_trials – number of trials for sampling crop_size after cropping
- get_transform(image, boxes)¶
Call function to crop images and bounding boxes with minimum IoU constraint.
- 参数:
boxes – ground truth boxes in (x1, y1, x2, y2) format