Upload folder using huggingface_hub
Browse files- .gitattributes +8 -0
- add_image_bytes.py +244 -0
- test_Evalmi50k_1_5_sampled.json +3 -0
- test_TAD66k_forDG.json +3 -0
- test_agiqa3k.json +3 -0
- test_ava.json +3 -0
- test_evalmuse.json +3 -0
- test_kadid.json +3 -0
- test_koniq.json +3 -0
- test_spaq.json +3 -0
.gitattributes
CHANGED
|
@@ -58,3 +58,11 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 58 |
# Video files - compressed
|
| 59 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 60 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
# Video files - compressed
|
| 59 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 60 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
| 61 |
+
test_Evalmi50k_1_5_sampled.json filter=lfs diff=lfs merge=lfs -text
|
| 62 |
+
test_TAD66k_forDG.json filter=lfs diff=lfs merge=lfs -text
|
| 63 |
+
test_agiqa3k.json filter=lfs diff=lfs merge=lfs -text
|
| 64 |
+
test_ava.json filter=lfs diff=lfs merge=lfs -text
|
| 65 |
+
test_evalmuse.json filter=lfs diff=lfs merge=lfs -text
|
| 66 |
+
test_kadid.json filter=lfs diff=lfs merge=lfs -text
|
| 67 |
+
test_koniq.json filter=lfs diff=lfs merge=lfs -text
|
| 68 |
+
test_spaq.json filter=lfs diff=lfs merge=lfs -text
|
add_image_bytes.py
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
import json
|
| 3 |
+
import os
|
| 4 |
+
import base64
|
| 5 |
+
import logging
|
| 6 |
+
import time
|
| 7 |
+
import random
|
| 8 |
+
import pandas as pd
|
| 9 |
+
from typing import Optional
|
| 10 |
+
|
| 11 |
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 12 |
+
logger = logging.getLogger(__name__)
|
| 13 |
+
|
| 14 |
+
BASE_JSON_DIR = '/data1/luyt/code_omniquality/mnt/petrelfs/luyiting/MultiAgentEval/data_process_v1'
|
| 15 |
+
OUTPUT_DIR = '/data1/luyt/code_omniquality/mnt/petrelfs/luyiting/MultiAgentEval/data_process_v1/test_json'
|
| 16 |
+
|
| 17 |
+
DATASET_CONFIGS = {
|
| 18 |
+
"koniq": {
|
| 19 |
+
"json_file": "test_koniq.json",
|
| 20 |
+
"image_base": "/data1/datasets/IQA/koniq1",
|
| 21 |
+
"path_type": "relative",
|
| 22 |
+
},
|
| 23 |
+
"kadid": {
|
| 24 |
+
"json_file": "test_kadid.json",
|
| 25 |
+
"image_base": "/data1/datasets/IQA/kadid10k/distorted_images",
|
| 26 |
+
"path_type": "relative_basename",
|
| 27 |
+
},
|
| 28 |
+
"spaq": {
|
| 29 |
+
"json_file": "test_spaq.json",
|
| 30 |
+
"image_base": "/data1/datasets/IQA/SPAQ/512x384",
|
| 31 |
+
"path_type": "relative_basename",
|
| 32 |
+
},
|
| 33 |
+
"ava": {
|
| 34 |
+
"json_file": "test_ava.json",
|
| 35 |
+
"image_base": "/data2/datasets/AVA",
|
| 36 |
+
"path_type": "relative",
|
| 37 |
+
"sample_n": 2000,
|
| 38 |
+
},
|
| 39 |
+
"tad66k": {
|
| 40 |
+
"json_file": "test_TAD66k_forDG.json",
|
| 41 |
+
"image_base": "/data2/datasets/TAD66k",
|
| 42 |
+
"path_type": "absolute_remap",
|
| 43 |
+
"remap_prefix": "/mnt/petrelfs/luyiting/data/IQA/TAD66K/",
|
| 44 |
+
"remap_target": "/data2/datasets/TAD66k/",
|
| 45 |
+
"sample_n": 2000,
|
| 46 |
+
},
|
| 47 |
+
"evalmuse": {
|
| 48 |
+
"json_file": "train_evalmuse_llava_style.json",
|
| 49 |
+
"image_base": "/data2/datasets/EvalMuse/dataset/images",
|
| 50 |
+
"path_type": "absolute_remap",
|
| 51 |
+
"remap_prefix": "/mnt/petrelfs/luyiting/data/IQA/EvalMuse/dataset/images/",
|
| 52 |
+
"remap_target": "/data2/datasets/EvalMuse/dataset/images/",
|
| 53 |
+
"output_name": "test_evalmuse.json",
|
| 54 |
+
"sample_n": 2000,
|
| 55 |
+
},
|
| 56 |
+
"agiqa3k": {
|
| 57 |
+
"json_file": None, # generated from CSV
|
| 58 |
+
"csv_file": "AGIQA3K_data.csv",
|
| 59 |
+
"image_base": "/data2/datasets/AGIQA-3k",
|
| 60 |
+
"path_type": "filename_only",
|
| 61 |
+
},
|
| 62 |
+
"evalmi": {
|
| 63 |
+
"json_file": "test_Evalmi50k_1_5_sampled.json",
|
| 64 |
+
"image_base": "/data2/datasets/EvalMi-50K",
|
| 65 |
+
"path_type": "absolute_remap",
|
| 66 |
+
"remap_prefix": "/mnt/petrelfs/luyiting/data/IQA/EvalMi-50K/",
|
| 67 |
+
"remap_target": "/data2/datasets/EvalMi-50K/",
|
| 68 |
+
"sample_n": 2000,
|
| 69 |
+
"must_find": True,
|
| 70 |
+
},
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def load_image_as_base64(img_path: str) -> Optional[str]:
|
| 75 |
+
try:
|
| 76 |
+
if not os.path.exists(img_path):
|
| 77 |
+
return None
|
| 78 |
+
with open(img_path, 'rb') as f:
|
| 79 |
+
return base64.b64encode(f.read()).decode('utf-8')
|
| 80 |
+
except Exception as e:
|
| 81 |
+
logger.error(f"Error loading image {img_path}: {e}")
|
| 82 |
+
return None
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def resolve_image_path(image_field: str, config: dict) -> Optional[str]:
|
| 86 |
+
image_base = config["image_base"]
|
| 87 |
+
if image_base is None:
|
| 88 |
+
return None
|
| 89 |
+
|
| 90 |
+
path_type = config["path_type"]
|
| 91 |
+
|
| 92 |
+
if path_type == "relative":
|
| 93 |
+
return os.path.join(image_base, image_field)
|
| 94 |
+
elif path_type == "relative_basename":
|
| 95 |
+
return os.path.join(image_base, os.path.basename(image_field))
|
| 96 |
+
elif path_type == "filename_only":
|
| 97 |
+
return os.path.join(image_base, image_field)
|
| 98 |
+
elif path_type == "absolute":
|
| 99 |
+
if os.path.exists(image_field):
|
| 100 |
+
return image_field
|
| 101 |
+
return None
|
| 102 |
+
elif path_type == "absolute_remap":
|
| 103 |
+
remap_prefix = config["remap_prefix"]
|
| 104 |
+
remap_target = config["remap_target"]
|
| 105 |
+
if image_field.startswith(remap_prefix):
|
| 106 |
+
return remap_target + image_field[len(remap_prefix):]
|
| 107 |
+
return os.path.join(remap_target, os.path.basename(image_field))
|
| 108 |
+
|
| 109 |
+
return None
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
def generate_agiqa3k_json(csv_path: str) -> list:
|
| 113 |
+
"""Generate AGIQA-3k test JSON from CSV."""
|
| 114 |
+
df = pd.read_csv(csv_path)
|
| 115 |
+
logger.info(f"[agiqa3k] Loaded CSV: {len(df)} rows")
|
| 116 |
+
|
| 117 |
+
json_data = []
|
| 118 |
+
for _, row in df.iterrows():
|
| 119 |
+
if pd.isna(row.get('name')) or pd.isna(row.get('prompt')):
|
| 120 |
+
continue
|
| 121 |
+
json_data.append({
|
| 122 |
+
"image": str(row['name']),
|
| 123 |
+
"gt_score": float(row['mos_align']) if pd.notna(row.get('mos_align')) else 0.0,
|
| 124 |
+
"gt_score1": float(row['mos_quality']) if pd.notna(row.get('mos_quality')) else 0.0,
|
| 125 |
+
"gt_score2": float(row['std_align']) if pd.notna(row.get('std_align')) else 0.0,
|
| 126 |
+
"prompt": str(row['prompt']),
|
| 127 |
+
"conversations": [
|
| 128 |
+
{
|
| 129 |
+
"from": "human",
|
| 130 |
+
"value": f"Judge the image alignment with the prompt: \"{row['prompt']}\"\n"
|
| 131 |
+
"Please evaluate how well the image matches each element of provided prompt.\n\n"
|
| 132 |
+
"And answer with the final alignment rating.\n"
|
| 133 |
+
"Pick from [bad, poor, fair, good, excellent]."
|
| 134 |
+
}
|
| 135 |
+
]
|
| 136 |
+
})
|
| 137 |
+
return json_data
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
def process_dataset(name: str, config: dict):
|
| 141 |
+
if config["image_base"] is not None and not os.path.exists(config["image_base"]):
|
| 142 |
+
logger.warning(f"[{name}] Image base dir not found: {config['image_base']}, skipping")
|
| 143 |
+
return
|
| 144 |
+
if config["image_base"] is None:
|
| 145 |
+
logger.warning(f"[{name}] No image base configured (images not available locally), skipping")
|
| 146 |
+
return
|
| 147 |
+
|
| 148 |
+
# Load data
|
| 149 |
+
if config.get("csv_file"):
|
| 150 |
+
csv_path = os.path.join(BASE_JSON_DIR, config["csv_file"])
|
| 151 |
+
if not os.path.exists(csv_path):
|
| 152 |
+
logger.warning(f"[{name}] CSV file not found: {csv_path}, skipping")
|
| 153 |
+
return
|
| 154 |
+
data = generate_agiqa3k_json(csv_path)
|
| 155 |
+
else:
|
| 156 |
+
json_path = os.path.join(BASE_JSON_DIR, config["json_file"])
|
| 157 |
+
if not os.path.exists(json_path):
|
| 158 |
+
logger.warning(f"[{name}] JSON file not found: {json_path}, skipping")
|
| 159 |
+
return
|
| 160 |
+
logger.info(f"[{name}] Loading JSON: {json_path}")
|
| 161 |
+
with open(json_path, 'r', encoding='utf-8') as f:
|
| 162 |
+
data = json.load(f)
|
| 163 |
+
|
| 164 |
+
# If must_find is set, pre-filter to items whose images exist locally
|
| 165 |
+
sample_n = config.get("sample_n")
|
| 166 |
+
if config.get("must_find") and sample_n:
|
| 167 |
+
logger.info(f"[{name}] Pre-filtering items with existing local images...")
|
| 168 |
+
valid_data = []
|
| 169 |
+
for item in data:
|
| 170 |
+
if 'image' not in item:
|
| 171 |
+
continue
|
| 172 |
+
img_path = resolve_image_path(item['image'], config)
|
| 173 |
+
if img_path and os.path.exists(img_path):
|
| 174 |
+
valid_data.append(item)
|
| 175 |
+
logger.info(f"[{name}] Found {len(valid_data)}/{len(data)} items with local images")
|
| 176 |
+
data = valid_data
|
| 177 |
+
|
| 178 |
+
# Random sampling
|
| 179 |
+
if sample_n and len(data) > sample_n:
|
| 180 |
+
logger.info(f"[{name}] Randomly sampling {sample_n} from {len(data)} items")
|
| 181 |
+
random.seed(42)
|
| 182 |
+
data = random.sample(data, sample_n)
|
| 183 |
+
|
| 184 |
+
total = len(data)
|
| 185 |
+
found = 0
|
| 186 |
+
not_found = 0
|
| 187 |
+
start_time = time.time()
|
| 188 |
+
|
| 189 |
+
for i, item in enumerate(data):
|
| 190 |
+
if 'image' not in item:
|
| 191 |
+
continue
|
| 192 |
+
|
| 193 |
+
img_path = resolve_image_path(item['image'], config)
|
| 194 |
+
if img_path and os.path.exists(img_path):
|
| 195 |
+
img_bytes = load_image_as_base64(img_path)
|
| 196 |
+
if img_bytes:
|
| 197 |
+
item['image_byte'] = img_bytes
|
| 198 |
+
found += 1
|
| 199 |
+
else:
|
| 200 |
+
not_found += 1
|
| 201 |
+
else:
|
| 202 |
+
not_found += 1
|
| 203 |
+
|
| 204 |
+
if (i + 1) % 500 == 0:
|
| 205 |
+
elapsed = time.time() - start_time
|
| 206 |
+
logger.info(f"[{name}] Progress: {i+1}/{total}, found: {found}, not_found: {not_found}, elapsed: {elapsed:.1f}s")
|
| 207 |
+
|
| 208 |
+
elapsed = time.time() - start_time
|
| 209 |
+
logger.info(f"[{name}] Done: total={total}, found={found}, not_found={not_found}, elapsed={elapsed:.1f}s")
|
| 210 |
+
|
| 211 |
+
output_name = config.get("output_name") or config.get("json_file") or f"test_{name}.json"
|
| 212 |
+
output_path = os.path.join(OUTPUT_DIR, output_name)
|
| 213 |
+
logger.info(f"[{name}] Saving to: {output_path}")
|
| 214 |
+
with open(output_path, 'w', encoding='utf-8') as f:
|
| 215 |
+
json.dump(data, f, ensure_ascii=False)
|
| 216 |
+
logger.info(f"[{name}] Saved successfully ({os.path.getsize(output_path) / 1024 / 1024:.1f} MB)")
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
def main():
|
| 220 |
+
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
| 221 |
+
|
| 222 |
+
# Only process datasets not already done
|
| 223 |
+
already_done = set()
|
| 224 |
+
for fname in os.listdir(OUTPUT_DIR):
|
| 225 |
+
if fname.endswith('.json'):
|
| 226 |
+
already_done.add(fname)
|
| 227 |
+
|
| 228 |
+
for name, config in DATASET_CONFIGS.items():
|
| 229 |
+
output_name = config.get("output_name") or config.get("json_file") or f"test_{name}.json"
|
| 230 |
+
if output_name in already_done:
|
| 231 |
+
logger.info(f"[{name}] Already processed ({output_name}), skipping. Delete to reprocess.")
|
| 232 |
+
continue
|
| 233 |
+
try:
|
| 234 |
+
process_dataset(name, config)
|
| 235 |
+
except Exception as e:
|
| 236 |
+
logger.error(f"[{name}] Failed: {e}")
|
| 237 |
+
import traceback
|
| 238 |
+
traceback.print_exc()
|
| 239 |
+
|
| 240 |
+
logger.info("All datasets processed.")
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
if __name__ == "__main__":
|
| 244 |
+
main()
|
test_Evalmi50k_1_5_sampled.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4654be03e20b755f68aaffc02101ae1e057d972136a0ad5935aea5d849f89e51
|
| 3 |
+
size 2082644631
|
test_TAD66k_forDG.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e82bc753966c685bac76ce7608a7b76e1a9b60d740ebc1c6a561dd6c64d0a22e
|
| 3 |
+
size 419386635
|
test_agiqa3k.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d519a7d49cd82b1a63dd7394152f1b420a22bb8d719ee56331e49a2ef8330305
|
| 3 |
+
size 133820434
|
test_ava.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0943a1ab25e82c324f840de3ab89db8946466276180402a6f4eb36eca434ca8e
|
| 3 |
+
size 351586738
|
test_evalmuse.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9cd37269cd9a55b5807f84d4d37d1dd521739d8de1d295065dea150c173300c2
|
| 3 |
+
size 3387211109
|
test_kadid.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3a3ea832eb55b0a816522677b9cf83f5b7cadd983e60defaf8fc7dce5cb5bf8e
|
| 3 |
+
size 828912501
|
test_koniq.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:533237469d002eab0c3095b1140d9a5a5ae076953ab85eeaa016b20f2406561f
|
| 3 |
+
size 199817363
|
test_spaq.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:54be2eb6c19c03e41622599fd8b5e4944c5fe8f9b5ac92d95e42a260b957dc27
|
| 3 |
+
size 76775104
|