Views
No views yet
| Attribute | Value |
|---|---|
| Base Model | OpenGVLab/InternVL3-2B |
| Method | LoRA (Low-Rank Adaptation) |
| LoRA Rank | 128 |
| Target Modules | down_proj, gate_proj, k_proj, o_proj, q_proj, up_proj, v_proj |
| Task | Navigation hazard detection |
1import torch
2from transformers import AutoModel, AutoTokenizer
3from huggingface_hub import hf_hub_download
4from safetensors.torch import load_file
5
6# Load base model
7model = AutoModel.from_pretrained(
8 "OpenGVLab/InternVL3-2B",
9 torch_dtype=torch.bfloat16,
10 trust_remote_code=True,
11 device_map="auto"
12)
13tokenizer = AutoTokenizer.from_pretrained("OpenGVLab/InternVL3-2B", trust_remote_code=True)
14
15# Download adapter weights
16adapter_path = hf_hub_download("blind-assist/internvl3-2b-walk-lora-Epoch3-8500-v2", "adapter_model.safetensors")
17adapter_weights = load_file(adapter_path)
18
19# Merge LoRA weights
20model_state = model.state_dict()
21scaling = 1.0 # lora_alpha / lora_r = 128 / 128
22
23for key in adapter_weights:
24 if '.lora_A.' in key:
25 lora_b_key = key.replace('.lora_A.', '.lora_B.')
26 if lora_b_key in adapter_weights:
27 model_key = key.replace('.lora_A.', '.').replace('base_model.model.', '')
28 if model_key in model_state:
29 lora_a = adapter_weights[key].float().to(model_state[model_key].device)
30 lora_b = adapter_weights[lora_b_key].float().to(model_state[model_key].device)
31 delta = torch.matmul(lora_b, lora_a) * scaling
32 model_state[model_key] = model_state[model_key].float() + delta
33 model_state[model_key] = model_state[model_key].to(torch.bfloat16)
34 elif '.lora_B.' not in key:
35 # Load other fine-tuned weights
36 model_key = key.replace('base_model.model.', '')
37 if model_key in model_state and model_state[model_key].shape == adapter_weights[key].shape:
38 model_state[model_key] = adapter_weights[key].to(model_state[model_key].device)
39
40model.load_state_dict(model_state)
41model.eval()
42
43# Inference
44prompt = "Given the visual input from the user's forward perspective, generate exactly one short sentence to guide a visually impaired user by identifying critical obstacles or landmarks, describing their locations using clock directions relative to the user (12 o'clock is straight ahead), including relevant details such as size, material, or distance, and giving one clear action, while prioritizing immediate safety and avoiding any extra explanation."
45
46response = model.chat(
47 tokenizer=tokenizer,
48 pixel_values=your_image_tensor, # Preprocessed image
49 question=prompt,
50 generation_config=dict(max_new_tokens=256, do_sample=False)
51)
52print(response)1@misc{blindassist2024walkvlm,
2 title={WalkVLM: Fine-tuned Vision-Language Model for Blind Navigation},
3 author={Blind-Assist Team},
4 year={2024},
5 url={https://huggingface.co/blind-assist/internvl3-2b-walk-lora-Epoch3-8500-v2}
6}