Views
No views yet
1git clone https://github.com/Haochen-Wang409/ross.git
2cd ross1conda create -n ross python=3.10 -y
2conda activate ross
3pip install --upgrade pip # enable PEP 660 support
4pip install -e .pip install -e ".[train]"
pip install flash-attn --no-build-isolation1import torch
2from PIL import Image
3
4from ross.model.builder import load_pretrained_model
5from ross.mm_utils import get_model_name_from_path, process_images, tokenizer_image_token
6from ross.eval.run_llava import eval_model
7
8model_path = "HaochenWang/ross-qwen2-7b"
9
10tokenizer, model, image_processor, context_len = load_pretrained_model(
11 model_path=model_path,
12 model_base=None,
13 model_name=get_model_name_from_path(model_path)
14)
15
16model.cuda()
17model.eval()
18
19image = Image.open("...")
20prompt = "..."
21
22images_tensor = process_images(
23 images,
24 image_processor,
25 model.config,
26).cuda()
27
28input_ids = tokenizer_image_token(
29 prompt, tokenizer, IMAGE_TOKEN_INDEX, return_tensors="pt",
30).unsqueeze(0).cuda()
31
32with torch.inference_mode():
33 output_ids = model.generate(
34 input_ids,
35 images=images_tensor,
36 do_sample=True,
37 temperature=0.8,
38 top_p=0.7,
39 top_k=20,
40 num_beams=5,
41 max_new_tokens=512,
42 use_cache=True,
43 )
44
45outputs = tokenizer.batch_decode(output_ids, skip_special_tokens=True)[0].strip()
46print(outputs)1@article{wang2024ross,
2 title={Reconstructive visual instruction tuning},
3 author={Wang, Haochen and Zheng, Anlin and Zhao, Yucheng and Wang, Tiancai and Ge, Zheng and Zhang, Xiangyu and Zhang, Zhaoxiang},
4 journal={arXiv preprint arXiv:2410.09575},
5 year={2024}
6}