Add files using upload-large-folder tool
Browse files- 之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/eval_scripts/measure_attention_head/measure_attention_head_COCO_HuatuoGPT_V_34B.sh +24 -0
- 之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/eval_scripts/measure_attention_head/measure_attention_head_COCO_HuatuoGPT_V_7B.sh +24 -0
- 之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/eval_scripts/measure_attention_head/measure_attention_head_COCO_LLaVA_13B.sh +24 -0
- 之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/eval_scripts/measure_attention_head/measure_attention_head_COCO_LLaVA_7B.sh +24 -0
- 之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/eval_scripts/measure_attention_head/measure_attention_head_COCO_LLaVA_Med_7B.sh +24 -0
- 之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/eval_scripts/measure_attention_head/measure_attention_head_COCO_MedGemma_27B_IT.sh +24 -0
- 之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/eval_scripts/measure_attention_head/measure_attention_head_COCO_MedGemma_4B_IT.sh +24 -0
- 之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/eval_scripts/measure_attention_head/measure_attention_head_COCO_Qwen25VL_32B.sh +24 -0
- 之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/eval_scripts/measure_attention_head/measure_attention_head_COCO_Qwen25VL_3B.sh +24 -0
- 之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/eval_scripts/measure_attention_head/measure_attention_head_COCO_Qwen25VL_7B.sh +24 -0
- 之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/eval_scripts/measure_attention_head/measure_attention_head_VGMED_HuatuoGPT_V_34B.sh +21 -0
- 之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/eval_scripts/measure_attention_head/measure_attention_head_VGMED_HuatuoGPT_V_7B.sh +21 -0
- 之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/eval_scripts/measure_attention_head/measure_attention_head_VGMED_LLaVA_7B.sh +21 -0
- 之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/eval_scripts/measure_attention_head/measure_attention_head_VGMED_LLaVA_Med_7B.sh +21 -0
- 之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/eval_scripts/measure_attention_head/measure_attention_head_VGMED_MedGemma_27B_IT.sh +21 -0
- 之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/eval_scripts/measure_attention_head/measure_attention_head_VGMED_MedGemma_4B_IT.sh +21 -0
- 之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/eval_scripts/measure_attention_head/measure_attention_head_VGMED_Qwen25VL_32B.sh +21 -0
- 之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/eval_scripts/measure_attention_head/measure_attention_head_VGMED_Qwen25VL_7B.sh +21 -0
- 之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/models/HealthGPT/llava/demo/gen_infer.py +134 -0
- 之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/models/HealthGPT/llava/demo/utils.py +103 -0
之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/eval_scripts/measure_attention_head/measure_attention_head_COCO_HuatuoGPT_V_34B.sh
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# export HF_ENDPOINT=https://hf-mirror.com
|
| 3 |
+
cd "$(dirname "$0")/../.."
|
| 4 |
+
|
| 5 |
+
MODEL_PATH="FreedomIntelligence/HuatuoGPT-Vision-34B"
|
| 6 |
+
COCO_ROOT="../benchmarks/COCO/val2014"
|
| 7 |
+
COCO_ANNOTATION_ROOT="../benchmarks/COCO"
|
| 8 |
+
OUTPUT_ROOT="attention_results/HuatuoGPT-V-34B"
|
| 9 |
+
|
| 10 |
+
python measure_attention_head.py \
|
| 11 |
+
--dataset COCO \
|
| 12 |
+
--q_type localization \
|
| 13 |
+
--model_path "$MODEL_PATH" \
|
| 14 |
+
--coco_root "$COCO_ROOT" \
|
| 15 |
+
--coco_annotation_root "$COCO_ANNOTATION_ROOT" \
|
| 16 |
+
--output_root "$OUTPUT_ROOT"
|
| 17 |
+
|
| 18 |
+
# python measure_attention_head.py \
|
| 19 |
+
# --dataset COCO \
|
| 20 |
+
# --q_type attribute \
|
| 21 |
+
# --model_path "$MODEL_PATH" \
|
| 22 |
+
# --coco_root "$COCO_ROOT" \
|
| 23 |
+
# --coco_annotation_root "$COCO_ANNOTATION_ROOT" \
|
| 24 |
+
# --output_root "$OUTPUT_ROOT"
|
之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/eval_scripts/measure_attention_head/measure_attention_head_COCO_HuatuoGPT_V_7B.sh
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# export HF_ENDPOINT=https://hf-mirror.com
|
| 3 |
+
cd "$(dirname "$0")/../.."
|
| 4 |
+
|
| 5 |
+
MODEL_PATH="FreedomIntelligence/HuatuoGPT-Vision-7B"
|
| 6 |
+
COCO_ROOT="../benchmarks/COCO/val2014"
|
| 7 |
+
COCO_ANNOTATION_ROOT="../benchmarks/COCO"
|
| 8 |
+
OUTPUT_ROOT="attention_results/HuatuoGPT-V-7B"
|
| 9 |
+
|
| 10 |
+
python measure_attention_head.py \
|
| 11 |
+
--dataset COCO \
|
| 12 |
+
--q_type localization \
|
| 13 |
+
--model_path "$MODEL_PATH" \
|
| 14 |
+
--coco_root "$COCO_ROOT" \
|
| 15 |
+
--coco_annotation_root "$COCO_ANNOTATION_ROOT" \
|
| 16 |
+
--output_root "$OUTPUT_ROOT"
|
| 17 |
+
|
| 18 |
+
# python measure_attention_head.py \
|
| 19 |
+
# --dataset COCO \
|
| 20 |
+
# --q_type attribute \
|
| 21 |
+
# --model_path "$MODEL_PATH" \
|
| 22 |
+
# --coco_root "$COCO_ROOT" \
|
| 23 |
+
# --coco_annotation_root "$COCO_ANNOTATION_ROOT" \
|
| 24 |
+
# --output_root "$OUTPUT_ROOT"
|
之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/eval_scripts/measure_attention_head/measure_attention_head_COCO_LLaVA_13B.sh
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# export HF_ENDPOINT=https://hf-mirror.com
|
| 3 |
+
cd "$(dirname "$0")/../.."
|
| 4 |
+
|
| 5 |
+
MODEL_PATH="llava-hf/llava-v1.6-vicuna-13b-hf"
|
| 6 |
+
COCO_ROOT="../benchmarks/COCO/val2014"
|
| 7 |
+
COCO_ANNOTATION_ROOT="../benchmarks/COCO"
|
| 8 |
+
OUTPUT_ROOT="attention_results/LLaVA-13B"
|
| 9 |
+
|
| 10 |
+
python measure_attention_head.py \
|
| 11 |
+
--dataset COCO \
|
| 12 |
+
--q_type localization \
|
| 13 |
+
--model_path "$MODEL_PATH" \
|
| 14 |
+
--coco_root "$COCO_ROOT" \
|
| 15 |
+
--coco_annotation_root "$COCO_ANNOTATION_ROOT" \
|
| 16 |
+
--output_root "$OUTPUT_ROOT"
|
| 17 |
+
|
| 18 |
+
# python measure_attention_head.py \
|
| 19 |
+
# --dataset COCO \
|
| 20 |
+
# --q_type attribute \
|
| 21 |
+
# --model_path "$MODEL_PATH" \
|
| 22 |
+
# --coco_root "$COCO_ROOT" \
|
| 23 |
+
# --coco_annotation_root "$COCO_ANNOTATION_ROOT" \
|
| 24 |
+
# --output_root "$OUTPUT_ROOT"
|
之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/eval_scripts/measure_attention_head/measure_attention_head_COCO_LLaVA_7B.sh
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# export HF_ENDPOINT=https://hf-mirror.com
|
| 3 |
+
cd "$(dirname "$0")/../.."
|
| 4 |
+
|
| 5 |
+
MODEL_PATH="llava-hf/llava-v1.6-mistral-7b-hf"
|
| 6 |
+
COCO_ROOT="../benchmarks/COCO/val2014"
|
| 7 |
+
COCO_ANNOTATION_ROOT="../benchmarks/COCO"
|
| 8 |
+
OUTPUT_ROOT="attention_results/LLaVA-7B"
|
| 9 |
+
|
| 10 |
+
python measure_attention_head.py \
|
| 11 |
+
--dataset COCO \
|
| 12 |
+
--q_type localization \
|
| 13 |
+
--model_path "$MODEL_PATH" \
|
| 14 |
+
--coco_root "$COCO_ROOT" \
|
| 15 |
+
--coco_annotation_root "$COCO_ANNOTATION_ROOT" \
|
| 16 |
+
--output_root "$OUTPUT_ROOT"
|
| 17 |
+
|
| 18 |
+
# python measure_attention_head.py \
|
| 19 |
+
# --dataset COCO \
|
| 20 |
+
# --q_type attribute \
|
| 21 |
+
# --model_path "$MODEL_PATH" \
|
| 22 |
+
# --coco_root "$COCO_ROOT" \
|
| 23 |
+
# --coco_annotation_root "$COCO_ANNOTATION_ROOT" \
|
| 24 |
+
# --output_root "$OUTPUT_ROOT"
|
之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/eval_scripts/measure_attention_head/measure_attention_head_COCO_LLaVA_Med_7B.sh
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# export HF_ENDPOINT=https://hf-mirror.com
|
| 3 |
+
cd "$(dirname "$0")/../.."
|
| 4 |
+
|
| 5 |
+
MODEL_PATH="microsoft/llava-med-v1.5-mistral-7b"
|
| 6 |
+
COCO_ROOT="../benchmarks/COCO/val2014"
|
| 7 |
+
COCO_ANNOTATION_ROOT="../benchmarks/COCO"
|
| 8 |
+
OUTPUT_ROOT="attention_results/LLaVA-Med-7B"
|
| 9 |
+
|
| 10 |
+
python measure_attention_head.py \
|
| 11 |
+
--dataset COCO \
|
| 12 |
+
--q_type localization \
|
| 13 |
+
--model_path "$MODEL_PATH" \
|
| 14 |
+
--coco_root "$COCO_ROOT" \
|
| 15 |
+
--coco_annotation_root "$COCO_ANNOTATION_ROOT" \
|
| 16 |
+
--output_root "$OUTPUT_ROOT"
|
| 17 |
+
|
| 18 |
+
# python measure_attention_head.py \
|
| 19 |
+
# --dataset COCO \
|
| 20 |
+
# --q_type attribute \
|
| 21 |
+
# --model_path "$MODEL_PATH" \
|
| 22 |
+
# --coco_root "$COCO_ROOT" \
|
| 23 |
+
# --coco_annotation_root "$COCO_ANNOTATION_ROOT" \
|
| 24 |
+
# --output_root "$OUTPUT_ROOT"
|
之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/eval_scripts/measure_attention_head/measure_attention_head_COCO_MedGemma_27B_IT.sh
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# export HF_ENDPOINT=https://hf-mirror.com
|
| 3 |
+
cd "$(dirname "$0")/../.."
|
| 4 |
+
|
| 5 |
+
MODEL_PATH="../checkpoint/models/medgemma-27b-it"
|
| 6 |
+
COCO_ROOT="../benchmarks/COCO/val2014"
|
| 7 |
+
COCO_ANNOTATION_ROOT="../benchmarks/COCO"
|
| 8 |
+
OUTPUT_ROOT="attention_results/MedGemma-27B-IT"
|
| 9 |
+
|
| 10 |
+
python measure_attention_head.py \
|
| 11 |
+
--dataset COCO \
|
| 12 |
+
--q_type localization \
|
| 13 |
+
--model_path "$MODEL_PATH" \
|
| 14 |
+
--coco_root "$COCO_ROOT" \
|
| 15 |
+
--coco_annotation_root "$COCO_ANNOTATION_ROOT" \
|
| 16 |
+
--output_root "$OUTPUT_ROOT"
|
| 17 |
+
|
| 18 |
+
# python measure_attention_head.py \
|
| 19 |
+
# --dataset COCO \
|
| 20 |
+
# --q_type attribute \
|
| 21 |
+
# --model_path "$MODEL_PATH" \
|
| 22 |
+
# --coco_root "$COCO_ROOT" \
|
| 23 |
+
# --coco_annotation_root "$COCO_ANNOTATION_ROOT" \
|
| 24 |
+
# --output_root "$OUTPUT_ROOT"
|
之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/eval_scripts/measure_attention_head/measure_attention_head_COCO_MedGemma_4B_IT.sh
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# export HF_ENDPOINT=https://hf-mirror.com
|
| 3 |
+
cd "$(dirname "$0")/../.."
|
| 4 |
+
|
| 5 |
+
MODEL_PATH="../checkpoint/models/medgemma-4b-it"
|
| 6 |
+
COCO_ROOT="../benchmarks/COCO/val2014"
|
| 7 |
+
COCO_ANNOTATION_ROOT="../benchmarks/COCO"
|
| 8 |
+
OUTPUT_ROOT="attention_results/MedGemma-4B-IT"
|
| 9 |
+
|
| 10 |
+
python measure_attention_head.py \
|
| 11 |
+
--dataset COCO \
|
| 12 |
+
--q_type localization \
|
| 13 |
+
--model_path "$MODEL_PATH" \
|
| 14 |
+
--coco_root "$COCO_ROOT" \
|
| 15 |
+
--coco_annotation_root "$COCO_ANNOTATION_ROOT" \
|
| 16 |
+
--output_root "$OUTPUT_ROOT"
|
| 17 |
+
|
| 18 |
+
# python measure_attention_head.py \
|
| 19 |
+
# --dataset COCO \
|
| 20 |
+
# --q_type attribute \
|
| 21 |
+
# --model_path "$MODEL_PATH" \
|
| 22 |
+
# --coco_root "$COCO_ROOT" \
|
| 23 |
+
# --coco_annotation_root "$COCO_ANNOTATION_ROOT" \
|
| 24 |
+
# --output_root "$OUTPUT_ROOT"
|
之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/eval_scripts/measure_attention_head/measure_attention_head_COCO_Qwen25VL_32B.sh
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# export HF_ENDPOINT=https://hf-mirror.com
|
| 3 |
+
cd "$(dirname "$0")/../.."
|
| 4 |
+
|
| 5 |
+
MODEL_PATH="Qwen/Qwen2.5-VL-32B-Instruct"
|
| 6 |
+
COCO_ROOT="../benchmarks/COCO/val2014"
|
| 7 |
+
COCO_ANNOTATION_ROOT="../benchmarks/COCO"
|
| 8 |
+
OUTPUT_ROOT="attention_results/Qwen2.5VL-32B"
|
| 9 |
+
|
| 10 |
+
python measure_attention_head.py \
|
| 11 |
+
--dataset COCO \
|
| 12 |
+
--q_type localization \
|
| 13 |
+
--model_path "$MODEL_PATH" \
|
| 14 |
+
--coco_root "$COCO_ROOT" \
|
| 15 |
+
--coco_annotation_root "$COCO_ANNOTATION_ROOT" \
|
| 16 |
+
--output_root "$OUTPUT_ROOT"
|
| 17 |
+
|
| 18 |
+
# python measure_attention_head.py \
|
| 19 |
+
# --dataset COCO \
|
| 20 |
+
# --q_type attribute \
|
| 21 |
+
# --model_path "$MODEL_PATH" \
|
| 22 |
+
# --coco_root "$COCO_ROOT" \
|
| 23 |
+
# --coco_annotation_root "$COCO_ANNOTATION_ROOT" \
|
| 24 |
+
# --output_root "$OUTPUT_ROOT"
|
之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/eval_scripts/measure_attention_head/measure_attention_head_COCO_Qwen25VL_3B.sh
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# export HF_ENDPOINT=https://hf-mirror.com
|
| 3 |
+
cd "$(dirname "$0")/../.."
|
| 4 |
+
|
| 5 |
+
MODEL_PATH="Qwen/Qwen2.5-VL-3B-Instruct"
|
| 6 |
+
COCO_ROOT="../benchmarks/COCO/val2014"
|
| 7 |
+
COCO_ANNOTATION_ROOT="../benchmarks/COCO"
|
| 8 |
+
OUTPUT_ROOT="attention_results/Qwen2.5VL-3B"
|
| 9 |
+
|
| 10 |
+
python measure_attention_head.py \
|
| 11 |
+
--dataset COCO \
|
| 12 |
+
--q_type localization \
|
| 13 |
+
--model_path "$MODEL_PATH" \
|
| 14 |
+
--coco_root "$COCO_ROOT" \
|
| 15 |
+
--coco_annotation_root "$COCO_ANNOTATION_ROOT" \
|
| 16 |
+
--output_root "$OUTPUT_ROOT"
|
| 17 |
+
|
| 18 |
+
# python measure_attention_head.py \
|
| 19 |
+
# --dataset COCO \
|
| 20 |
+
# --q_type attribute \
|
| 21 |
+
# --model_path "$MODEL_PATH" \
|
| 22 |
+
# --coco_root "$COCO_ROOT" \
|
| 23 |
+
# --coco_annotation_root "$COCO_ANNOTATION_ROOT" \
|
| 24 |
+
# --output_root "$OUTPUT_ROOT"
|
之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/eval_scripts/measure_attention_head/measure_attention_head_COCO_Qwen25VL_7B.sh
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# export HF_ENDPOINT=https://hf-mirror.com
|
| 3 |
+
cd "$(dirname "$0")/../.."
|
| 4 |
+
|
| 5 |
+
MODEL_PATH="Qwen/Qwen2.5-VL-7B-Instruct"
|
| 6 |
+
COCO_ROOT="../benchmarks/COCO/val2014"
|
| 7 |
+
COCO_ANNOTATION_ROOT="../benchmarks/COCO"
|
| 8 |
+
OUTPUT_ROOT="attention_results/Qwen2.5VL-7B"
|
| 9 |
+
|
| 10 |
+
python measure_attention_head.py \
|
| 11 |
+
--dataset COCO \
|
| 12 |
+
--q_type localization \
|
| 13 |
+
--model_path "$MODEL_PATH" \
|
| 14 |
+
--coco_root "$COCO_ROOT" \
|
| 15 |
+
--coco_annotation_root "$COCO_ANNOTATION_ROOT" \
|
| 16 |
+
--output_root "$OUTPUT_ROOT"
|
| 17 |
+
|
| 18 |
+
# python measure_attention_head.py \
|
| 19 |
+
# --dataset COCO \
|
| 20 |
+
# --q_type attribute \
|
| 21 |
+
# --model_path "$MODEL_PATH" \
|
| 22 |
+
# --coco_root "$COCO_ROOT" \
|
| 23 |
+
# --coco_annotation_root "$COCO_ANNOTATION_ROOT" \
|
| 24 |
+
# --output_root "$OUTPUT_ROOT"
|
之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/eval_scripts/measure_attention_head/measure_attention_head_VGMED_HuatuoGPT_V_34B.sh
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# export HF_ENDPOINT=https://hf-mirror.com
|
| 3 |
+
cd "$(dirname "$0")/../.."
|
| 4 |
+
|
| 5 |
+
MODEL_PATH="FreedomIntelligence/HuatuoGPT-Vision-34B"
|
| 6 |
+
VGMED_ROOT="../benchmarks/VGMED"
|
| 7 |
+
OUTPUT_ROOT="attention_results/HuatuoGPT-V-34B"
|
| 8 |
+
|
| 9 |
+
python measure_attention_head.py \
|
| 10 |
+
--dataset VGMED \
|
| 11 |
+
--q_type localization \
|
| 12 |
+
--model_path "$MODEL_PATH" \
|
| 13 |
+
--vgmed_root "$VGMED_ROOT" \
|
| 14 |
+
--output_root "$OUTPUT_ROOT"
|
| 15 |
+
|
| 16 |
+
# python measure_attention_head.py \
|
| 17 |
+
# --dataset VGMED \
|
| 18 |
+
# --q_type attribute \
|
| 19 |
+
# --model_path "$MODEL_PATH" \
|
| 20 |
+
# --vgmed_root "$VGMED_ROOT" \
|
| 21 |
+
# --output_root "$OUTPUT_ROOT"
|
之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/eval_scripts/measure_attention_head/measure_attention_head_VGMED_HuatuoGPT_V_7B.sh
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# export HF_ENDPOINT=https://hf-mirror.com
|
| 3 |
+
cd "$(dirname "$0")/../.."
|
| 4 |
+
|
| 5 |
+
MODEL_PATH="FreedomIntelligence/HuatuoGPT-Vision-7B"
|
| 6 |
+
VGMED_ROOT="../benchmarks/VGMED"
|
| 7 |
+
OUTPUT_ROOT="attention_results/HuatuoGPT-V-7B"
|
| 8 |
+
|
| 9 |
+
python measure_attention_head.py \
|
| 10 |
+
--dataset VGMED \
|
| 11 |
+
--q_type localization \
|
| 12 |
+
--model_path "$MODEL_PATH" \
|
| 13 |
+
--vgmed_root "$VGMED_ROOT" \
|
| 14 |
+
--output_root "$OUTPUT_ROOT"
|
| 15 |
+
|
| 16 |
+
# python measure_attention_head.py \
|
| 17 |
+
# --dataset VGMED \
|
| 18 |
+
# --q_type attribute \
|
| 19 |
+
# --model_path "$MODEL_PATH" \
|
| 20 |
+
# --vgmed_root "$VGMED_ROOT" \
|
| 21 |
+
# --output_root "$OUTPUT_ROOT"
|
之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/eval_scripts/measure_attention_head/measure_attention_head_VGMED_LLaVA_7B.sh
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# export HF_ENDPOINT=https://hf-mirror.com
|
| 3 |
+
cd "$(dirname "$0")/../.."
|
| 4 |
+
|
| 5 |
+
MODEL_PATH="llava-hf/llava-v1.6-mistral-7b-hf"
|
| 6 |
+
VGMED_ROOT="../benchmarks/VGMED"
|
| 7 |
+
OUTPUT_ROOT="attention_results/LLaVA-7B"
|
| 8 |
+
|
| 9 |
+
python measure_attention_head.py \
|
| 10 |
+
--dataset VGMED \
|
| 11 |
+
--q_type localization \
|
| 12 |
+
--model_path "$MODEL_PATH" \
|
| 13 |
+
--vgmed_root "$VGMED_ROOT" \
|
| 14 |
+
--output_root "$OUTPUT_ROOT"
|
| 15 |
+
|
| 16 |
+
# python measure_attention_head.py \
|
| 17 |
+
# --dataset VGMED \
|
| 18 |
+
# --q_type attribute \
|
| 19 |
+
# --model_path "$MODEL_PATH" \
|
| 20 |
+
# --vgmed_root "$VGMED_ROOT" \
|
| 21 |
+
# --output_root "$OUTPUT_ROOT"
|
之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/eval_scripts/measure_attention_head/measure_attention_head_VGMED_LLaVA_Med_7B.sh
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# export HF_ENDPOINT=https://hf-mirror.com
|
| 3 |
+
cd "$(dirname "$0")/../.."
|
| 4 |
+
|
| 5 |
+
MODEL_PATH="microsoft/llava-med-v1.5-mistral-7b"
|
| 6 |
+
VGMED_ROOT="../benchmarks/VGMED"
|
| 7 |
+
OUTPUT_ROOT="attention_results/LLaVA-Med-7B"
|
| 8 |
+
|
| 9 |
+
python measure_attention_head.py \
|
| 10 |
+
--dataset VGMED \
|
| 11 |
+
--q_type localization \
|
| 12 |
+
--model_path "$MODEL_PATH" \
|
| 13 |
+
--vgmed_root "$VGMED_ROOT" \
|
| 14 |
+
--output_root "$OUTPUT_ROOT"
|
| 15 |
+
|
| 16 |
+
# python measure_attention_head.py \
|
| 17 |
+
# --dataset VGMED \
|
| 18 |
+
# --q_type attribute \
|
| 19 |
+
# --model_path "$MODEL_PATH" \
|
| 20 |
+
# --vgmed_root "$VGMED_ROOT" \
|
| 21 |
+
# --output_root "$OUTPUT_ROOT"
|
之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/eval_scripts/measure_attention_head/measure_attention_head_VGMED_MedGemma_27B_IT.sh
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# export HF_ENDPOINT=https://hf-mirror.com
|
| 3 |
+
cd "$(dirname "$0")/../.."
|
| 4 |
+
|
| 5 |
+
MODEL_PATH="../checkpoint/models/medgemma-27b-it"
|
| 6 |
+
VGMED_ROOT="../benchmarks/VGMED"
|
| 7 |
+
OUTPUT_ROOT="attention_results/MedGemma-27B-IT"
|
| 8 |
+
|
| 9 |
+
python measure_attention_head.py \
|
| 10 |
+
--dataset VGMED \
|
| 11 |
+
--q_type localization \
|
| 12 |
+
--model_path "$MODEL_PATH" \
|
| 13 |
+
--vgmed_root "$VGMED_ROOT" \
|
| 14 |
+
--output_root "$OUTPUT_ROOT"
|
| 15 |
+
|
| 16 |
+
# python measure_attention_head.py \
|
| 17 |
+
# --dataset VGMED \
|
| 18 |
+
# --q_type attribute \
|
| 19 |
+
# --model_path "$MODEL_PATH" \
|
| 20 |
+
# --vgmed_root "$VGMED_ROOT" \
|
| 21 |
+
# --output_root "$OUTPUT_ROOT"
|
之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/eval_scripts/measure_attention_head/measure_attention_head_VGMED_MedGemma_4B_IT.sh
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# export HF_ENDPOINT=https://hf-mirror.com
|
| 3 |
+
cd "$(dirname "$0")/../.."
|
| 4 |
+
|
| 5 |
+
MODEL_PATH="../checkpoint/models/medgemma-4b-it"
|
| 6 |
+
VGMED_ROOT="../benchmarks/VGMED"
|
| 7 |
+
OUTPUT_ROOT="attention_results/MedGemma-4B-IT"
|
| 8 |
+
|
| 9 |
+
python measure_attention_head.py \
|
| 10 |
+
--dataset VGMED \
|
| 11 |
+
--q_type localization \
|
| 12 |
+
--model_path "$MODEL_PATH" \
|
| 13 |
+
--vgmed_root "$VGMED_ROOT" \
|
| 14 |
+
--output_root "$OUTPUT_ROOT"
|
| 15 |
+
|
| 16 |
+
# python measure_attention_head.py \
|
| 17 |
+
# --dataset VGMED \
|
| 18 |
+
# --q_type attribute \
|
| 19 |
+
# --model_path "$MODEL_PATH" \
|
| 20 |
+
# --vgmed_root "$VGMED_ROOT" \
|
| 21 |
+
# --output_root "$OUTPUT_ROOT"
|
之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/eval_scripts/measure_attention_head/measure_attention_head_VGMED_Qwen25VL_32B.sh
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# export HF_ENDPOINT=https://hf-mirror.com
|
| 3 |
+
cd "$(dirname "$0")/../.."
|
| 4 |
+
|
| 5 |
+
MODEL_PATH="Qwen/Qwen2.5-VL-32B-Instruct"
|
| 6 |
+
VGMED_ROOT="../benchmarks/VGMED"
|
| 7 |
+
OUTPUT_ROOT="attention_results/Qwen2.5VL-32B"
|
| 8 |
+
|
| 9 |
+
python measure_attention_head.py \
|
| 10 |
+
--dataset VGMED \
|
| 11 |
+
--q_type localization \
|
| 12 |
+
--model_path "$MODEL_PATH" \
|
| 13 |
+
--vgmed_root "$VGMED_ROOT" \
|
| 14 |
+
--output_root "$OUTPUT_ROOT"
|
| 15 |
+
|
| 16 |
+
# python measure_attention_head.py \
|
| 17 |
+
# --dataset VGMED \
|
| 18 |
+
# --q_type attribute \
|
| 19 |
+
# --model_path "$MODEL_PATH" \
|
| 20 |
+
# --vgmed_root "$VGMED_ROOT" \
|
| 21 |
+
# --output_root "$OUTPUT_ROOT"
|
之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/eval_scripts/measure_attention_head/measure_attention_head_VGMED_Qwen25VL_7B.sh
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# export HF_ENDPOINT=https://hf-mirror.com
|
| 3 |
+
cd "$(dirname "$0")/../.."
|
| 4 |
+
|
| 5 |
+
MODEL_PATH="Qwen/Qwen2.5-VL-7B-Instruct"
|
| 6 |
+
VGMED_ROOT="../benchmarks/VGMED"
|
| 7 |
+
OUTPUT_ROOT="attention_results/Qwen2.5VL-7B"
|
| 8 |
+
|
| 9 |
+
python measure_attention_head.py \
|
| 10 |
+
--dataset VGMED \
|
| 11 |
+
--q_type localization \
|
| 12 |
+
--model_path "$MODEL_PATH" \
|
| 13 |
+
--vgmed_root "$VGMED_ROOT" \
|
| 14 |
+
--output_root "$OUTPUT_ROOT"
|
| 15 |
+
|
| 16 |
+
# python measure_attention_head.py \
|
| 17 |
+
# --dataset VGMED \
|
| 18 |
+
# --q_type attribute \
|
| 19 |
+
# --model_path "$MODEL_PATH" \
|
| 20 |
+
# --vgmed_root "$VGMED_ROOT" \
|
| 21 |
+
# --output_root "$OUTPUT_ROOT"
|
之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/models/HealthGPT/llava/demo/gen_infer.py
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os, sys
|
| 2 |
+
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
|
| 3 |
+
|
| 4 |
+
import copy, re
|
| 5 |
+
from dataclasses import dataclass, field
|
| 6 |
+
import json
|
| 7 |
+
import logging
|
| 8 |
+
import pathlib
|
| 9 |
+
from typing import Dict, Optional, Sequence, List
|
| 10 |
+
import torch
|
| 11 |
+
import transformers
|
| 12 |
+
import tokenizers
|
| 13 |
+
from llava.constants import IGNORE_INDEX, IMAGE_TOKEN_INDEX, DEFAULT_IMAGE_TOKEN, DEFAULT_IM_START_TOKEN, DEFAULT_IM_END_TOKEN
|
| 14 |
+
from torch.utils.data import Dataset
|
| 15 |
+
|
| 16 |
+
from llava import conversation as conversation_lib
|
| 17 |
+
from llava.model import *
|
| 18 |
+
from llava.mm_utils import tokenizer_image_token
|
| 19 |
+
from llava.model.language_model.llava_phi3 import LlavaPhiForCausalLM, LlavaPhiConfig
|
| 20 |
+
from PIL import Image
|
| 21 |
+
import pickle
|
| 22 |
+
import argparse
|
| 23 |
+
from packaging import version
|
| 24 |
+
IS_TOKENIZER_GREATER_THAN_0_14 = version.parse(tokenizers.__version__) >= version.parse('0.14')
|
| 25 |
+
from utils import find_all_linear_names, add_special_tokens_and_resize_model, load_weights, expand2square
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def infer():
|
| 30 |
+
parser = argparse.ArgumentParser()
|
| 31 |
+
parser.add_argument('--model_name_or_path', type=str, default='microsoft/Phi-3-mini-4k-instruct')
|
| 32 |
+
parser.add_argument('--dtype', type=str, default='FP32')
|
| 33 |
+
parser.add_argument('--attn_implementation', type=str, default=None)
|
| 34 |
+
parser.add_argument('--hlora_r', type=int, default=16)
|
| 35 |
+
parser.add_argument('--hlora_alpha', type=int, default=32)
|
| 36 |
+
parser.add_argument('--hlora_dropout', type=float, default=0.0)
|
| 37 |
+
parser.add_argument('--hlora_nums', type=int, default=4)
|
| 38 |
+
parser.add_argument('--vq_idx_nums', type=int, default=1024)
|
| 39 |
+
parser.add_argument('--instruct_template', type=str, default='phi3_instruct')
|
| 40 |
+
parser.add_argument('--vit_path', type=str, default='openai/clip-vit-large-patch14-336')
|
| 41 |
+
parser.add_argument('--hlora_path', type=str, default=None)
|
| 42 |
+
parser.add_argument('--fusion_layer_path', type=str, default=None)
|
| 43 |
+
parser.add_argument('--question', type=str, default=None)
|
| 44 |
+
parser.add_argument('--img_path', type=str, default=None)
|
| 45 |
+
parser.add_argument('--do_sample', type=bool, default=False)
|
| 46 |
+
parser.add_argument('--temperature', type=float, default=0.0)
|
| 47 |
+
parser.add_argument('--top_p', type=float, default=None)
|
| 48 |
+
parser.add_argument('--num_beams', type=int, default=1)
|
| 49 |
+
parser.add_argument('--max_new_tokens', type=int, default=1100)
|
| 50 |
+
parser.add_argument('--save_path', type=str, default='./example.jpg')
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
args = parser.parse_args()
|
| 54 |
+
|
| 55 |
+
model_dtype = torch.float32 if args.dtype == 'FP32' else (torch.float16 if args.dtype == 'FP16' else torch.bfloat16)
|
| 56 |
+
|
| 57 |
+
model = LlavaPhiForCausalLM.from_pretrained(
|
| 58 |
+
pretrained_model_name_or_path=args.model_name_or_path,
|
| 59 |
+
attn_implementation=args.attn_implementation,
|
| 60 |
+
torch_dtype=model_dtype
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
from llava.peft import LoraConfig, get_peft_model
|
| 64 |
+
lora_config = LoraConfig(
|
| 65 |
+
r=args.hlora_r,
|
| 66 |
+
lora_alpha=args.hlora_alpha,
|
| 67 |
+
target_modules=find_all_linear_names(model),
|
| 68 |
+
lora_dropout=args.hlora_dropout,
|
| 69 |
+
bias='none',
|
| 70 |
+
task_type="CAUSAL_LM",
|
| 71 |
+
lora_nums=args.hlora_nums,
|
| 72 |
+
)
|
| 73 |
+
model = get_peft_model(model, lora_config)
|
| 74 |
+
|
| 75 |
+
tokenizer = transformers.AutoTokenizer.from_pretrained(
|
| 76 |
+
args.model_name_or_path,
|
| 77 |
+
padding_side="right",
|
| 78 |
+
use_fast=False,
|
| 79 |
+
)
|
| 80 |
+
num_new_tokens = add_special_tokens_and_resize_model(tokenizer, model, args.vq_idx_nums)
|
| 81 |
+
print(f"Number of new tokens added for unified task: {num_new_tokens}")
|
| 82 |
+
|
| 83 |
+
from utils import gen_vision_args
|
| 84 |
+
gen_vision_args.model_name_or_path = args.model_name_or_path
|
| 85 |
+
gen_vision_args.vision_tower = args.vit_path
|
| 86 |
+
gen_vision_args.version = args.instruct_template
|
| 87 |
+
|
| 88 |
+
model.get_model().initialize_vision_modules(model_args=gen_vision_args)
|
| 89 |
+
model.get_vision_tower().to(dtype=model_dtype)
|
| 90 |
+
|
| 91 |
+
model = load_weights(model, args.hlora_path, args.fusion_layer_path)
|
| 92 |
+
model.eval()
|
| 93 |
+
model.to(model_dtype).cuda()
|
| 94 |
+
|
| 95 |
+
from taming_transformers.idx2img import idx2img
|
| 96 |
+
|
| 97 |
+
question = args.question
|
| 98 |
+
img_path = args.img_path
|
| 99 |
+
|
| 100 |
+
if img_path:
|
| 101 |
+
qs = DEFAULT_IMAGE_TOKEN + '\n' + question
|
| 102 |
+
else:
|
| 103 |
+
qs = question
|
| 104 |
+
conv = conversation_lib.conv_templates[args.instruct_template].copy()
|
| 105 |
+
conv.append_message(conv.roles[0], qs)
|
| 106 |
+
conv.append_message(conv.roles[1], None)
|
| 107 |
+
prompt = conv.get_prompt() + '<start_index>'
|
| 108 |
+
input_ids = tokenizer_image_token(prompt, tokenizer, IMAGE_TOKEN_INDEX, return_tensors='pt').cuda().unsqueeze_(0)
|
| 109 |
+
if img_path:
|
| 110 |
+
image = Image.open(img_path).convert('RGB')
|
| 111 |
+
image = expand2square(image, tuple(int(x*255) for x in model.get_vision_tower().image_processor.image_mean))
|
| 112 |
+
image_tensor = model.get_vision_tower().image_processor.preprocess(image, return_tensors='pt')['pixel_values'][0].unsqueeze_(0)
|
| 113 |
+
with torch.inference_mode():
|
| 114 |
+
output_ids = model.base_model.model.generate(
|
| 115 |
+
input_ids,
|
| 116 |
+
images=image_tensor.to(dtype=model_dtype, device='cuda', non_blocking=True) if img_path else None,
|
| 117 |
+
image_sizes=image.size if img_path else None,
|
| 118 |
+
do_sample=args.do_sample,
|
| 119 |
+
temperature=args.temperature,
|
| 120 |
+
top_p=args.top_p,
|
| 121 |
+
num_beams=args.num_beams,
|
| 122 |
+
max_new_tokens=args.max_new_tokens,
|
| 123 |
+
use_cache=True)
|
| 124 |
+
|
| 125 |
+
response = [int(idx) for idx in re.findall(r'\d+', tokenizer.decode(output_ids[0])[:-8])]
|
| 126 |
+
print(f'Q: {question}')
|
| 127 |
+
print(f'HealthGPT: {response}')
|
| 128 |
+
idx2img(torch.tensor(response).cuda(), args.save_path)
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
if __name__ == "__main__":
|
| 133 |
+
|
| 134 |
+
infer()
|
之前的代码版本/第一版-全部代码/MedEvalKit-v1-v1-fullcode/models/HealthGPT/llava/demo/utils.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import transformers
|
| 3 |
+
import tokenizers
|
| 4 |
+
import os, sys
|
| 5 |
+
from dataclasses import dataclass, field
|
| 6 |
+
import argparse
|
| 7 |
+
from PIL import Image
|
| 8 |
+
|
| 9 |
+
def expand2square(pil_img, background_color):
|
| 10 |
+
width, height = pil_img.size
|
| 11 |
+
if width == height:
|
| 12 |
+
return pil_img
|
| 13 |
+
elif width > height:
|
| 14 |
+
result = Image.new(pil_img.mode, (width, width), background_color)
|
| 15 |
+
result.paste(pil_img, (0, (width - height) // 2))
|
| 16 |
+
return result
|
| 17 |
+
else:
|
| 18 |
+
result = Image.new(pil_img.mode, (height, height), background_color)
|
| 19 |
+
result.paste(pil_img, ((height - width) // 2, 0))
|
| 20 |
+
return result
|
| 21 |
+
|
| 22 |
+
def find_all_linear_names(model):
|
| 23 |
+
cls = torch.nn.Linear
|
| 24 |
+
lora_module_names = set()
|
| 25 |
+
multimodal_keywords = ['mm_projector', 'vision_tower', 'vision_resampler']
|
| 26 |
+
for name, module in model.named_modules():
|
| 27 |
+
if any(mm_keyword in name for mm_keyword in multimodal_keywords):
|
| 28 |
+
continue
|
| 29 |
+
if isinstance(module, cls):
|
| 30 |
+
names = name.split('.')
|
| 31 |
+
lora_module_names.add(names[0] if len(names) == 1 else names[-1])
|
| 32 |
+
|
| 33 |
+
if 'lm_head' in lora_module_names: # needed for 16-bit
|
| 34 |
+
lora_module_names.remove('lm_head')
|
| 35 |
+
return list(lora_module_names)
|
| 36 |
+
|
| 37 |
+
def add_special_tokens_and_resize_model(tokenizer, model, vq_idx_nums=8192):
|
| 38 |
+
if len(tokenizer.additional_special_tokens) != 0:
|
| 39 |
+
return tokenizer.additional_special_tokens
|
| 40 |
+
index_tokens = [f"<idx_{i}>" for i in range(vq_idx_nums)]
|
| 41 |
+
special_tokens = {
|
| 42 |
+
'additional_special_tokens': ['<start_index>'] + index_tokens + ['<end_index>'] + ['<pixel_newline>']
|
| 43 |
+
}
|
| 44 |
+
num_new_tokens = tokenizer.add_special_tokens(special_tokens)
|
| 45 |
+
model.resize_token_embeddings(len(tokenizer))
|
| 46 |
+
if num_new_tokens > 0:
|
| 47 |
+
input_embeddings = model.get_input_embeddings().weight.data
|
| 48 |
+
output_embeddings = model.get_output_embeddings().weight.data
|
| 49 |
+
|
| 50 |
+
input_embeddings_avg = input_embeddings[:-num_new_tokens].mean(
|
| 51 |
+
dim=0, keepdim=True)
|
| 52 |
+
output_embeddings_avg = output_embeddings[:-num_new_tokens].mean(
|
| 53 |
+
dim=0, keepdim=True)
|
| 54 |
+
|
| 55 |
+
input_embeddings[-num_new_tokens:] = input_embeddings_avg
|
| 56 |
+
output_embeddings[-num_new_tokens:] = output_embeddings_avg
|
| 57 |
+
|
| 58 |
+
return num_new_tokens
|
| 59 |
+
|
| 60 |
+
com_vision_args = argparse.Namespace(
|
| 61 |
+
freeze_backbone=False,
|
| 62 |
+
mm_patch_merge_type='flat',
|
| 63 |
+
mm_projector_type='mlp2x_gelu',
|
| 64 |
+
mm_use_im_patch_token=False,
|
| 65 |
+
mm_use_im_start_end=False,
|
| 66 |
+
mm_vision_select_feature='patch',
|
| 67 |
+
mm_vision_select_layer=-2,
|
| 68 |
+
model_name_or_path=None,
|
| 69 |
+
pretrain_mm_mlp_adapter=None,
|
| 70 |
+
tune_mm_mlp_adapter=False,
|
| 71 |
+
version=None,
|
| 72 |
+
vision_tower=None
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
gen_vision_args = argparse.Namespace(
|
| 76 |
+
freeze_backbone=False,
|
| 77 |
+
mm_patch_merge_type='flat',
|
| 78 |
+
mm_projector_type='mlp2x_gelu',
|
| 79 |
+
mm_use_im_patch_token=False,
|
| 80 |
+
mm_use_im_start_end=False,
|
| 81 |
+
mm_vision_select_feature='patch',
|
| 82 |
+
mm_vision_select_layer=1,
|
| 83 |
+
model_name_or_path=None,
|
| 84 |
+
pretrain_mm_mlp_adapter=None,
|
| 85 |
+
tune_mm_mlp_adapter=False,
|
| 86 |
+
version=None,
|
| 87 |
+
vision_tower=None
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
def load_weights(model, hlora_path, fusion_layer_path=None):
|
| 91 |
+
hlora_weights = torch.load(hlora_path)
|
| 92 |
+
hlora_unexpected_keys = model.load_state_dict(hlora_weights, strict=False)[1]
|
| 93 |
+
if hlora_unexpected_keys:
|
| 94 |
+
print(f"Warning: Unexpected keys in hlora checkpoint: {hlora_unexpected_keys}")
|
| 95 |
+
|
| 96 |
+
if fusion_layer_path:
|
| 97 |
+
fusion_layer_weights = torch.load(fusion_layer_path)
|
| 98 |
+
fusion_layer_unexpected_keys = model.load_state_dict(fusion_layer_weights, strict=False)[1]
|
| 99 |
+
if fusion_layer_unexpected_keys:
|
| 100 |
+
print(f"Warning: Unexpected keys in fusion_layer checkpoint: {fusion_layer_unexpected_keys}")
|
| 101 |
+
|
| 102 |
+
return model
|
| 103 |
+
|