File size: 1,795 Bytes
9824665
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
---
library_name: peft
base_model: microsoft/Florence-2-base-ft
tags:
  - florence-2
  - lora
  - object-detection
  - subplot-detection
license: mit
---

# plot-visualization-florence-2-lora-32

This is a LoRA fine-tuned version of [microsoft/Florence-2-base-ft](https://huggingface.co/microsoft/Florence-2-base-ft) for detecting subplots in scientific figures.

## Model Details

- **Base Model:** microsoft/Florence-2-base-ft
- **LoRA Rank:** 32
- **Task:** Object Detection (subplot detection)
- **Labels:** `quantitative plot`, `qualitative plot`

## Usage

```python
from pathlib import Path
from PIL import Image
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoProcessor
import torch

# Load model
base_model = "microsoft/Florence-2-base-ft"
processor = AutoProcessor.from_pretrained(base_model, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
    base_model,
    trust_remote_code=True,
    torch_dtype=torch.float16,
)
model = PeftModel.from_pretrained(model, "amayuelas/plot-visualization-florence-2-lora-32")
model = model.merge_and_unload()
model = model.to("cuda")

# Run inference
image = Image.open("your_image.jpg").convert("RGB")
prompt = "<OD>"
inputs = processor(text=prompt, images=image, return_tensors="pt").to("cuda")
inputs["pixel_values"] = inputs["pixel_values"].to(torch.float16)

with torch.no_grad():
    generated_ids = model.generate(
        input_ids=inputs["input_ids"],
        pixel_values=inputs["pixel_values"],
        max_new_tokens=1024,
        num_beams=3,
        use_cache=False,
    )

output = processor.batch_decode(generated_ids, skip_special_tokens=False)[0]
print(output)
```

## Training

This model was fine-tuned using PEFT/LoRA on a dataset of scientific figures with annotated subplots.