Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,92 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: apache-2.0
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
base_model:
|
| 6 |
+
- Lin-Chen/open-llava-next-llama3-8b
|
| 7 |
+
tags:
|
| 8 |
+
- remote sensing
|
| 9 |
+
---
|
| 10 |
+
# Adapting Multimodal Large Language Models to Domains via Post-Training
|
| 11 |
+
|
| 12 |
+
This repo contains the **remote sensing MLLM developed from LLaVA-NeXT-Llama3-8B** in our paper: [On Domain-Specific Post-Training for Multimodal Large Language Models](https://huggingface.co/papers/2411.19930).
|
| 13 |
+
|
| 14 |
+
The main project page is: [Adapt-MLLM-to-Domains](https://huggingface.co/AdaptLLM/Adapt-MLLM-to-Domains/edit/main/README.md)
|
| 15 |
+
|
| 16 |
+
## 1. To Chat with AdaMLLM
|
| 17 |
+
|
| 18 |
+
```python
|
| 19 |
+
from transformers import LlavaNextProcessor, LlavaNextForConditionalGeneration
|
| 20 |
+
import torch
|
| 21 |
+
from PIL import Image
|
| 22 |
+
import requests
|
| 23 |
+
|
| 24 |
+
# Define your input image and instruction here:
|
| 25 |
+
## image
|
| 26 |
+
url = "https://cdn-uploads.huggingface.co/production/uploads/650801ced5578ef7e20b33d4/bRu85CWwP9129bSCRzos2.png"
|
| 27 |
+
image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
|
| 28 |
+
|
| 29 |
+
instruction = "What's in the image?"
|
| 30 |
+
|
| 31 |
+
model_path='AdaptLLM/remote sensing-LLaVA-NeXT-Llama3-8B'
|
| 32 |
+
|
| 33 |
+
# =========================== Do NOT need to modify the following ===============================
|
| 34 |
+
# Load the processor
|
| 35 |
+
processor = LlavaNextProcessor.from_pretrained(model_path)
|
| 36 |
+
|
| 37 |
+
# Define image token
|
| 38 |
+
image_token = "<|reserved_special_token_4|>"
|
| 39 |
+
|
| 40 |
+
# Format the prompt
|
| 41 |
+
prompt = (
|
| 42 |
+
f"<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n\n"
|
| 43 |
+
f"You are a helpful language and vision assistant. You are able to understand the visual content that the user provides, and assist the user with a variety of tasks using natural language."
|
| 44 |
+
f"<|eot_id|><|start_header_id|>user<|end_header_id|>\n\n"
|
| 45 |
+
f"{image_token}\n{instruction}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n"
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
# Load the model
|
| 49 |
+
model = LlavaNextForConditionalGeneration.from_pretrained(model_path, torch_dtype=torch.float16, device_map="auto")
|
| 50 |
+
|
| 51 |
+
# Prepare inputs and generate output
|
| 52 |
+
inputs = processor(images=image, text=prompt, return_tensors="pt").to(model.device)
|
| 53 |
+
answer_start = int(inputs["input_ids"].shape[-1])
|
| 54 |
+
output = model.generate(**inputs, max_new_tokens=512)
|
| 55 |
+
|
| 56 |
+
# Decode predictions
|
| 57 |
+
pred = processor.decode(output[0][answer_start:], skip_special_tokens=True)
|
| 58 |
+
print(pred)
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
## 2. To Evaluate Any MLLM on Domain-Specific Benchmarks
|
| 62 |
+
|
| 63 |
+
Refer to the [remote sensing-VQA-benchmark](https://huggingface.co/datasets/AdaptLLM/remote sensing-VQA-benchmark) to reproduce our results and evaluate many other MLLMs on domain-specific benchmarks.
|
| 64 |
+
|
| 65 |
+
## 3. To Reproduce this Domain-Adapted MLLM
|
| 66 |
+
|
| 67 |
+
See [Post-Train Guide](https://github.com/bigai-ai/QA-Synthesizer/blob/main/docs/Post_Train.md) to adapt MLLMs to domains.
|
| 68 |
+
|
| 69 |
+
## Citation
|
| 70 |
+
If you find our work helpful, please cite us.
|
| 71 |
+
|
| 72 |
+
[AdaMLLM](https://huggingface.co/papers/2411.19930)
|
| 73 |
+
```bibtex
|
| 74 |
+
@article{adamllm,
|
| 75 |
+
title={On Domain-Specific Post-Training for Multimodal Large Language Models},
|
| 76 |
+
author={Cheng, Daixuan and Huang, Shaohan and Zhu, Ziyu and Zhang, Xintong and Zhao, Wayne Xin and Luan, Zhongzhi and Dai, Bo and Zhang, Zhenliang},
|
| 77 |
+
journal={arXiv preprint arXiv:2411.19930},
|
| 78 |
+
year={2024}
|
| 79 |
+
}
|
| 80 |
+
```
|
| 81 |
+
|
| 82 |
+
[Adapt LLM to Domains](https://huggingface.co/papers/2309.09530) (ICLR 2024)
|
| 83 |
+
```bibtex
|
| 84 |
+
@inproceedings{
|
| 85 |
+
cheng2024adapting,
|
| 86 |
+
title={Adapting Large Language Models via Reading Comprehension},
|
| 87 |
+
author={Daixuan Cheng and Shaohan Huang and Furu Wei},
|
| 88 |
+
booktitle={The Twelfth International Conference on Learning Representations},
|
| 89 |
+
year={2024},
|
| 90 |
+
url={https://openreview.net/forum?id=y886UXPEZ0}
|
| 91 |
+
}
|
| 92 |
+
```
|