| import json |
| import pandas as pd |
| from collections import defaultdict |
| import os |
|
|
| def get_latest_file(directory): |
| |
| files = [os.path.join(directory, f) for f in os.listdir(directory) if os.path.isfile(os.path.join(directory, f))] |
|
|
| |
| latest_file = max(files, key=os.path.getmtime) |
| |
| return latest_file |
| print(get_latest_file("/mnt/bn/life-mllm/users/cxr/hallucination/VLMEvalKit/case_study")) |
|
|
| base_data = [] |
| |
| |
| base_jsonl_path = \ |
| "/mnt/bn/life-mllm/users/cxr/hallucination/VLMEvalKit/outputs/20251114_174347/Qwen2.5-VL-7B-Instruct/T20251114_G/01_POPE.jsonl" |
| with open(base_jsonl_path, "r", encoding="utf-8") as f: |
| for line in f: |
| if line.strip(): |
| base_data.append(json.loads(line)) |
|
|
| ours_data = [] |
| ours_jsonl_path = \ |
| "/mnt/bn/life-mllm/users/cxr/hallucination/VLMEvalKit/outputs/20251114_175000/Qwen2.5-VL-7B-Instruct/T20251114_G/01_POPE.jsonl" |
| |
| with open(ours_jsonl_path, "r", encoding="utf-8") as f: |
| for line in f: |
| if line.strip(): |
| ours_data.append(json.loads(line)) |
|
|
| tsv_path = "/mnt/bn/life-mllm/users/cxr/zhy/LMUData/POPE.tsv" |
| pope_path = "/mnt/bn/life-mllm/users/cxr/hallucination/OPERA/pope_coco/coco_pope_random.jsonl" |
|
|
| |
|
|
| def load_data(path): |
| data = [] |
| if path.endswith(".jsonl"): |
| with open(path, "r", encoding="utf-8") as f: |
| for line in f: |
| if line.strip(): |
| data.append(json.loads(line)) |
| elif path.endswith(".tsv"): |
| data = pd.read_csv(path, sep="\t") |
| return data |
|
|
| |
| if False: |
| pope_data = load_data(tsv_path) |
| pope_data = pope_data['answer'] |
| else: |
| pope_data_t = load_data(pope_path) |
| pope_data = [item['label'] for item in pope_data_t] |
|
|
|
|
| |
| for base, ours, pope in zip(base_data, ours_data, pope_data): |
| if base['response'].lower().strip('.') != pope.lower() and ours['response'].lower().strip('.') == pope.lower(): |
| print(base['index'], base['response'].lower(), ours['response'], pope_data_t[base['index']]['text'], os.path.join("/mnt/bn/life-mllm/users/cxr/hallucination/datasets/val2014", pope_data_t[base['index']]['image'])) |
|
|
|
|