MMDT-radar / utils /score_extract /adversarial_robustness_agg.py
polaris73's picture
hf upload
94afa8b
import json
import os
def adversarial_robustness_t2i_agg(model, result_dir):
model = model.split("/")[-1]
result_path = os.path.join(result_dir, "adversarial_robustness_t2i_summary.json")
with open(result_path, "r") as file:
results = json.load(file)
agg_scores = {}
agg_scores["score"] = results[model].pop("Average")
agg_scores["subscenarios"] = results[model]
return agg_scores
def adversarial_robustness_i2t_agg(model, result_dir):
model = model.split("/")[-1]
result_path = os.path.join(result_dir, "adversarial_robustness_i2t_summary.json")
with open(result_path, "r") as file:
results = json.load(file)
agg_scores = {}
agg_scores["score"] = results[model].pop("Average")
agg_scores["subscenarios"] = results[model]
return agg_scores
if __name__ == "__main__":
t2i_models = [ # Average time spent running the following example
"dall-e-2",
"dall-e-3",
"DeepFloyd/IF-I-M-v1.0", # 15.372
"dreamlike-art/dreamlike-photoreal-2.0", # 3.526
"prompthero/openjourney-v4", # 4.981
"stabilityai/stable-diffusion-xl-base-1.0", # 7.463
]
i2t_models = [ # Average time spent running the following example
"gpt-4-vision-preview",
"gpt-4o-2024-05-13",
"llava-hf/llava-v1.6-vicuna-7b-hf"
]
result_dir = "./data/results"
print(adversarial_robustness_i2t_agg(i2t_models[0], result_dir))
print(adversarial_robustness_t2i_agg(t2i_models[0], result_dir))