Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,83 @@
|
|
1 |
-
---
|
2 |
-
license: apache-2.0
|
3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
---
|
4 |
+
|
5 |
+
vit-gpt2-image-captioning_COCO_FineTuned
|
6 |
+
This repository contains the fine-tuned ViT-GPT2 model for image captioning, trained on the COCO dataset. The model combines a Vision Transformer (ViT) for image feature extraction and GPT-2 for text generation to create descriptive captions from images.
|
7 |
+
|
8 |
+
Model Overview
|
9 |
+
Model Type: Vision Transformer (ViT) + GPT-2
|
10 |
+
Dataset: COCO (Common Objects in Context)
|
11 |
+
Task: Image Captioning
|
12 |
+
This model generates captions for input images based on the objects and contexts identified within the images. It has been fine-tuned on the COCO dataset, which includes a wide variety of images with detailed annotations, making it suitable for diverse image captioning tasks.
|
13 |
+
|
14 |
+
Model Details
|
15 |
+
The model architecture consists of two main components:
|
16 |
+
|
17 |
+
Vision Transformer (ViT): A powerful image encoder that extracts feature maps from input images.
|
18 |
+
GPT-2: A language model that generates human-like text, fine-tuned to generate captions based on the extracted image features.
|
19 |
+
The model has been trained to:
|
20 |
+
|
21 |
+
Recognize objects and scenes from images.
|
22 |
+
Generate grammatically correct and contextually accurate captions.
|
23 |
+
Usage
|
24 |
+
You can use this model for image captioning tasks with the Hugging Face transformers library. Below is a sample code to load the model and generate captions for input images.
|
25 |
+
|
26 |
+
Installation
|
27 |
+
To use this model, you need to install the following libraries:
|
28 |
+
|
29 |
+
bash
|
30 |
+
Copy code
|
31 |
+
pip install torch torchvision transformers
|
32 |
+
Code Example
|
33 |
+
python
|
34 |
+
Copy code
|
35 |
+
from transformers import VisionEncoderDecoderModel, ViTImageProcessor, GPT2Tokenizer
|
36 |
+
import torch
|
37 |
+
from PIL import Image
|
38 |
+
|
39 |
+
# Load the fine-tuned model and tokenizer
|
40 |
+
model = VisionEncoderDecoderModel.from_pretrained("ashok2216/vit-gpt2-image-captioning_COCO_FineTuned")
|
41 |
+
processor = ViTImageProcessor.from_pretrained("ashok2216/vit-gpt2-image-captioning_COCO_FineTuned")
|
42 |
+
tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
|
43 |
+
|
44 |
+
# Preprocess the image
|
45 |
+
image = Image.open("path_to_image.jpg")
|
46 |
+
inputs = processor(images=image, return_tensors="pt")
|
47 |
+
|
48 |
+
# Generate caption
|
49 |
+
pixel_values = inputs.pixel_values
|
50 |
+
output = model.generate(pixel_values)
|
51 |
+
caption = tokenizer.decode(output[0], skip_special_tokens=True)
|
52 |
+
|
53 |
+
print("Generated Caption:", caption)
|
54 |
+
Inputs
|
55 |
+
Image Input: The input should be an image file. Supported formats include .jpg, .png, etc.
|
56 |
+
Output: A text string representing the generated caption for the image.
|
57 |
+
Example
|
58 |
+
For an input image, the model might generate a caption like:
|
59 |
+
|
60 |
+
Input Image:
|
61 |
+
|
62 |
+
Generated Caption:
|
63 |
+
"A group of people walking down the street with umbrellas in their hands."
|
64 |
+
|
65 |
+
Fine-Tuning Details
|
66 |
+
Dataset: COCO dataset (common objects in context)
|
67 |
+
Image Size: 224x224 pixels
|
68 |
+
Training Time: ~12 hours on a GPU (depending on batch size and hardware)
|
69 |
+
Fine-Tuning Strategy: We fine-tuned the ViT-GPT2 model for 5 epochs using the COCO training split.
|
70 |
+
Model Performance
|
71 |
+
This model performs well on various image captioning benchmarks. However, its performance is highly dependent on the diversity and quality of the input image. It is recommended to fine-tune or retrain the model further for more specific domains if necessary.
|
72 |
+
|
73 |
+
Limitations
|
74 |
+
The model might struggle with generating accurate captions for highly ambiguous or abstract images.
|
75 |
+
It is trained primarily on the COCO dataset and might perform better on images with similar contexts to the training data.
|
76 |
+
License
|
77 |
+
This model is licensed under the MIT License.
|
78 |
+
|
79 |
+
Acknowledgments
|
80 |
+
COCO Dataset: The model was trained on the COCO dataset, which is widely used for image captioning tasks.
|
81 |
+
Hugging Face: For providing the platform to share models and facilitate easy usage of transformer-based models.
|
82 |
+
Contact
|
83 |
+
For any questions, please contact Ashok Kumar.
|