Upload /workspace/ComfyUI/models/LLM/CogFlorence-2.1-Large/README.md with huggingface_hub
Browse files
workspace/ComfyUI/models/LLM/CogFlorence-2.1-Large/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
base_model:
|
| 4 |
+
- microsoft/Florence-2-large
|
| 5 |
+
datasets:
|
| 6 |
+
- Ejafa/ye-pop
|
| 7 |
+
tags:
|
| 8 |
+
- art
|
| 9 |
+
pipeline_tag: image-to-text
|
| 10 |
+
language:
|
| 11 |
+
- en
|
| 12 |
+
library_name: transformers
|
| 13 |
+
---
|
| 14 |
+
# microsoft/Florence-2-large tuned on Ejafa/ye-pop captioned with CogVLM2
|
| 15 |
+
|
| 16 |
+
This repository contains a fine-tuned version of the `microsoft/Florence-2-large` model. The model has been tuned on a 40,000 image subset of the `Ejafa/ye-pop` dataset, with captions generated using `THUDM/cogvlm2-llama3-chat-19B`.
|
| 17 |
+
|
| 18 |
+
## Training Details
|
| 19 |
+
|
| 20 |
+
- **Vision Encoder**: The vision encoder was frozen during training.
|
| 21 |
+
- **Batch Size**: 64
|
| 22 |
+
- **Gradient Accumulation Steps**: 16
|
| 23 |
+
- **Learning Rate**: 5.12e-05
|
| 24 |
+
- **Optimizer**: AdamW
|
| 25 |
+
- **Scheduler**: polynomial
|
| 26 |
+
- **Epochs**: 7.37
|
| 27 |
+
|
| 28 |
+
## Dataset
|
| 29 |
+
|
| 30 |
+
The fine-tuning process utilized a 40,000 image subset from the `Ejafa/ye-pop` dataset. This dataset contains a wide array of images with varying subjects, providing a robust training ground for improving the model's captioning abilities.
|
| 31 |
+
|
| 32 |
+
## Captioning
|
| 33 |
+
|
| 34 |
+
The captions were generated using `THUDM/cogvlm2-llama3-chat-19B`.
|
| 35 |
+
|
| 36 |
+
## Usage
|
| 37 |
+
|
| 38 |
+
To use this model, you can load it directly from the Hugging Face Model Hub:
|
| 39 |
+
|
| 40 |
+
```python
|
| 41 |
+
from transformers import AutoModelForCausalLM, AutoProcessor, AutoConfig
|
| 42 |
+
import torch
|
| 43 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 44 |
+
model = AutoModelForCausalLM.from_pretrained("thwri/CogFlorence-2.1-Large", trust_remote_code=True).to(device).eval()
|
| 45 |
+
processor = AutoProcessor.from_pretrained("thwri/CogFlorence-2.1-Large", trust_remote_code=True)
|
| 46 |
+
# Function to run the model on an example
|
| 47 |
+
def run_example(task_prompt, image):
|
| 48 |
+
prompt = task_prompt
|
| 49 |
+
# Ensure the image is in RGB mode
|
| 50 |
+
if image.mode != "RGB":
|
| 51 |
+
image = image.convert("RGB")
|
| 52 |
+
inputs = processor(text=prompt, images=image, return_tensors="pt").to(device)
|
| 53 |
+
generated_ids = model.generate(
|
| 54 |
+
input_ids=inputs["input_ids"],
|
| 55 |
+
pixel_values=inputs["pixel_values"],
|
| 56 |
+
max_new_tokens=1024,
|
| 57 |
+
num_beams=3,
|
| 58 |
+
do_sample=True
|
| 59 |
+
)
|
| 60 |
+
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=False)[0]
|
| 61 |
+
parsed_answer = processor.post_process_generation(generated_text, task=task_prompt, image_size=(image.width, image.height))
|
| 62 |
+
return parsed_answer
|
| 63 |
+
from PIL import Image
|
| 64 |
+
import requests
|
| 65 |
+
import copy
|
| 66 |
+
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg?download=true"
|
| 67 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
| 68 |
+
result = run_example("<MORE_DETAILED_CAPTION>" , image)
|
| 69 |
+
print(result)
|
| 70 |
+
# {'<MORE_DETAILED_CAPTION>': 'A vivid, close-up photograph of a classic car, specifically a Volkswagen Beetle, parked on a cobblestone street. The car is painted in a striking shade of turquoise, with a glossy finish that reflects the surrounding environment. The vehicle's rounded shape is accentuated by its rounded tires and chrome detailing. The background reveals a weathered yellow wall with a rustic wooden door, adding to the rustic charm of the scene. The sky above is clear, suggesting a sunny day. The overall style of the image is candid, capturing a moment in time without any posed or staged elements.'}
|
| 71 |
+
```
|