|
|
import csv |
|
|
import numpy as np |
|
|
from scipy.stats import spearmanr, kendalltau |
|
|
|
|
|
def add_to_csv(input_files,human_score_csv): |
|
|
output_rows = [] |
|
|
for idx in [0,10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190]: |
|
|
for filename in input_files: |
|
|
with open(filename, newline='', encoding='utf-8') as f: |
|
|
reader = csv.reader(f) |
|
|
header = next(reader) |
|
|
rows = list(reader) |
|
|
if idx < len(rows): |
|
|
for row in rows: |
|
|
if row[0] == f"{idx+1:04d}.png": |
|
|
target_row = row |
|
|
break |
|
|
|
|
|
|
|
|
|
|
|
third_last = target_row[-3] |
|
|
second_last = target_row[-2] |
|
|
output_rows.append([third_last, second_last]) |
|
|
|
|
|
|
|
|
with open(human_score_csv, newline='', encoding='utf-8') as f: |
|
|
reader = csv.reader(f) |
|
|
original_rows = list(reader) |
|
|
|
|
|
|
|
|
if len(original_rows) - 1 != len(output_rows): |
|
|
raise ValueError("原CSV数据行数与新列数据行数不一致,请检查!") |
|
|
|
|
|
|
|
|
with open(human_score_csv, 'w', newline='', encoding='utf-8') as f: |
|
|
writer = csv.writer(f) |
|
|
|
|
|
writer.writerow(original_rows[0][0:10] + ['qwen_alignment', 'qwen_quality']) |
|
|
|
|
|
for orig_row, new_col in zip(original_rows[1:], output_rows): |
|
|
writer.writerow(orig_row[0:10] + new_col) |
|
|
|
|
|
|
|
|
def corr(combined_csv): |
|
|
avg_align_list = [] |
|
|
avg_quality_list= [] |
|
|
qwen_align_list = [] |
|
|
qwen_quality_list = [] |
|
|
|
|
|
with open(combined_csv, newline='', encoding='utf-8') as f: |
|
|
reader = csv.reader(f) |
|
|
header = next(reader) |
|
|
for row in reader: |
|
|
|
|
|
alignment_123 = [float(row[-9]), float(row[-8]), float(row[-7])] |
|
|
|
|
|
alignment_avg = np.mean(alignment_123) |
|
|
|
|
|
avg_align_list.append(alignment_avg) |
|
|
|
|
|
|
|
|
qwen_alignment = float(row[-2]) |
|
|
qwen_quality = float(row[-1]) |
|
|
qwen_alignment_qualilty = 0.9*qwen_alignment + 0.1*qwen_quality |
|
|
|
|
|
|
|
|
|
|
|
qwen_align_list.append(qwen_alignment_qualilty) |
|
|
|
|
|
|
|
|
|
|
|
align_spearman_corr, align_spearman_p = spearmanr(avg_align_list, qwen_align_list) |
|
|
align_kendall_corr, align_kendall_p = kendalltau(avg_align_list, qwen_align_list) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print(f"align Spearman correlation: {align_spearman_corr:.4f}, p-value: {align_spearman_p:.4g}") |
|
|
print(f"align Kendall correlation: {align_kendall_corr:.4f}, p-value: {align_kendall_p:.4g}") |
|
|
|
|
|
print(f"{align_kendall_corr:.4f} & {align_spearman_corr:.4f} &") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
input_files = [ |
|
|
"/group/xihuiliu/sky/reasoning/csv/text_image_new/bagel.csv", |
|
|
"/group/xihuiliu/sky/reasoning/csv/text_image_new/GPT.csv", |
|
|
"/group/xihuiliu/sky/reasoning/csv/text_image_new/hidream.csv", |
|
|
"/group/xihuiliu/sky/reasoning/csv/text_image_new/janus_pro_7B.csv", |
|
|
"/group/xihuiliu/sky/reasoning/csv/text_image_new/sd30_medium.csv", |
|
|
] |
|
|
human_score_csv = "/group/xihuiliu/sky/reasoning/human_eval/human_score/text_image.csv" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
add_to_csv(input_files,human_score_csv) |
|
|
|
|
|
corr(human_score_csv) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|