Oscar<T>

Models & Types · AiDotNet.VisionLanguage.Foundational

Oscar (Object-Semantics Aligned pre-training) using object tags as anchor points.

Inheritance: NeuralNetworkBase<T> → VisionLanguageModelBase<T> → Oscar<T>

Implements: IVisionLanguageFusionModel<T>

For Beginners

Oscar is a vision-language model. Default values follow the original paper settings.

How It Works

Oscar (Li et al., ECCV 2020) uses detected object tags as “anchor points” to ease cross-modal alignment. The input to the transformer is a triple of (word tokens, object tags, region features), processed in a single BERT stream. Pre-training uses masked token loss and contrastive loss.

References:

  • Paper: “Oscar: Object-Semantics Aligned Pre-training for Vision-Language Tasks” (Li et al., ECCV 2020)

Example

// Create an Oscar model for vision-language tasks
// using object tags as anchor points for cross-modal alignment
var architecture = new NeuralNetworkArchitecture<double>(
    inputType: InputType.TwoDimensional,
    taskType: NeuralNetworkTaskType.ImageClassification,
    inputHeight: 224, inputWidth: 224, inputDepth: 3, outputSize: 512);
            
// ONNX inference mode with pre-trained model
var model = new Oscar<double>(architecture, "oscar.onnx");
            
// Training mode with native layers
var trainModel = new Oscar<double>(architecture, new OscarOptions());

Constructors

Constructor Summary
Oscar(NeuralNetworkArchitecture<T> architecture, OscarOptions options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer)
Oscar(NeuralNetworkArchitecture<T> architecture, string modelPath, OscarOptions options)

Properties

Property Summary
int EmbeddingDimension { get; }
int FusionEmbeddingDim { get; }
int MaxSequenceLength { get; }

Methods

Method Summary
ModelMetadata<T> GetModelMetadata()
T ComputeMatchingScore(Tensor<T> image, string text)
Tensor<T> EncodeImage(Tensor<T> image)
Tensor<T> ForwardForTraining(Tensor<T> input)
Tensor<T> FuseImageText(Tensor<T> image, string text)