Image-Text-to-Text
Transformers
Safetensors
uhr_bat
text-generation
vision-language
remote-sensing
ultra-high-resolution
query-guided-token-compression
qwen2
longva
uhr-bat
conversational
custom_code
Instructions to use RL-MIND/UHR-BAT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use RL-MIND/UHR-BAT with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="RL-MIND/UHR-BAT", trust_remote_code=True) messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("RL-MIND/UHR-BAT", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use RL-MIND/UHR-BAT with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "RL-MIND/UHR-BAT" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "RL-MIND/UHR-BAT", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/RL-MIND/UHR-BAT
- SGLang
How to use RL-MIND/UHR-BAT with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "RL-MIND/UHR-BAT" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "RL-MIND/UHR-BAT", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "RL-MIND/UHR-BAT" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "RL-MIND/UHR-BAT", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use RL-MIND/UHR-BAT with Docker Model Runner:
docker model run hf.co/RL-MIND/UHR-BAT
Update quick start with single-image inference example
Browse files
README.md
CHANGED
|
@@ -55,30 +55,79 @@ The model repository includes `configuration_uhr_bat.py` and `modeling_uhr_bat.p
|
|
| 55 |
## Quick Start
|
| 56 |
|
| 57 |
```python
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
model = AutoModelForCausalLM.from_pretrained(
|
| 61 |
-
|
| 62 |
trust_remote_code=True,
|
| 63 |
torch_dtype="auto",
|
| 64 |
device_map="auto",
|
| 65 |
-
)
|
| 66 |
-
```
|
| 67 |
-
|
| 68 |
-
Tokenizer:
|
| 69 |
-
|
| 70 |
-
```python
|
| 71 |
-
from transformers import AutoTokenizer
|
| 72 |
-
|
| 73 |
-
tokenizer = AutoTokenizer.from_pretrained("FelixKAI/UHR-BAT")
|
| 74 |
-
```
|
| 75 |
|
| 76 |
-
|
|
|
|
|
|
|
| 77 |
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
```
|
| 83 |
|
| 84 |
## Citation
|
|
|
|
| 55 |
## Quick Start
|
| 56 |
|
| 57 |
```python
|
| 58 |
+
import importlib
|
| 59 |
+
import torch
|
| 60 |
+
from PIL import Image
|
| 61 |
+
from transformers import AutoImageProcessor
|
| 62 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 63 |
+
|
| 64 |
+
model_id = "FelixKAI/UHR-BAT"
|
| 65 |
+
image_path = "your_remote_sensing_image.jpg"
|
| 66 |
+
question = "Describe this remote-sensing image."
|
| 67 |
+
|
| 68 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 69 |
+
if tokenizer.pad_token_id is None:
|
| 70 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 71 |
+
image_processor = AutoImageProcessor.from_pretrained(model_id)
|
| 72 |
|
| 73 |
model = AutoModelForCausalLM.from_pretrained(
|
| 74 |
+
model_id,
|
| 75 |
trust_remote_code=True,
|
| 76 |
torch_dtype="auto",
|
| 77 |
device_map="auto",
|
| 78 |
+
).eval()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
+
# Reuse the preprocessing helpers shipped with the model's remote code.
|
| 81 |
+
uhrbat = importlib.import_module(model.__class__.__module__)
|
| 82 |
+
image = Image.open(image_path).convert("RGB")
|
| 83 |
|
| 84 |
+
prompt = (
|
| 85 |
+
"<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n"
|
| 86 |
+
f"<|im_start|>user\n<image>\n{question}<|im_end|>\n"
|
| 87 |
+
"<|im_start|>assistant\n"
|
| 88 |
+
)
|
| 89 |
+
image_token_id = getattr(model.config, "image_token_index", -200)
|
| 90 |
+
input_ids = uhrbat.tokenizer_image_token(
|
| 91 |
+
prompt,
|
| 92 |
+
tokenizer,
|
| 93 |
+
image_token_id,
|
| 94 |
+
return_tensors="pt",
|
| 95 |
+
).unsqueeze(0).to(model.device)
|
| 96 |
+
attention_mask = torch.ones_like(input_ids)
|
| 97 |
+
|
| 98 |
+
target_sizes = [672, 1344, 2688, 4032]
|
| 99 |
+
multiscale_pixels = [
|
| 100 |
+
uhrbat.split_image_to_multiscale_tiles(
|
| 101 |
+
image,
|
| 102 |
+
image_processor,
|
| 103 |
+
target_sizes=target_sizes,
|
| 104 |
+
tile_size=336,
|
| 105 |
+
)
|
| 106 |
+
]
|
| 107 |
+
|
| 108 |
+
with torch.inference_mode():
|
| 109 |
+
output = model.generate(
|
| 110 |
+
inputs=input_ids,
|
| 111 |
+
attention_mask=attention_mask,
|
| 112 |
+
image_sizes=[image.size],
|
| 113 |
+
modalities=["image"],
|
| 114 |
+
multiscale_pixels=multiscale_pixels,
|
| 115 |
+
multiscale_masks=[{}],
|
| 116 |
+
multiscale_topk=[80, 320, 600, 2000],
|
| 117 |
+
multiscale_target_sizes=target_sizes,
|
| 118 |
+
do_sample=False,
|
| 119 |
+
max_new_tokens=256,
|
| 120 |
+
return_dict_in_generate=True,
|
| 121 |
+
output_scores=True,
|
| 122 |
+
pad_token_id=tokenizer.pad_token_id or tokenizer.eos_token_id,
|
| 123 |
+
eos_token_id=tokenizer.eos_token_id,
|
| 124 |
+
)
|
| 125 |
+
|
| 126 |
+
prompt_len = output.sequences.shape[1] - len(output.scores)
|
| 127 |
+
answer_ids = output.sequences[:, prompt_len:].clone()
|
| 128 |
+
answer_ids[answer_ids < 0] = tokenizer.pad_token_id or tokenizer.eos_token_id
|
| 129 |
+
answer = tokenizer.decode(answer_ids[0], skip_special_tokens=True).strip()
|
| 130 |
+
print(answer)
|
| 131 |
```
|
| 132 |
|
| 133 |
## Citation
|