Datasets:

Modalities:
Image
ArXiv:
Libraries:
Datasets
License:
TUTUS / celebdata /annotations /create_TUTUS_DEV.py
s1m0neee's picture
Upload TUTUS data files 1-400 of 40780
6fb625d verified
Raw History Blame Contribute Delete
4.38 kB
import pandas as pd
import json
import os
import random
from rich.progress import track
# For all the models we have pristine data for
MODELS_PRISTINE = [
"TUTUS-TS-P_llava_next_pristine.csv",
"TUTUS-TS-P_llava_onevision_pristine.csv",
"TUTUS-TS-P_llava_onevision_smol_pristine.csv",
"TUTUS-TS-P_qwen2vl_pristine.csv",
"TUTUS-TS-P_qwen2vl_smol_pristine.csv",
"TUTUS-TS-P_qwen2_5vl_pristine.csv",
"TUTUS-TS-P_qwen2_5vl_smol_pristine.csv",
]
def stats_plot():
import json
import pandas as pd
import scienceplots
import matplotlib.pyplot as plt
import seaborn as sns
plt.style.use("science")
with open("TUTUS-TS-P_leakage_statistics.json", "r") as f:
dj = json.load(f)
df = pd.DataFrame(dj).T.reset_index().rename(columns={'index': 'model'})
# Melt for seaborn
df_melted = df.melt(id_vars='model', var_name='metric', value_name='count')
# Plot
plt.figure(figsize=(6, 4))
sns.barplot(
data=df_melted,
x='model',
y='count',
hue='metric',
#palette='muted'
)
# Styling
plt.title('Leakage Comparison per Model', fontsize=14, weight='bold')
plt.xticks(rotation=45, ha='right')
plt.xlabel('Model')
plt.ylabel('Count')
plt.grid(axis='y', linestyle='--', alpha=0.7)
plt.legend(title='Metric')
plt.tight_layout()
plt.savefig("TUTUS-TS-P_leakage_statistics_plot.pdf")
def main():
leaked_images_intersection = None
leakage_statistics = {}
for subset in MODELS_PRISTINE:
print(f"Processing subset: {subset}")
model_name = subset.replace("TUTUS-TS-P_", "").replace("_pristine.csv", "")
df = pd.read_csv(subset)
df = df.drop_duplicates(subset=["image_path"])
df = df[df.apply(lambda row: row["name"] in row["leaking"], axis=1)]
if not leaked_images_intersection:
leaked_images_intersection = set(df['image_path'].tolist())
else:
leaked_images_intersection = leaked_images_intersection.intersection(set(df['image_path'].tolist()))
tot_identities_leaked = len(set(df['name'].tolist()))
tot_images_leaked = len(df)
leakage_statistics[model_name] = {
"tot_identities_leaked": tot_identities_leaked,
"tot_images_leaked": tot_images_leaked
}
# After the pass on all models, compute intersection stats
output_path = "TUTUS-TS-P_leakage_statistics.json"
leaked_names_intersection = set([fp.split("/")[-2] for fp in leaked_images_intersection])
train_names = set(os.listdir("../train"))
leaked_names_intersection_base_num = len(leaked_names_intersection.intersection(train_names))
leaked_names_intersection_novel_num = len(leaked_names_intersection) - leaked_names_intersection_base_num
leakage_statistics["intersection"] = {
"tot_identities_leaked_base": leaked_names_intersection_base_num,
"tot_identities_leaked_novel": leaked_names_intersection_novel_num,
"tot_images_leaked": len(leaked_images_intersection)
}
with open(output_path, "w") as f:
json.dump(leakage_statistics, f, indent=4)
leaked_images_intersection_subset = random.sample(list(leaked_images_intersection), k=300)
# for subset in track(MODELS_PRISTINE):
# print(f"Processing again to extract dev-subset: {subset}")
# model_name = subset.replace("TUTUS-TS-P_", "").replace("_pristine.csv", "")
# df = pd.read_csv(subset)
# df = df.drop_duplicates(subset=["image_path"])
# df = df[df.apply(lambda row: row["name"] in row["leaking"], axis=1)]
# # I have a list leaked_images_intersection and want to keep only the rows
# # of df that are in leaked_images_intersection
# df = df[df['image_path'].isin(leaked_images_intersection_subset)]
# df.to_csv(f"TUTUS-DEV-{model_name}_pristine.csv", index=False)
df = pd.read_csv("TUTUS-TS-P.csv")[["idx", "ds_name", "name", "image_path", "leaking_prompt", "support_prompt"]]
df = df.drop_duplicates(subset=["image_path"])
# Keep only name/image_id
df = df[df['image_path'].isin("/".join(sample.split("/")[-2:]) for sample in leaked_images_intersection_subset)]
df.to_csv(f"TUTUS-DEV.csv", index=False)
if __name__ == "__main__":
main()