Update README.md
Browse files
README.md
CHANGED
@@ -38,7 +38,7 @@ You can use this model for image captioning tasks with the Hugging Face transfor
|
|
38 |
# Installation
|
39 |
|
40 |
To use this model, you need to install the following libraries:
|
41 |
-
|
42 |
bash
|
43 |
Copy code
|
44 |
pip install torch torchvision transformers
|
@@ -48,20 +48,20 @@ Copy code
|
|
48 |
from transformers import VisionEncoderDecoderModel, ViTImageProcessor, GPT2Tokenizer
|
49 |
import torch
|
50 |
from PIL import Image
|
51 |
-
|
52 |
# Load the fine-tuned model and tokenizer
|
53 |
-
|
54 |
model = VisionEncoderDecoderModel.from_pretrained("ashok2216/vit-gpt2-image-captioning_COCO_FineTuned")
|
55 |
processor = ViTImageProcessor.from_pretrained("ashok2216/vit-gpt2-image-captioning_COCO_FineTuned")
|
56 |
tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
|
57 |
-
|
58 |
# Preprocess the image
|
59 |
-
|
60 |
image = Image.open("path_to_image.jpg")
|
61 |
inputs = processor(images=image, return_tensors="pt")
|
62 |
-
|
63 |
# Generate caption
|
64 |
-
|
65 |
pixel_values = inputs.pixel_values
|
66 |
output = model.generate(pixel_values)
|
67 |
caption = tokenizer.decode(output[0], skip_special_tokens=True)
|
@@ -72,7 +72,7 @@ Image Input: The input should be an image file. Supported formats include .jpg,
|
|
72 |
Output: A text string representing the generated caption for the image.
|
73 |
Example
|
74 |
For an input image, the model might generate a caption like:
|
75 |
-
|
76 |
# Input Image:
|
77 |
|
78 |
Generated Caption:
|
|
|
38 |
# Installation
|
39 |
|
40 |
To use this model, you need to install the following libraries:
|
41 |
+
```python
|
42 |
bash
|
43 |
Copy code
|
44 |
pip install torch torchvision transformers
|
|
|
48 |
from transformers import VisionEncoderDecoderModel, ViTImageProcessor, GPT2Tokenizer
|
49 |
import torch
|
50 |
from PIL import Image
|
51 |
+
```
|
52 |
# Load the fine-tuned model and tokenizer
|
53 |
+
```python
|
54 |
model = VisionEncoderDecoderModel.from_pretrained("ashok2216/vit-gpt2-image-captioning_COCO_FineTuned")
|
55 |
processor = ViTImageProcessor.from_pretrained("ashok2216/vit-gpt2-image-captioning_COCO_FineTuned")
|
56 |
tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
|
57 |
+
```
|
58 |
# Preprocess the image
|
59 |
+
```python
|
60 |
image = Image.open("path_to_image.jpg")
|
61 |
inputs = processor(images=image, return_tensors="pt")
|
62 |
+
```
|
63 |
# Generate caption
|
64 |
+
```python
|
65 |
pixel_values = inputs.pixel_values
|
66 |
output = model.generate(pixel_values)
|
67 |
caption = tokenizer.decode(output[0], skip_special_tokens=True)
|
|
|
72 |
Output: A text string representing the generated caption for the image.
|
73 |
Example
|
74 |
For an input image, the model might generate a caption like:
|
75 |
+
```
|
76 |
# Input Image:
|
77 |
|
78 |
Generated Caption:
|