Table of Contents

Class TransferBenchmark<T>

Namespace
AiDotNet.SelfSupervisedLearning.Evaluation
Assembly
AiDotNet.dll

Transfer learning benchmark for evaluating SSL representations on downstream tasks.

public class TransferBenchmark<T>

Type Parameters

T

The numeric type used for computations.

Inheritance
TransferBenchmark<T>
Inherited Members

Remarks

For Beginners: Transfer learning benchmarks test how well pretrained representations transfer to new tasks. We take an encoder pretrained on one dataset (e.g., ImageNet) and evaluate it on different tasks (e.g., object detection, segmentation).

Common transfer benchmarks:

  • Classification: CIFAR-10/100, Food-101, Flowers-102
  • Detection: PASCAL VOC, COCO
  • Segmentation: Cityscapes, ADE20K
  • Fine-grained: iNaturalist, Cars, Aircraft

Evaluation protocols:

  • Linear probing: Freeze encoder, train linear head
  • Fine-tuning: Update all parameters with lower learning rate
  • Few-shot: Train with limited labeled data (1%, 10%)

Constructors

TransferBenchmark(INeuralNetwork<T>, int)

Initializes a new instance of the TransferBenchmark class.

public TransferBenchmark(INeuralNetwork<T> encoder, int encoderOutputDim)

Parameters

encoder INeuralNetwork<T>

The pretrained encoder.

encoderOutputDim int

Output dimension of the encoder.

Methods

FewShotEvaluation(Tensor<T>, int[], Tensor<T>, int[], int, double[])

Runs few-shot evaluation with limited labeled data.

public Dictionary<double, BenchmarkResult<T>> FewShotEvaluation(Tensor<T> trainData, int[] trainLabels, Tensor<T> testData, int[] testLabels, int numClasses, double[] percentages)

Parameters

trainData Tensor<T>

Full training data.

trainLabels int[]

Full training labels.

testData Tensor<T>

Test data.

testLabels int[]

Test labels.

numClasses int

Number of classes.

percentages double[]

Percentages of training data to use.

Returns

Dictionary<double, BenchmarkResult<T>>

Results for each percentage.

KNNEvaluation(Tensor<T>, int[], Tensor<T>, int[], int)

Runs k-NN evaluation on a downstream dataset.

public BenchmarkResult<T> KNNEvaluation(Tensor<T> trainData, int[] trainLabels, Tensor<T> testData, int[] testLabels, int k = 20)

Parameters

trainData Tensor<T>
trainLabels int[]
testData Tensor<T>
testLabels int[]
k int

Returns

BenchmarkResult<T>

LinearProbing(Tensor<T>, int[], Tensor<T>, int[], int, int)

Runs linear probing evaluation on a downstream dataset.

public BenchmarkResult<T> LinearProbing(Tensor<T> trainData, int[] trainLabels, Tensor<T> testData, int[] testLabels, int numClasses, int epochs = 90)

Parameters

trainData Tensor<T>

Training data.

trainLabels int[]

Training labels.

testData Tensor<T>

Test data.

testLabels int[]

Test labels.

numClasses int

Number of classes in the dataset.

epochs int

Number of training epochs.

Returns

BenchmarkResult<T>

Benchmark result with accuracy metrics.

RunFullSuite(Tensor<T>, int[], Tensor<T>, int[], int, string)

Runs a full benchmark suite.

public BenchmarkSuite<T> RunFullSuite(Tensor<T> trainData, int[] trainLabels, Tensor<T> testData, int[] testLabels, int numClasses, string datasetName = "Unknown")

Parameters

trainData Tensor<T>
trainLabels int[]
testData Tensor<T>
testLabels int[]
numClasses int
datasetName string

Returns

BenchmarkSuite<T>