aug

package
v0.9.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Byte2FloatImage

func Byte2FloatImage(x *ts.Tensor) *ts.Tensor

Byte2FloatImage converts uint8 dtype image tensor to float dtype. It's panic if input image is not uint8 dtype.

func Float2ByteImage

func Float2ByteImage(x *ts.Tensor) *ts.Tensor

Float2ByteImage converts float dtype image to uint8 dtype image. It's panic if input is not float dtype tensor.

func HSV2RGB

func HSV2RGB(x *ts.Tensor) *ts.Tensor

func RGB2HSV

func RGB2HSV(x *ts.Tensor) *ts.Tensor

func RandomRotate

func RandomRotate(img *ts.Tensor, min, max float64) (*ts.Tensor, error)

RandomRotate randomly rotates a tensor image within a specifed angle range (degree).

func Rotate

func Rotate(img *ts.Tensor, angle float64) (*ts.Tensor, error)

Types

type AffineOption

type AffineOption func(*affineOptions)

func WithAffineDegree

func WithAffineDegree(degree []int64) AffineOption

func WithAffineFillValue

func WithAffineFillValue(fillValue []float64) AffineOption

func WithAffineMode

func WithAffineMode(mode string) AffineOption

func WithAffineScale

func WithAffineScale(scale []float64) AffineOption

func WithAffineShear

func WithAffineShear(shear []float64) AffineOption

func WithAffineTranslate

func WithAffineTranslate(translate []float64) AffineOption

type Augment

type Augment struct {
	// contains filtered or unexported fields
}

Augment is a struct composes of augmentation functions to implement Transformer interface.

func (*Augment) Transform

func (a *Augment) Transform(image *ts.Tensor) *ts.Tensor

Transform implements Transformer interface for Augment struct.

type CenterCrop

type CenterCrop struct {
	// contains filtered or unexported fields
}

CenterCrop crops the given image at the center. If the image is torch Tensor, it is expected to have [..., H, W] shape, where ... means an arbitrary number of leading dimensions. If image size is smaller than output size along any edge, image is padded with 0 and then center cropped.

func (*CenterCrop) Forward

func (cc *CenterCrop) Forward(x *ts.Tensor) *ts.Tensor

type ColorJitter

type ColorJitter struct {
	// contains filtered or unexported fields
}

func (*ColorJitter) Forward

func (c *ColorJitter) Forward(x *ts.Tensor) *ts.Tensor

Forward implement ts.Module by randomly picking one of brightness, contrast, staturation or hue function to transform input image tensor. NOTE. input image dtype must be `uint8(Byte)`

type ColorOption

type ColorOption func(*colorOptions)

func WithColorBrightness

func WithColorBrightness(v []float64) ColorOption

func WithColorContrast

func WithColorContrast(v []float64) ColorOption

func WithColorHue

func WithColorHue(vals []float64) ColorOption

func WithColorSaturation

func WithColorSaturation(v []float64) ColorOption

type CutoutOption

type CutoutOption func(o *cutoutOptions)

func WithCutoutPvalue

func WithCutoutPvalue(p float64) CutoutOption

func WithCutoutRatio

func WithCutoutRatio(ratio []float64) CutoutOption

func WithCutoutScale

func WithCutoutScale(scale []float64) CutoutOption

func WithCutoutValue

func WithCutoutValue(rgb []int64) CutoutOption

type DownSample

type DownSample struct{}

func (*DownSample) Forward

func (rs *DownSample) Forward(x *ts.Tensor) *ts.Tensor

Forward implements ts.Module for RandRotateModule NOTE. input tensor must be uint8 (Byte) dtype otherwise panic!

type GaussianBlur

type GaussianBlur struct {
	// contains filtered or unexported fields
}

func (*GaussianBlur) Forward

func (b *GaussianBlur) Forward(x *ts.Tensor) *ts.Tensor

type Grayscale

type Grayscale struct {
	// contains filtered or unexported fields
}

GrayScale converts image to grayscale. If the image is torch Tensor, it is expected to have [..., 3, H, W] shape, where ... means an arbitrary number of leading dimensions Args: - num_output_channels (int): (1 or 3) number of channels desired for output image

func NewGrayscale

func NewGrayscale(outChanOpt ...int64) *Grayscale

func (*Grayscale) Forward

func (gs *Grayscale) Forward(x *ts.Tensor) *ts.Tensor

type Normalize

type Normalize struct {
	// contains filtered or unexported fields
}

Normalize normalizes a tensor image with mean and standard deviation. Given mean: “(mean[1],...,mean[n])“ and std: “(std[1],..,std[n])“ for “n“ channels, this transform will normalize each channel of the input “torch.*Tensor“ i.e., “output[channel] = (input[channel] - mean[channel]) / std[channel]“ .. note:: This transform acts out of place, i.e., it does not mutate the input tensor. Args: - mean (sequence): Sequence of means for each channel. - std (sequence): Sequence of standard deviations for each channel.

func (*Normalize) Forward

func (n *Normalize) Forward(x *ts.Tensor) *ts.Tensor

type NormalizeOption

type NormalizeOption func(*normalizeOptions)

func WithNormalizeMean

func WithNormalizeMean(mean []float64) NormalizeOption

func WithNormalizeStd

func WithNormalizeStd(std []float64) NormalizeOption

type Option

type Option func(o *Options)

func OneOf

func OneOf(pvalue float64, tfOpts ...Option) Option

OneOf randomly return one transformer from list of transformers with a specific p value.

func WithCenterCrop

func WithCenterCrop(size []int64) Option

func WithColorJitter

func WithColorJitter(opts ...ColorOption) Option

func WithGaussianBlur

func WithGaussianBlur(ks []int64, sig []float64) Option

func WithNormalize

func WithNormalize(opts ...NormalizeOption) Option

func WithRandRotate

func WithRandRotate(minAngle, maxAngle float64) Option

func WithRandomAdjustSharpness

func WithRandomAdjustSharpness(opts ...SharpnessOption) Option

func WithRandomAffine

func WithRandomAffine(opts ...AffineOption) Option

func WithRandomAutocontrast

func WithRandomAutocontrast(p ...float64) Option

func WithRandomCrop

func WithRandomCrop(size []int64, padding []int64, paddingIfNeeded bool, paddingMode string) Option

func WithRandomCutout

func WithRandomCutout(opts ...CutoutOption) Option

func WithRandomEqualize

func WithRandomEqualize(p ...float64) Option

func WithRandomGrayscale

func WithRandomGrayscale(pvalueOpt ...float64) Option

func WithRandomHFlip

func WithRandomHFlip(pvalue float64) Option

func WithRandomInvert

func WithRandomInvert(pvalueOpt ...float64) Option

func WithRandomPerspective

func WithRandomPerspective(opts ...PerspectiveOption) Option

func WithRandomPosterize

func WithRandomPosterize(opts ...PosterizeOption) Option

func WithRandomSolarize

func WithRandomSolarize(opts ...SolarizeOption) Option

func WithRandomVFlip

func WithRandomVFlip(pvalue float64) Option

func WithResize

func WithResize(h, w int64) Option

func WithRotate

func WithRotate(angle float64) Option

func WithZoomIn

func WithZoomIn(v float64) Option

func WithZoomOut

func WithZoomOut(v float64) Option

type Options

type Options struct {
	// contains filtered or unexported fields
}

type PerspectiveOption

type PerspectiveOption func(*perspectiveOptions)

func WithPerspectiveMode

func WithPerspectiveMode(m string) PerspectiveOption

func WithPerspectivePvalue

func WithPerspectivePvalue(p float64) PerspectiveOption

func WithPerspectiveScale

func WithPerspectiveScale(s float64) PerspectiveOption

func WithPerspectiveValue

func WithPerspectiveValue(v []float64) PerspectiveOption

type PosterizeOption

type PosterizeOption func(*posterizeOptions)

func WithPosterizeBits

func WithPosterizeBits(bits uint8) PosterizeOption

func WithPosterizePvalue

func WithPosterizePvalue(p float64) PosterizeOption

type RandRotateModule

type RandRotateModule struct {
	// contains filtered or unexported fields
}

RandomRotateModule

func (*RandRotateModule) Forward

func (rr *RandRotateModule) Forward(x *ts.Tensor) *ts.Tensor

Forward implements ts.Module for RandRotateModule

type RandomAdjustSharpness

type RandomAdjustSharpness struct {
	// contains filtered or unexported fields
}

Adjust the sharpness of the image randomly with a given probability. If the image is torch Tensor, it is expected to have [..., 1 or 3, H, W] shape, where ... means an arbitrary number of leading dimensions. Args: sharpness_factor (float): How much to adjust the sharpness. Can be any non negative number. 0 gives a blurred image, 1 gives the original image while 2 increases the sharpness by a factor of 2. p (float): probability of the image being color inverted. Default value is 0.5

func (*RandomAdjustSharpness) Forward

func (ras *RandomAdjustSharpness) Forward(x *ts.Tensor) *ts.Tensor

NOTE. input img dtype shoule be `uint8` (Byte)

type RandomAffine

type RandomAffine struct {
	// contains filtered or unexported fields
}

RandomAffine is transformation of the image keeping center invariant. If the image is torch Tensor, it is expected to have [..., H, W] shape, where ... means an arbitrary number of leading dimensions. Args: - degrees (sequence or number): Range of degrees to select from. If degrees is a number instead of sequence like (min, max), the range of degrees will be (-degrees, +degrees). Set to 0 to deactivate rotations. - translate (tuple, optional): tuple of maximum absolute fraction for horizontal and vertical translations. For example translate=(a, b), then horizontal shift is randomly sampled in the range -img_width * a < dx < img_width * a and vertical shift is randomly sampled in the range -img_height * b < dy < img_height * b. Will not translate by default. - scale (tuple, optional): scaling factor interval, e.g (a, b), then scale is randomly sampled from the range a <= scale <= b. Will keep original scale by default. - shear (sequence or number, optional): Range of degrees to select from. If shear is a number, a shear parallel to the x axis in the range (-shear, +shear) will be applied. Else if shear is a sequence of 2 values a shear parallel to the x axis in the range (shear[0], shear[1]) will be applied. Else if shear is a sequence of 4 values, a x-axis shear in (shear[0], shear[1]) and y-axis shear in (shear[2], shear[3]) will be applied. Will not apply shear by default. - interpolation (InterpolationMode): Desired interpolation enum defined by :class:`torchvision.transforms.InterpolationMode`. Default is “InterpolationMode.NEAREST“. If input is Tensor, only “InterpolationMode.NEAREST“, “InterpolationMode.BILINEAR“ are supported. For backward compatibility integer values (e.g. “PIL.Image.NEAREST“) are still acceptable. - fill (sequence or number): Pixel fill value for the area outside the transformed image. Default is “0“. If given a number, the value is used for all bands respectively. Please use the “interpolation“ parameter instead. .. _filters: https://pillow.readthedocs.io/en/latest/handbook/concepts.html#filters

func (*RandomAffine) Forward

func (ra *RandomAffine) Forward(x *ts.Tensor) *ts.Tensor

type RandomAutocontrast

type RandomAutocontrast struct {
	// contains filtered or unexported fields
}

RandomAutocontrast autocontrasts the pixels of the given image randomly with a given probability. If the image is torch Tensor, it is expected to have [..., 1 or 3, H, W] shape, where ... means an arbitrary number of leading dimensions. Args: - p (float): probability of the image being autocontrasted. Default value is 0.5

func (*RandomAutocontrast) Forward

func (rac *RandomAutocontrast) Forward(x *ts.Tensor) *ts.Tensor

type RandomCrop

type RandomCrop struct {
	// contains filtered or unexported fields
}

func (*RandomCrop) Forward

func (c *RandomCrop) Forward(x *ts.Tensor) *ts.Tensor

type RandomCutout

type RandomCutout struct {
	// contains filtered or unexported fields
}

Randomly selects a rectangle region in an torch Tensor image and erases its pixels. This transform does not support PIL Image. 'Random Erasing Data Augmentation' by Zhong et al. See https://arxiv.org/abs/1708.04896

Args: p: probability that the random erasing operation will be performed. scale: range of proportion of erased area against input image. ratio: range of aspect ratio of erased area. value: erasing value. Default is 0. If a single int, it is used to erase all pixels. If a tuple of length 3, it is used to erase R, G, B channels respectively. If a str of 'random', erasing each pixel with random values.

func (*RandomCutout) Forward

func (rc *RandomCutout) Forward(img *ts.Tensor) *ts.Tensor

type RandomEqualize

type RandomEqualize struct {
	// contains filtered or unexported fields
}

RandomEqualize equalizes the histogram of the given image randomly with a given probability. If the image is torch Tensor, it is expected to have [..., 1 or 3, H, W] shape, where ... means an arbitrary number of leading dimensions. Args: - p (float): probability of the image being equalized. Default value is 0.5 Histogram equalization Ref. https://en.wikipedia.org/wiki/Histogram_equalization

func (*RandomEqualize) Forward

func (re *RandomEqualize) Forward(x *ts.Tensor) *ts.Tensor

NOTE. input image MUST be uint8 dtype otherwise panic!

type RandomGrayscale

type RandomGrayscale struct {
	// contains filtered or unexported fields
}

RandomGrayscale randomly converts image to grayscale with a probability of p (default 0.1). If the image is torch Tensor, it is expected to have [..., 3, H, W] shape, where ... means an arbitrary number of leading dimensions Args: - p (float): probability that image should be converted to grayscale.

func (*RandomGrayscale) Forward

func (rgs *RandomGrayscale) Forward(x *ts.Tensor) *ts.Tensor

type RandomHorizontalFlip

type RandomHorizontalFlip struct {
	// contains filtered or unexported fields
}

RandomHorizontalFlip horizontally flips the given image randomly with a given probability.

If the image is torch Tensor, it is expected to have [..., H, W] shape, where ... means an arbitrary number of leading dimensions Args: p (float): probability of the image being flipped. Default value is 0.5

func (*RandomHorizontalFlip) Forward

func (hf *RandomHorizontalFlip) Forward(x *ts.Tensor) *ts.Tensor

type RandomInvert

type RandomInvert struct {
	// contains filtered or unexported fields
}

func (*RandomInvert) Forward

func (ri *RandomInvert) Forward(x *ts.Tensor) *ts.Tensor

type RandomPerspective

type RandomPerspective struct {
	// contains filtered or unexported fields
}

RandomPerspective performs a random perspective transformation of the given image with a given probability. If the image is torch Tensor, it is expected to have [..., H, W] shape, where ... means an arbitrary number of leading dimensions. Args: distortion_scale (float): argument to control the degree of distortion and ranges from 0 to 1. Default is 0.5. p (float): probability of the image being transformed. Default is 0.5. interpolation (InterpolationMode): Desired interpolation enum defined by :class:`torchvision.transforms.InterpolationMode`. Default is “InterpolationMode.BILINEAR“. If input is Tensor, only “InterpolationMode.NEAREST“, “InterpolationMode.BILINEAR“ are supported. For backward compatibility integer values (e.g. “PIL.Image.NEAREST“) are still acceptable. fill (sequence or number): Pixel fill value for the area outside the transformed image. Default is “0“. If given a number, the value is used for all bands respectively.

func (*RandomPerspective) Forward

func (rp *RandomPerspective) Forward(x *ts.Tensor) *ts.Tensor

type RandomPosterize

type RandomPosterize struct {
	// contains filtered or unexported fields
}

RandomPosterize posterizes the image randomly with a given probability by reducing the number of bits for each color channel. If the image is torch Tensor, it should be of type torch.uint8, and it is expected to have [..., 1 or 3, H, W] shape, where ... means an arbitrary number of leading dimensions. Args: - bits (int): number of bits to keep for each channel (0-8) - p (float): probability of the image being color inverted. Default value is 0.5 Ref. https://en.wikipedia.org/wiki/Posterization

func (*RandomPosterize) Forward

func (rp *RandomPosterize) Forward(x *ts.Tensor) *ts.Tensor

NOTE. Input image must be uint8 dtype otherwise panic!

type RandomResizedCrop

type RandomResizedCrop struct{}

TODO.

type RandomSolarize

type RandomSolarize struct {
	// contains filtered or unexported fields
}

RandomSolarize solarizes the image randomly with a given probability by inverting all pixel values above a threshold. If img is a Tensor, it is expected to be in [..., 1 or 3, H, W] format, where ... means it can have an arbitrary number of leading dimensions. If img is PIL Image, it is expected to be in mode "L" or "RGB". Args: - threshold (float): all pixels equal or above this value are inverted. - p (float): probability of the image being color inverted. Default value is 0.5 Ref. https://en.wikipedia.org/wiki/Solarization_(photography)

func (*RandomSolarize) Forward

func (rs *RandomSolarize) Forward(x *ts.Tensor) *ts.Tensor

type RandomVerticalFlip

type RandomVerticalFlip struct {
	// contains filtered or unexported fields
}

RandomVerticalFlip vertically flips the given image randomly with a given probability.

If the image is torch Tensor, it is expected to have [..., H, W] shape, where ... means an arbitrary number of leading dimensions Args: p (float): probability of the image being flipped. Default value is 0.5

func (*RandomVerticalFlip) Forward

func (vf *RandomVerticalFlip) Forward(x *ts.Tensor) *ts.Tensor

type ResizeModule

type ResizeModule struct {
	// contains filtered or unexported fields
}

func (*ResizeModule) Forward

func (rs *ResizeModule) Forward(x *ts.Tensor) *ts.Tensor

Forward implements ts.Module for RandRotateModule NOTE. input tensor must be uint8 (Byte) dtype otherwise panic!

type RotateModule

type RotateModule struct {
	// contains filtered or unexported fields
}

RotateModule

func (*RotateModule) Forward

func (r *RotateModule) Forward(x *ts.Tensor) *ts.Tensor

Forward implements ts.Module for RotateModule

type SharpnessOption

type SharpnessOption func(*sharpnessOptions)

func WithSharpnessFactor

func WithSharpnessFactor(f float64) SharpnessOption

func WithSharpnessPvalue

func WithSharpnessPvalue(p float64) SharpnessOption

type SolarizeOption

type SolarizeOption func(*solarizeOptions)

func WithSolarizePvalue

func WithSolarizePvalue(p float64) SolarizeOption

func WithSolarizeThreshold

func WithSolarizeThreshold(th float64) SolarizeOption

type Transformer

type Transformer interface {
	Transform(x *ts.Tensor) *ts.Tensor
}

Transformer is an interface that can transform an image tensor.

func Compose

func Compose(opts ...Option) (Transformer, error)

Compose creates a new Augment struct by adding augmentation methods.

type ZoomIn

type ZoomIn struct {
	// contains filtered or unexported fields
}

func (*ZoomIn) Forward

func (rs *ZoomIn) Forward(x *ts.Tensor) *ts.Tensor

Forward implements ts.Module for RandRotateModule NOTE. input tensor must be uint8 (Byte) dtype otherwise panic!

type ZoomOut

type ZoomOut struct {
	// contains filtered or unexported fields
}

func (*ZoomOut) Forward

func (rs *ZoomOut) Forward(x *ts.Tensor) *ts.Tensor

Forward implements ts.Module for RandRotateModule NOTE. input tensor must be uint8 (Byte) dtype otherwise panic!

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL