Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,60 @@
|
|
1 |
---
|
2 |
license: mit
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
license: mit
|
3 |
---
|
4 |
+
|
5 |
+
### Simple running code is based on [CoLLaVO-Github](https://github.com/ByungKwanLee/CoLLaVO).
|
6 |
+
|
7 |
+
You need only the following seven steps.
|
8 |
+
|
9 |
+
### [0] Download Github Code of CoLLaVO, install the required libraries, set the necessary environment variable (README.md explains in detail! Don't Worry!).
|
10 |
+
|
11 |
+
```bash
|
12 |
+
git clone https://github.com/ByungKwanLee/CoLLaVO
|
13 |
+
bash install
|
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/crayon_image.jpg"
|
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 CoLlaVO
|
33 |
+
```python
|
34 |
+
from collavo.load_collavo import prepare_collavo
|
35 |
+
collavo_model, collavo_processor, seg_model, seg_processor = prepare_collavo(collavo_path='BK-Lee/CoLLaVO-7B', bits=4, dtype='fp16')
|
36 |
+
|
37 |
+
```
|
38 |
+
|
39 |
+
### [4] Pre-processing for CoLLaVO
|
40 |
+
```python
|
41 |
+
collavo_inputs = collavo_model.demo_process(image=image,
|
42 |
+
prompt=prompt,
|
43 |
+
processor=collavo_processor,
|
44 |
+
seg_model=seg_model,
|
45 |
+
seg_processor=seg_processor,
|
46 |
+
device='cuda:0')
|
47 |
+
```
|
48 |
+
|
49 |
+
### [5] Generate
|
50 |
+
```python
|
51 |
+
import torch
|
52 |
+
with torch.inference_mode():
|
53 |
+
generate_ids = collavo_model.generate(**collavo_inputs, do_sample=True, temperature=0.9, top_p=0.95, max_new_tokens=256, use_cache=True)
|
54 |
+
```
|
55 |
+
|
56 |
+
### [6] Decoding
|
57 |
+
```python
|
58 |
+
answer = collavo_processor.batch_decode(generate_ids, skip_special_tokens=True)[0].split('[U')[0]
|
59 |
+
print(answer)
|
60 |
+
```
|