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
TThe 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
encoderINeuralNetwork<T>The pretrained encoder.
encoderOutputDimintOutput 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
trainDataTensor<T>Full training data.
trainLabelsint[]Full training labels.
testDataTensor<T>Test data.
testLabelsint[]Test labels.
numClassesintNumber of classes.
percentagesdouble[]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
Returns
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
trainDataTensor<T>Training data.
trainLabelsint[]Training labels.
testDataTensor<T>Test data.
testLabelsint[]Test labels.
numClassesintNumber of classes in the dataset.
epochsintNumber 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
trainDataTensor<T>trainLabelsint[]testDataTensor<T>testLabelsint[]numClassesintdatasetNamestring