Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,64 @@
|
|
| 1 |
---
|
| 2 |
license: mit
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: mit
|
| 3 |
---
|
| 4 |
+
|
| 5 |
+
### Simple running code is based on [MoAI-Github](https://github.com/ByungKwanLee/MoAI).
|
| 6 |
+
|
| 7 |
+
You need only the following seven steps.
|
| 8 |
+
|
| 9 |
+
### [0] Download Github Code of MoAI.
|
| 10 |
+
|
| 11 |
+
```bash
|
| 12 |
+
git clone https://github.com/ByungKwanLee/MoAI
|
| 13 |
+
```
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
### [1] Loading Image
|
| 17 |
+
|
| 18 |
+
```python
|
| 19 |
+
from PIL import Image
|
| 20 |
+
from torchvision.transforms import Resize
|
| 21 |
+
from torchvision.transforms.functional import pil_to_tensor
|
| 22 |
+
image_path = "figures/moai_mystery.png"
|
| 23 |
+
image = Resize(size=(490, 490), antialias=False)(pil_to_tensor(Image.open(image_path)))
|
| 24 |
+
```
|
| 25 |
+
|
| 26 |
+
### [2] Instruction Prompt
|
| 27 |
+
|
| 28 |
+
```python
|
| 29 |
+
prompt = "Describe this image in detail."
|
| 30 |
+
```
|
| 31 |
+
|
| 32 |
+
### [3] Loading MoAI
|
| 33 |
+
```python
|
| 34 |
+
from moai.load_moai import prepare_moai
|
| 35 |
+
moai_model, moai_processor, seg_model, seg_processor, od_model, od_processor, sgg_model, ocr_model \
|
| 36 |
+
= prepare_moai(moai_path='/mnt/ssd/lbk-cvpr/MoAI/final', bits=4, grad_ckpt=False, lora=False, dtype='fp16')
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
### [4] Pre-processing for MoAI
|
| 40 |
+
```python
|
| 41 |
+
moai_inputs = moai_model.demo_process(image=image,
|
| 42 |
+
prompt=prompt,
|
| 43 |
+
processor=moai_processor,
|
| 44 |
+
seg_model=seg_model,
|
| 45 |
+
seg_processor=seg_processor,
|
| 46 |
+
od_model=od_model,
|
| 47 |
+
od_processor=od_processor,
|
| 48 |
+
sgg_model=sgg_model,
|
| 49 |
+
ocr_model=ocr_model,
|
| 50 |
+
device='cuda:0')
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
### [5] Generate
|
| 54 |
+
```python
|
| 55 |
+
import torch
|
| 56 |
+
with torch.inference_mode():
|
| 57 |
+
generate_ids = moai_model.generate(**moai_inputs, do_sample=True, temperature=0.9, top_p=0.95, max_new_tokens=256, use_cache=True)
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
### [6] Decoding
|
| 61 |
+
```python
|
| 62 |
+
answer = moai_processor.batch_decode(generate_ids, skip_special_tokens=True)[0].split('[U')[0]
|
| 63 |
+
print(answer)
|
| 64 |
+
```
|