This is a fine-tuned BLIP-2 model that integrates a Swin Transformer for vision and Llama 3.2 (3B) for language generation. It is optimized for plant disease-related visual question answering (VQA) tasks.
1from transformers import Blip2Processor, Blip2ForConditionalGeneration, SwinModel
2from PIL import Image
3
4
5class CustomBlip2ForConditionalGeneration(Blip2ForConditionalGeneration):
6 def __init__(self, config):
7 super().__init__(config)
8 self.vision_model = SwinModel(config.vision_config)
9
10# Load the processor and model
11processor = Blip2Processor.from_pretrained("raghavendrad60/Plant_Disease_SWIN_BLIP2_Llama3.2_3B")
12model = CustomBlip2ForConditionalGeneration.from_pretrained("raghavendrad60/Plant_Disease_SWIN_BLIP2_Llama3.2_3B")
13
14# Prepare an image and text input (e.g., a plant image and a relevant question)
15image = Image.open("path_to_your_image.jpg")
16text = "Q) Name plant and disease."
17
18# Process the inputs
19inputs = processor(image, text, return_tensors="pt", padding="max_length", max_length=512, truncation=True)
20
21# Generate output
22outputs = model(**inputs)
23answer = processor.tokenizer.decode(outputs[0], skip_special_tokens=True)
24print("Answer:", answer)
-
Training Code:
The model was trained using the code available in the
Custom-BLIP-2 GitHub repository.
-
Usage:
This model is designed for research purposes and can be used for plant disease detection and related VQA tasks. It leverages a robust vision encoder and language model to generate high-quality responses.