FerretV2<T>
Models & Types · AiDotNet.VisionLanguage.Grounding
Ferret-v2: improved referring and grounding with enhanced spatial understanding.
Inheritance: NeuralNetworkBase<T> → VisionLanguageModelBase<T> → FerretV2<T>
Implements: IVisualGroundingModel<T>
For Beginners
Ferret-v2 is an improved vision-language model for referring and grounding that handles images at multiple resolutions for better spatial understanding. Default values follow the original paper settings.
How It Works
Ferret-v2 (Zhang et al., 2024) improves upon Ferret with multi-granularity visual encoding that processes images at multiple resolutions, enhanced spatial understanding through DINOv2 features, and a flexible any-resolution scaling approach for handling diverse aspect ratios and input sizes. The multi-granularity design captures both fine-grained details and global context.
References:
- Paper: “Ferret-v2: An Improved Baseline for Referring and Grounding with Multi-Granularity Visual Encoding” (Apple, 2024)
Example
// Create a Ferret-v2 model for improved referring and grounding
// with multi-granularity visual encoding and enhanced spatial understanding
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 FerretV2<double>(architecture, "ferretv2.onnx");
// Training mode with native layers
var trainModel = new FerretV2<double>(architecture, new FerretV2Options());
Constructors
| Constructor | Summary |
|---|---|
FerretV2(NeuralNetworkArchitecture<T> architecture, FerretV2Options options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer) |
|
FerretV2(NeuralNetworkArchitecture<T> architecture, string modelPath, FerretV2Options options) |
Properties
| Property | Summary |
|---|---|
int EmbeddingDimension { get; } |
|
int MaxDetections { get; } |
Methods
| Method | Summary |
|---|---|
ModelMetadata<T> GetModelMetadata() |
|
Tensor<T> DetectObjects(Tensor<T> image, IReadOnlyList<string> categories) |
|
Tensor<T> EncodeImage(Tensor<T> image) |
|
Tensor<T> GroundText(Tensor<T> image, string textQuery) |
Grounds text using Ferret-v2’s any-resolution high-res grounding approach. |