MedFlamingo<T>

Models & Types · AiDotNet.VisionLanguage.Medical

Med-Flamingo: few-shot medical visual question answering via Flamingo architecture.

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

Implements: IMedicalVLM<T>

For Beginners

Med-Flamingo is a vision-language model for few-shot medical visual question answering using the Flamingo architecture. Default values follow the original paper settings.

How It Works

Med-Flamingo (2023) adapts the OpenFlamingo architecture for few-shot medical visual question answering. It uses gated cross-attention layers to interleave medical image features with text tokens and a perceiver resampler to compress visual information, enabling the model to learn from just a few medical image-text examples without extensive fine-tuning.

References:

  • Paper: “Med-Flamingo: A Multimodal Medical Few-shot Learner (Various, 2023)”

Example

// Create a Med-Flamingo model for few-shot medical visual question answering
// with gated cross-attention and perceiver resampler from OpenFlamingo
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 MedFlamingo<double>(architecture, "medflamingo.onnx");
            
// Training mode with native layers
var trainModel = new MedFlamingo<double>(architecture, new MedFlamingoOptions());

Constructors

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

Properties

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

Methods

Method Summary
ModelMetadata<T> GetModelMetadata()
Tensor<T> AnswerMedicalQuestion(Tensor<T> image, string question)
Tensor<T> EncodeImage(Tensor<T> image)
Tensor<T> GenerateFromImage(Tensor<T> image, string prompt) Generates text from a medical image using Med-Flamingo’s gated cross-attention pipeline.