Table of Contents

Class CutMix<T>

Namespace
AiDotNet.Augmentation.Image
Assembly
AiDotNet.dll

Cuts a rectangular region from one image and pastes it onto another (CutMix augmentation).

public class CutMix<T> : LabelMixingAugmentationBase<T, ImageTensor<T>>, ILabelMixingAugmentation<T, ImageTensor<T>>, IAugmentation<T, ImageTensor<T>>

Type Parameters

T

The numeric type for calculations.

Inheritance
CutMix<T>
Implements
Inherited Members

Remarks

CutMix is a regularization technique that combines aspects of Cutout and MixUp. It cuts a rectangular region from one training image and pastes it onto another image. The labels are mixed proportionally to the area of the cut region: y' = λy₁ + (1-λ)y₂ where λ is the ratio of the original image area that remains.

For Beginners: Imagine cutting a square from one photo and pasting it onto another, like cutting a face from one picture and pasting it onto a landscape. The label becomes a mix based on how much of each image is visible. Unlike MixUp which creates "ghostly" blends, CutMix keeps sharp boundaries which can be more natural-looking.

When to use:

  • Image classification as a stronger regularizer than Cutout
  • When you want benefits of both Cutout (occlusion) and MixUp (label smoothing)
  • Often combined with MixUp in training pipelines

When NOT to use:

  • Object detection (the cut region might remove important objects entirely)
  • Semantic segmentation (hard to handle cut region masks)
  • When precise localization information is important

Constructors

CutMix(double, double, double, double)

Creates a new CutMix augmentation.

public CutMix(double alpha = 1, double minCutRatio = 0, double maxCutRatio = 1, double probability = 1)

Parameters

alpha double

The alpha parameter for the Beta distribution that samples the cut area ratio. Industry standard default is 1.0 (uniform distribution).

minCutRatio double

The minimum ratio of the image area that can be cut. Industry standard default is 0.0 (no minimum).

maxCutRatio double

The maximum ratio of the image area that can be cut. Industry standard default is 1.0 (up to entire image).

probability double

The probability of applying this augmentation (0.0 to 1.0). Industry standard default is 1.0 (always applied during training).

Remarks

For Beginners: The alpha parameter controls the size distribution of the cut region. With alpha=1.0, you might cut anything from a tiny corner to almost the whole image. The minCutRatio and maxCutRatio let you constrain this - for example, setting minCutRatio=0.1 and maxCutRatio=0.5 ensures you always cut between 10% and 50% of the image.

Properties

MaxCutRatio

Gets the maximum ratio of the image area that should be cut.

public double MaxCutRatio { get; }

Property Value

double

MinCutRatio

Gets the minimum ratio of the image area that should be cut.

public double MinCutRatio { get; }

Property Value

double

Methods

ApplyAugmentation(ImageTensor<T>, AugmentationContext<T>)

Applies CutMix augmentation (single image version - requires external pairing).

protected override ImageTensor<T> ApplyAugmentation(ImageTensor<T> data, AugmentationContext<T> context)

Parameters

data ImageTensor<T>
context AugmentationContext<T>

Returns

ImageTensor<T>

Remarks

CutMix requires two images. This method returns the image unchanged. Use ApplyCutMix with two images for the actual augmentation.

ApplyCutMix(ImageTensor<T>, ImageTensor<T>, Vector<T>?, Vector<T>?, AugmentationContext<T>)

Applies CutMix by cutting a region from image2 and pasting it onto image1.

public (ImageTensor<T> result, int x1, int y1, int x2, int y2) ApplyCutMix(ImageTensor<T> image1, ImageTensor<T> image2, Vector<T>? labels1, Vector<T>? labels2, AugmentationContext<T> context)

Parameters

image1 ImageTensor<T>

The base image that will receive the cut region.

image2 ImageTensor<T>

The source image from which the region is cut.

labels1 Vector<T>

The labels for the first image.

labels2 Vector<T>

The labels for the second image.

context AugmentationContext<T>

The augmentation context.

Returns

(ImageTensor<T> result, int x1, int y1, int x2, int y2)

The mixed image with the cut region from image2.

Remarks

The lambda value returned represents the proportion of the original image1 that remains visible (1 - cut_area_ratio). Labels should be mixed as: mixed_label = λ * labels1 + (1 - λ) * labels2

GetParameters()

Gets the parameters of this augmentation.

public override IDictionary<string, object> GetParameters()

Returns

IDictionary<string, object>

A dictionary of parameter names to values.