Table of Contents

Class Cutout<T>

Namespace
AiDotNet.Augmentation.Image
Assembly
AiDotNet.dll

Randomly masks out (cuts out) rectangular regions of an image.

public class Cutout<T> : AugmentationBase<T, ImageTensor<T>>, IAugmentation<T, ImageTensor<T>>

Type Parameters

T

The numeric type for calculations.

Inheritance
Cutout<T>
Implements
Inherited Members

Remarks

Cutout is a regularization technique that randomly removes rectangular patches from training images by filling them with a constant value (usually gray or black). This forces the model to focus on multiple parts of the object rather than relying on a single distinctive feature, improving robustness and generalization.

For Beginners: Imagine covering parts of a photo with sticky notes. If you can still recognize what's in the photo with pieces hidden, you understand the whole object better, not just one specific feature. Cutout does this automatically during training, teaching the model to recognize objects even when parts are obscured.

When to use:

  • Image classification where objects might be partially occluded
  • When you want to prevent the model from overfitting to specific features
  • As a regularization technique to improve generalization

When NOT to use:

  • Object detection or segmentation (might remove the entire object)
  • When fine-grained features are crucial for classification
  • Very small images where cutout would remove too much information

Constructors

Cutout(int, int, int, int, int, T?, double)

Creates a new cutout augmentation.

public Cutout(int numberOfHoles = 1, int minHoleHeight = 8, int maxHoleHeight = 32, int minHoleWidth = 8, int maxHoleWidth = 32, T? fillValue = default, double probability = 0.5)

Parameters

numberOfHoles int

The number of rectangular holes to cut out. Industry standard default is 1 (one hole per image).

minHoleHeight int

The minimum height of each hole in pixels. Industry standard default is 8 pixels.

maxHoleHeight int

The maximum height of each hole in pixels. Industry standard default is 32 pixels.

minHoleWidth int

The minimum width of each hole in pixels. Industry standard default is 8 pixels.

maxHoleWidth int

The maximum width of each hole in pixels. Industry standard default is 32 pixels.

fillValue T

The value to fill the cutout regions with. Use 0 for black, or 0.5 (for normalized images) for gray.

probability double

The probability of applying this augmentation (0.0 to 1.0). Industry standard default is 0.5.

Remarks

For Beginners: The hole size should be large enough to hide meaningful features but not so large that it removes most of the image. For 224x224 images, holes around 16-32 pixels work well. For 32x32 images (like CIFAR-10), use smaller holes around 8-16 pixels.

Properties

FillValue

Gets the fill value for the cutout regions.

public T FillValue { get; }

Property Value

T

MaxHoleHeight

Gets the maximum height of each hole.

public int MaxHoleHeight { get; }

Property Value

int

MaxHoleWidth

Gets the maximum width of each hole.

public int MaxHoleWidth { get; }

Property Value

int

MinHoleHeight

Gets the minimum height of each hole.

public int MinHoleHeight { get; }

Property Value

int

MinHoleWidth

Gets the minimum width of each hole.

public int MinHoleWidth { get; }

Property Value

int

NumberOfHoles

Gets the number of rectangular holes to cut out.

public int NumberOfHoles { get; }

Property Value

int

Methods

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

Applies the cutout to the image.

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

Parameters

data ImageTensor<T>
context AugmentationContext<T>

Returns

ImageTensor<T>

GetParameters()

Gets the parameters of this augmentation.

public override IDictionary<string, object> GetParameters()

Returns

IDictionary<string, object>

A dictionary of parameter names to values.