Add files using upload-large-folder tool
Browse files- benchmarks/COCO/COCO_attribute.jsonl +0 -0
- benchmarks/COCO/COCO_localization.jsonl +0 -0
- benchmarks/COCO/val2014/COCO_val2014_000000052238.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000058472.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000085160.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000089761.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000110906.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000115796.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000128262.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000139872.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000153392.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000155885.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000169849.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000181506.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000188308.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000205883.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000227224.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000243775.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000250870.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000275657.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000276458.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000283147.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000290165.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000308555.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000313130.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000316596.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000329957.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000330098.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000347648.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000356094.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000361238.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000369323.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000371529.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000382288.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000390975.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000428881.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000483553.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000484915.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000492552.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000493022.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000502844.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000519703.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000536791.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000550864.jpg +3 -0
- benchmarks/COCO/val2014/COCO_val2014_000000564851.jpg +3 -0
- download_data.py +113 -0
- download_sam3_assets.py +89 -0
- gpu1_hold_30g.log +2 -0
- predownload_models-ori.py +99 -0
- predownload_models.py +102 -0
benchmarks/COCO/COCO_attribute.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
benchmarks/COCO/COCO_localization.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
benchmarks/COCO/val2014/COCO_val2014_000000052238.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000058472.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000085160.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000089761.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000110906.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000115796.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000128262.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000139872.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000153392.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000155885.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000169849.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000181506.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000188308.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000205883.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000227224.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000243775.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000250870.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000275657.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000276458.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000283147.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000290165.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000308555.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000313130.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000316596.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000329957.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000330098.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000347648.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000356094.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000361238.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000369323.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000371529.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000382288.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000390975.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000428881.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000483553.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000484915.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000492552.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000493022.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000502844.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000519703.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000536791.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000550864.jpg
ADDED
|
Git LFS Details
|
benchmarks/COCO/val2014/COCO_val2014_000000564851.jpg
ADDED
|
Git LFS Details
|
download_data.py
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Download multiple datasets from Hugging Face and COCO."""
|
| 2 |
+
|
| 3 |
+
import argparse
|
| 4 |
+
import os
|
| 5 |
+
import sys
|
| 6 |
+
from huggingface_hub import snapshot_download
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
COCO_VAL_URL = "http://images.cocodataset.org/zips/val2014.zip"
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def download_huggingface_dataset(repo_id: str, output_dir: str, use_auth_token: bool) -> str:
|
| 13 |
+
os.makedirs(output_dir, exist_ok=True)
|
| 14 |
+
print(f"Downloading Hugging Face dataset {repo_id} to '{output_dir}'...")
|
| 15 |
+
local_dir = snapshot_download(
|
| 16 |
+
repo_id=repo_id,
|
| 17 |
+
repo_type="dataset",
|
| 18 |
+
local_dir=output_dir,
|
| 19 |
+
use_auth_token=use_auth_token,
|
| 20 |
+
)
|
| 21 |
+
print(f"Finished: {repo_id} -> {local_dir}\n")
|
| 22 |
+
return local_dir
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def download_file(url: str, output_path: str) -> None:
|
| 26 |
+
try:
|
| 27 |
+
import requests
|
| 28 |
+
except ImportError:
|
| 29 |
+
import urllib.request
|
| 30 |
+
|
| 31 |
+
print("requests not found, falling back to urllib.request")
|
| 32 |
+
urllib.request.urlretrieve(url, output_path)
|
| 33 |
+
return
|
| 34 |
+
|
| 35 |
+
print(f"Downloading file from {url} to '{output_path}'...")
|
| 36 |
+
with requests.get(url, stream=True) as response:
|
| 37 |
+
response.raise_for_status()
|
| 38 |
+
total_size = int(response.headers.get("content-length", 0))
|
| 39 |
+
downloaded = 0
|
| 40 |
+
chunk_size = 8192
|
| 41 |
+
with open(output_path, "wb") as f:
|
| 42 |
+
for chunk in response.iter_content(chunk_size=chunk_size):
|
| 43 |
+
if chunk:
|
| 44 |
+
f.write(chunk)
|
| 45 |
+
downloaded += len(chunk)
|
| 46 |
+
if total_size:
|
| 47 |
+
percent = downloaded * 100 / total_size
|
| 48 |
+
print(f"\rDownloaded {downloaded}/{total_size} bytes ({percent:.1f}%)", end="")
|
| 49 |
+
if total_size:
|
| 50 |
+
print()
|
| 51 |
+
print(f"Finished: {output_path}\n")
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def main():
|
| 55 |
+
parser = argparse.ArgumentParser(description="Download VGMED, Medical Multimodal Evaluation Data, and COCO 2014 val images.")
|
| 56 |
+
parser.add_argument(
|
| 57 |
+
"--output-dir",
|
| 58 |
+
default="/home/jinhua/ExplainableVQA/benchmarks",
|
| 59 |
+
help="Base output directory for all downloads. Default: downloads",
|
| 60 |
+
)
|
| 61 |
+
parser.add_argument(
|
| 62 |
+
"--use-auth-token",
|
| 63 |
+
action="store_true",
|
| 64 |
+
help="Use HF authentication token from HUGGINGFACE_HUB_TOKEN environment variable if required.",
|
| 65 |
+
)
|
| 66 |
+
parser.add_argument(
|
| 67 |
+
"--skip-vgmed",
|
| 68 |
+
action="store_true",
|
| 69 |
+
help="Skip downloading guimeng-liu/VGMED.",
|
| 70 |
+
)
|
| 71 |
+
parser.add_argument(
|
| 72 |
+
"--skip-med-eval",
|
| 73 |
+
action="store_true",
|
| 74 |
+
help="Skip downloading FreedomIntelligence/Medical_Multimodal_Evaluation_Data.",
|
| 75 |
+
)
|
| 76 |
+
parser.add_argument(
|
| 77 |
+
"--skip-coco",
|
| 78 |
+
action="store_true",
|
| 79 |
+
help="Skip downloading COCO 2014 validation images.",
|
| 80 |
+
)
|
| 81 |
+
parser.add_argument(
|
| 82 |
+
"--coco-url",
|
| 83 |
+
default=COCO_VAL_URL,
|
| 84 |
+
help="COCO 2014 val images download URL. Default is the official val2014 zip URL.",
|
| 85 |
+
)
|
| 86 |
+
args = parser.parse_args()
|
| 87 |
+
|
| 88 |
+
base_dir = os.path.abspath(args.output_dir)
|
| 89 |
+
os.makedirs(base_dir, exist_ok=True)
|
| 90 |
+
|
| 91 |
+
if not args.skip_vgmed:
|
| 92 |
+
download_huggingface_dataset(
|
| 93 |
+
repo_id="guimeng-liu/VGMED",
|
| 94 |
+
output_dir=os.path.join(base_dir, "VGMED"),
|
| 95 |
+
use_auth_token=args.use_auth_token,
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
+
if not args.skip_med_eval:
|
| 99 |
+
download_huggingface_dataset(
|
| 100 |
+
repo_id="FreedomIntelligence/Medical_Multimodal_Evaluation_Data",
|
| 101 |
+
output_dir=os.path.join(base_dir, "Medical_Multimodal_Evaluation_Data"),
|
| 102 |
+
use_auth_token=args.use_auth_token,
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
if not args.skip_coco:
|
| 106 |
+
coco_target = os.path.join(base_dir, "val2014.zip")
|
| 107 |
+
download_file(args.coco_url, coco_target)
|
| 108 |
+
|
| 109 |
+
print("All requested downloads completed.")
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
if __name__ == "__main__":
|
| 113 |
+
main()
|
download_sam3_assets.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Download the external assets needed by MedSAM3 that are not part of the
|
| 3 |
+
git repo itself (sam3.pt is too large to commit; bpe_simple_vocab_16e6.txt.gz
|
| 4 |
+
ships with OpenAI's CLIP repo, not this one; the LoRA weights are the
|
| 5 |
+
project's own released checkpoint on HuggingFace):
|
| 6 |
+
|
| 7 |
+
- facebook/sam3 model weights -> models/sam3.pt (via ModelScope, ~3.45GB)
|
| 8 |
+
- CLIP BPE vocab -> models/bpe_simple_vocab_16e6.txt.gz
|
| 9 |
+
- MedSAM3-v1 LoRA weights -> models/best_lora_weights.pt (huggingface.co/lal-Joey/MedSAM3_v1)
|
| 10 |
+
|
| 11 |
+
Usage:
|
| 12 |
+
python download_sam3_assets.py
|
| 13 |
+
"""
|
| 14 |
+
|
| 15 |
+
import os
|
| 16 |
+
import shutil
|
| 17 |
+
import urllib.request
|
| 18 |
+
|
| 19 |
+
MODELS_DIR = "/home/jinhua/ExplainableVQA/HuatuoGPT-Vision-Abla/MedSAM3/models"
|
| 20 |
+
|
| 21 |
+
BPE_VOCAB_URL = "https://raw.githubusercontent.com/facebookresearch/sam3/main/sam3/assets/bpe_simple_vocab_16e6.txt.gz"
|
| 22 |
+
BPE_VOCAB_PATH = os.path.join(MODELS_DIR, "bpe_simple_vocab_16e6.txt.gz")
|
| 23 |
+
|
| 24 |
+
SAM3_WEIGHTS_PATH = os.path.join(MODELS_DIR, "sam3.pt")
|
| 25 |
+
|
| 26 |
+
LORA_REPO_ID = "lal-Joey/MedSAM3_v1"
|
| 27 |
+
LORA_WEIGHTS_PATH = os.path.join(MODELS_DIR, "best_lora_weights.pt")
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def download_bpe_vocab():
|
| 31 |
+
if os.path.exists(BPE_VOCAB_PATH):
|
| 32 |
+
print(f"[Skip] {BPE_VOCAB_PATH} already exists.")
|
| 33 |
+
return
|
| 34 |
+
print(f"==> Downloading CLIP BPE vocab from {BPE_VOCAB_URL}")
|
| 35 |
+
os.makedirs(MODELS_DIR, exist_ok=True)
|
| 36 |
+
urllib.request.urlretrieve(BPE_VOCAB_URL, BPE_VOCAB_PATH)
|
| 37 |
+
print(f"[Done] Saved to {BPE_VOCAB_PATH}")
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def download_sam3_weights():
|
| 41 |
+
if os.path.exists(SAM3_WEIGHTS_PATH):
|
| 42 |
+
print(f"[Skip] {SAM3_WEIGHTS_PATH} already exists.")
|
| 43 |
+
return
|
| 44 |
+
from modelscope import snapshot_download
|
| 45 |
+
|
| 46 |
+
print("==> Downloading facebook/sam3 weights via ModelScope (~3.45GB)")
|
| 47 |
+
model_dir = snapshot_download("facebook/sam3")
|
| 48 |
+
print(f" Downloaded to {model_dir}")
|
| 49 |
+
|
| 50 |
+
src = os.path.join(model_dir, "sam3.pt")
|
| 51 |
+
if not os.path.exists(src):
|
| 52 |
+
candidates = [f for f in os.listdir(model_dir) if f.endswith(".pt")]
|
| 53 |
+
if not candidates:
|
| 54 |
+
raise FileNotFoundError(f"No .pt file found in {model_dir}")
|
| 55 |
+
src = os.path.join(model_dir, candidates[0])
|
| 56 |
+
|
| 57 |
+
os.makedirs(MODELS_DIR, exist_ok=True)
|
| 58 |
+
shutil.copy(src, SAM3_WEIGHTS_PATH)
|
| 59 |
+
print(f"[Done] Copied to {SAM3_WEIGHTS_PATH}")
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def download_lora_weights():
|
| 63 |
+
if os.path.exists(LORA_WEIGHTS_PATH):
|
| 64 |
+
print(f"[Skip] {LORA_WEIGHTS_PATH} already exists.")
|
| 65 |
+
return
|
| 66 |
+
from huggingface_hub import snapshot_download
|
| 67 |
+
|
| 68 |
+
print(f"==> Downloading LoRA weights from huggingface.co/{LORA_REPO_ID}")
|
| 69 |
+
repo_dir = snapshot_download(repo_id=LORA_REPO_ID)
|
| 70 |
+
print(f" Downloaded to {repo_dir}")
|
| 71 |
+
|
| 72 |
+
candidates = [f for f in os.listdir(repo_dir) if f.endswith(".pt")]
|
| 73 |
+
if not candidates:
|
| 74 |
+
raise FileNotFoundError(f"No .pt file found in {repo_dir}")
|
| 75 |
+
src = os.path.join(repo_dir, candidates[0])
|
| 76 |
+
|
| 77 |
+
os.makedirs(MODELS_DIR, exist_ok=True)
|
| 78 |
+
shutil.copy(src, LORA_WEIGHTS_PATH)
|
| 79 |
+
print(f"[Done] Copied to {LORA_WEIGHTS_PATH}")
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def main():
|
| 83 |
+
download_bpe_vocab()
|
| 84 |
+
download_sam3_weights()
|
| 85 |
+
download_lora_weights()
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
if __name__ == "__main__":
|
| 89 |
+
main()
|
gpu1_hold_30g.log
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
nohup: ignoring input
|
| 2 |
+
GPU 1: holding 30 GiB for 1 hour
|
predownload_models-ori.py
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Pre-download all HuggingFace model repos used by:
|
| 3 |
+
- MedEvalKit/eval_scripts/grounding/diff_region/*.sh (grounding diff-region analysis)
|
| 4 |
+
|
| 5 |
+
Downloads go to a custom HuggingFace cache directory
|
| 6 |
+
(/home/jinhua/ExplainableVQA/checkpoint/models) instead of the default
|
| 7 |
+
~/.cache/huggingface. As long as HF_HOME points to this same directory at
|
| 8 |
+
load time, `from_pretrained(repo_id, ...)` will transparently hit this cache
|
| 9 |
+
instead of re-downloading - it behaves exactly like the normal HF cache,
|
| 10 |
+
just relocated.
|
| 11 |
+
|
| 12 |
+
Each repo is retried several times with resume (snapshot_download skips files
|
| 13 |
+
already fully downloaded and resumes partial ones), since mirrors like
|
| 14 |
+
hf-mirror.com often time out near the end of large files.
|
| 15 |
+
|
| 16 |
+
Usage:
|
| 17 |
+
python predownload_models_to_checkpoint.py
|
| 18 |
+
"""
|
| 19 |
+
|
| 20 |
+
import os
|
| 21 |
+
import time
|
| 22 |
+
|
| 23 |
+
# Custom cache location - from_pretrained(repo_id) will read from here as
|
| 24 |
+
# long as HF_HOME is set to the same path when the model is actually loaded.
|
| 25 |
+
#os.environ.setdefault("HF_HOME", "/home/jinhua/ExplainableVQA/checkpoint/models")
|
| 26 |
+
|
| 27 |
+
# Use the hf-mirror.com mirror (much faster from China than huggingface.co directly).
|
| 28 |
+
#os.environ.setdefault("HF_ENDPOINT", "https://hf-mirror.com")
|
| 29 |
+
|
| 30 |
+
# Raise the default 10s timeout - hf-mirror.com often stalls on the final
|
| 31 |
+
# etag/HEAD check for large files.
|
| 32 |
+
os.environ.setdefault("HF_HUB_DOWNLOAD_TIMEOUT", "60")
|
| 33 |
+
|
| 34 |
+
# Disable the Xet backend: it generates a fresh random temp file on every
|
| 35 |
+
# resume instead of continuing the previous .incomplete file, so interrupted
|
| 36 |
+
# downloads restart from 0 instead of resuming.
|
| 37 |
+
os.environ.setdefault("HF_HUB_DISABLE_XET", "1")
|
| 38 |
+
|
| 39 |
+
from huggingface_hub import snapshot_download
|
| 40 |
+
|
| 41 |
+
REPO_IDS = [
|
| 42 |
+
# ---- MedEvalKit/eval_scripts/grounding/diff_region/*.sh ----
|
| 43 |
+
# "Qwen/Qwen2.5-VL-3B-Instruct", # Qwen2.5VL-3B
|
| 44 |
+
# "Qwen/Qwen2.5-VL-7B-Instruct", # Qwen2.5VL-7B
|
| 45 |
+
# "Qwen/Qwen2.5-VL-32B-Instruct", # Qwen2.5VL-32B
|
| 46 |
+
"llava-hf/llava-1.5-7b-hf", # LLaVA-7B
|
| 47 |
+
"llava-hf/llava-1.5-13b-hf", # LLaVA-13B
|
| 48 |
+
# "microsoft/llava-med-v1.5-mistral-7b", # LLaVA-Med-7B
|
| 49 |
+
# "FreedomIntelligence/HuatuoGPT-Vision-7B", # HuatuoGPT-V-7B
|
| 50 |
+
# "FreedomIntelligence/HuatuoGPT-Vision-34B", # HuatuoGPT-V-34B
|
| 51 |
+
# "google/medgemma-4b-it", # MedGemma-4B-IT
|
| 52 |
+
# "google/medgemma-27b-it", # MedGemma-27B-IT (gated repo, multimodal variant)
|
| 53 |
+
]
|
| 54 |
+
|
| 55 |
+
DATASET_REPO_IDS = []
|
| 56 |
+
|
| 57 |
+
MAX_RETRIES = 10
|
| 58 |
+
RETRY_DELAY_SECONDS = 5
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def download_with_retries(repo_id, repo_type="model"):
|
| 62 |
+
for attempt in range(1, MAX_RETRIES + 1):
|
| 63 |
+
try:
|
| 64 |
+
snapshot_download(repo_id=repo_id, repo_type=repo_type, resume_download=True)
|
| 65 |
+
return True
|
| 66 |
+
except Exception as e:
|
| 67 |
+
print(f" attempt {attempt}/{MAX_RETRIES} failed: {e}")
|
| 68 |
+
if attempt < MAX_RETRIES:
|
| 69 |
+
time.sleep(RETRY_DELAY_SECONDS)
|
| 70 |
+
return False
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def main():
|
| 74 |
+
#print(f"HF_HOME = {os.environ['HF_HOME']}")
|
| 75 |
+
|
| 76 |
+
failed = []
|
| 77 |
+
for repo_id in REPO_IDS:
|
| 78 |
+
print(f"==> Downloading {repo_id}")
|
| 79 |
+
if not download_with_retries(repo_id):
|
| 80 |
+
failed.append(repo_id)
|
| 81 |
+
print(f" GAVE UP: {repo_id}")
|
| 82 |
+
|
| 83 |
+
for repo_id in DATASET_REPO_IDS:
|
| 84 |
+
print(f"==> Downloading dataset {repo_id}")
|
| 85 |
+
if not download_with_retries(repo_id, repo_type="dataset"):
|
| 86 |
+
failed.append(repo_id)
|
| 87 |
+
print(f" GAVE UP: {repo_id}")
|
| 88 |
+
|
| 89 |
+
print("\n==== Summary ====")
|
| 90 |
+
if failed:
|
| 91 |
+
print("Failed repos (re-run this script to resume them):")
|
| 92 |
+
for repo_id in failed:
|
| 93 |
+
print(f" - {repo_id}")
|
| 94 |
+
else:
|
| 95 |
+
print("All repos downloaded successfully.")
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
if __name__ == "__main__":
|
| 99 |
+
main()
|
predownload_models.py
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Pre-download all HuggingFace model repos used by:
|
| 3 |
+
- MedEvalKit/eval_scripts/grounding/diff_region/*.sh (grounding diff-region analysis)
|
| 4 |
+
|
| 5 |
+
Downloads go to a custom HuggingFace cache directory
|
| 6 |
+
(/home/jinhua/ExplainableVQA/checkpoint/models) instead of the default
|
| 7 |
+
~/.cache/huggingface. As long as HF_HOME points to this same directory at
|
| 8 |
+
load time, `from_pretrained(repo_id, ...)` will transparently hit this cache
|
| 9 |
+
instead of re-downloading - it behaves exactly like the normal HF cache,
|
| 10 |
+
just relocated.
|
| 11 |
+
|
| 12 |
+
Each repo is retried several times with resume (snapshot_download skips files
|
| 13 |
+
already fully downloaded and resumes partial ones), since mirrors like
|
| 14 |
+
hf-mirror.com often time out near the end of large files.
|
| 15 |
+
|
| 16 |
+
Usage:
|
| 17 |
+
python predownload_models_to_checkpoint.py
|
| 18 |
+
"""
|
| 19 |
+
|
| 20 |
+
import os
|
| 21 |
+
import time
|
| 22 |
+
|
| 23 |
+
# Custom cache location - from_pretrained(repo_id) will read from here as
|
| 24 |
+
# long as HF_HOME is set to the same path when the model is actually loaded.
|
| 25 |
+
#os.environ.setdefault("HF_HOME", "/home/jinhua/ExplainableVQA/checkpoint/models")
|
| 26 |
+
|
| 27 |
+
# Use the hf-mirror.com mirror (much faster from China than huggingface.co directly).
|
| 28 |
+
#os.environ.setdefault("HF_ENDPOINT", "https://hf-mirror.com")
|
| 29 |
+
|
| 30 |
+
# Raise the default 10s timeout - hf-mirror.com often stalls on the final
|
| 31 |
+
# etag/HEAD check for large files.
|
| 32 |
+
os.environ.setdefault("HF_HUB_DOWNLOAD_TIMEOUT", "60")
|
| 33 |
+
|
| 34 |
+
# Disable the Xet backend: it generates a fresh random temp file on every
|
| 35 |
+
# resume instead of continuing the previous .incomplete file, so interrupted
|
| 36 |
+
# downloads restart from 0 instead of resuming.
|
| 37 |
+
os.environ.setdefault("HF_HUB_DISABLE_XET", "1")
|
| 38 |
+
|
| 39 |
+
from huggingface_hub import snapshot_download
|
| 40 |
+
|
| 41 |
+
REPO_IDS = [
|
| 42 |
+
# ---- MedEvalKit/eval_scripts/grounding/diff_region/*.sh ----
|
| 43 |
+
# "Qwen/Qwen2.5-VL-3B-Instruct", # Qwen2.5VL-3B
|
| 44 |
+
# "Qwen/Qwen2.5-VL-7B-Instruct", # Qwen2.5VL-7B
|
| 45 |
+
# "Qwen/Qwen2.5-VL-32B-Instruct", # Qwen2.5VL-32B
|
| 46 |
+
# "llava-hf/llava-1.5-7b-hf", # LLaVA-7B
|
| 47 |
+
# "llava-hf/llava-1.5-13b-hf", # LLaVA-13B
|
| 48 |
+
# "microsoft/llava-med-v1.5-mistral-7b", # LLaVA-Med-7B
|
| 49 |
+
# "FreedomIntelligence/HuatuoGPT-Vision-7B", # HuatuoGPT-V-7B
|
| 50 |
+
# "FreedomIntelligence/HuatuoGPT-Vision-34B", # HuatuoGPT-V-34B
|
| 51 |
+
# "google/medgemma-4b-it", # MedGemma-4B-IT
|
| 52 |
+
# "google/medgemma-27b-it", # MedGemma-27B-IT (gated repo, multimodal variant)
|
| 53 |
+
"Qwen/Qwen3-VL-2B-Instruct", # Qwen3VL-2B
|
| 54 |
+
"Qwen/Qwen3-VL-4B-Instruct", # Qwen3VL-4B
|
| 55 |
+
"Qwen/Qwen3-VL-8B-Instruct", # Qwen3VL-8B
|
| 56 |
+
]
|
| 57 |
+
|
| 58 |
+
DATASET_REPO_IDS = []
|
| 59 |
+
|
| 60 |
+
MAX_RETRIES = 10
|
| 61 |
+
RETRY_DELAY_SECONDS = 5
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def download_with_retries(repo_id, repo_type="model"):
|
| 65 |
+
for attempt in range(1, MAX_RETRIES + 1):
|
| 66 |
+
try:
|
| 67 |
+
snapshot_download(repo_id=repo_id, repo_type=repo_type, resume_download=True)
|
| 68 |
+
return True
|
| 69 |
+
except Exception as e:
|
| 70 |
+
print(f" attempt {attempt}/{MAX_RETRIES} failed: {e}")
|
| 71 |
+
if attempt < MAX_RETRIES:
|
| 72 |
+
time.sleep(RETRY_DELAY_SECONDS)
|
| 73 |
+
return False
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def main():
|
| 77 |
+
#print(f"HF_HOME = {os.environ['HF_HOME']}")
|
| 78 |
+
|
| 79 |
+
failed = []
|
| 80 |
+
for repo_id in REPO_IDS:
|
| 81 |
+
print(f"==> Downloading {repo_id}")
|
| 82 |
+
if not download_with_retries(repo_id):
|
| 83 |
+
failed.append(repo_id)
|
| 84 |
+
print(f" GAVE UP: {repo_id}")
|
| 85 |
+
|
| 86 |
+
for repo_id in DATASET_REPO_IDS:
|
| 87 |
+
print(f"==> Downloading dataset {repo_id}")
|
| 88 |
+
if not download_with_retries(repo_id, repo_type="dataset"):
|
| 89 |
+
failed.append(repo_id)
|
| 90 |
+
print(f" GAVE UP: {repo_id}")
|
| 91 |
+
|
| 92 |
+
print("\n==== Summary ====")
|
| 93 |
+
if failed:
|
| 94 |
+
print("Failed repos (re-run this script to resume them):")
|
| 95 |
+
for repo_id in failed:
|
| 96 |
+
print(f" - {repo_id}")
|
| 97 |
+
else:
|
| 98 |
+
print("All repos downloaded successfully.")
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
if __name__ == "__main__":
|
| 102 |
+
main()
|