Skip to content

Commit f9ffa31

Browse files
sarena: explicit LPIPS model path via LMUDataRoot, use cached tokenizer path
1 parent 1c58028 commit f9ffa31

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

vlmeval/dataset/utils/SArena/LPIPS.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1+
import os
12
import torch
23
import lpips
34

45
from tqdm import tqdm
56
from torch.utils.data import DataLoader
67
from torchvision.transforms import ToTensor, Normalize
78
from .base_metric import BaseMetric
9+
from vlmeval.smp.file import LMUDataRoot
810

911

1012
class LPIPSCalculator(BaseMetric):
1113
def __init__(self):
1214
super().__init__()
1315
self.class_name = self.__class__.__name__
1416
self.device = "cuda" if torch.cuda.is_available() else "cpu"
15-
self.model = lpips.LPIPS(net='vgg').to(self.device)
17+
model_path = os.path.join(LMUDataRoot(), 'aux_models', 'vgg.pth')
18+
self.model = lpips.LPIPS(net='vgg', model_path=model_path).to(self.device)
1619
self.metric = self.LPIPS
1720
self.to_tensor = ToTensor()
1821
self.normalize = Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])

vlmeval/dataset/utils/SArena/token_length.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,18 @@
77
from .base_metric import BaseMetric
88
from .average_meter import AverageMeter
99

10+
from vlmeval.smp.misc import get_cache_path
11+
1012

1113
class TokenLengthCalculator(BaseMetric):
14+
1215
def __init__(self, tokenizer_path: str):
1316
super().__init__()
1417
self.class_name = self.__class__.__name__
1518
self.device = "cuda" if torch.cuda.is_available() else "cpu"
19+
if get_cache_path(tokenizer_path, repo_type='models'):
20+
# AutoTokenizer won't use cached path.
21+
tokenizer_path = get_cache_path(tokenizer_path, repo_type='models')
1622
self.tokenizer = AutoTokenizer.from_pretrained(tokenizer_path)
1723
self.metric = self.count_token_length
1824

0 commit comments

Comments
 (0)