VideoLLaMA2<T>

Models & Types · AiDotNet.VisionLanguage.VideoLanguage

VideoLLaMA 2: spatial-temporal convolution for video tokens.

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

Implements: IVideoLanguageModel<T>

For Beginners

VideoLLaMA 2 is a video-language model with spatial-temporal convolution for efficient video token processing. Default values follow the original paper settings.

How It Works

VideoLLaMA 2 (Alibaba, 2024) advances spatial-temporal modeling for video understanding using convolution-based video token aggregation. It applies spatial-temporal convolutions to compress frame-level visual tokens along both spatial and temporal dimensions, with optional audio branch support for multi-modal video understanding.

References:

  • Paper: “VideoLLaMA 2: Advancing Spatial-Temporal Modeling” (Alibaba, 2024)

Example

// Create a VideoLLaMA 2 model for spatial-temporal video understanding
// with convolution-based video token aggregation and audio support
var architecture = new NeuralNetworkArchitecture<double>(
    inputType: InputType.FourDimensional,
    taskType: NeuralNetworkTaskType.ImageClassification,
    inputHeight: 336, inputWidth: 336, inputDepth: 3, inputFrames: 8, outputSize: 512);
            
// ONNX inference mode with pre-trained model
var model = new VideoLLaMA2<double>(architecture, "videollama2.onnx");
            
// Training mode with native layers
var trainModel = new VideoLLaMA2<double>(architecture, new VideoLLaMA2Options());

Constructors

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

Properties

Property Summary
int DecoderEmbeddingDim { get; }
int EmbeddingDimension { get; }
int MaxFrames { get; }
int MaxGenerationLength { get; }
string LanguageModelName { get; }

Methods

Method Summary
ModelMetadata<T> GetModelMetadata()
Tensor<T> EncodeImage(Tensor<T> image)
Tensor<T> GenerateFromImage(Tensor<T> image, string prompt) Generates from a single image using VideoLLaMA 2’s STC connector in single-frame mode.
Tensor<T> GenerateFromVideo(IReadOnlyList<Tensor<T>> frames, string prompt) Generates output from video frames using VideoLLaMA 2’s Spatial-Temporal Convolution (STC) connector.