Spaces:
Sleeping
Sleeping
| import argparse | |
| import pandas as pd | |
| def main( | |
| input_csv: str, | |
| out_counts: str = "num_raters_per_video.csv", | |
| out_stats_all: str = "video_stats_all.csv", | |
| out_stats_filtered: str = "video_stats_filtered.csv", | |
| min_raters: int = 2, | |
| ): | |
| # 1) λ°μ΄ν° λ‘λ | |
| df = pd.read_csv(input_csv) | |
| # μ«μν 보μ₯ (λ¬Έμ/λΉμΉΈ μμμ λ λλΉ) | |
| for col in ["action_consistency", "physical_plausibility"]: | |
| if col in df.columns: | |
| df[col] = pd.to_numeric(df[col], errors="coerce") | |
| # 2) λΉλμ€λ³ κ³ μ νκ°μ μ | |
| counts = ( | |
| df.groupby("video_id")["participant_id"] | |
| .nunique() | |
| .reset_index(name="num_raters") | |
| ) | |
| counts.to_csv(out_counts, index=False) | |
| # 3) λΉλμ€λ³ ν΅κ³ (νκ· /νμ€νΈμ°¨/νλ³Έμ) | |
| agg_map = { | |
| "participant_id": pd.Series.nunique, # κ³ μ νκ°μ μ | |
| "action_consistency": ["mean", "std", "count"], | |
| "physical_plausibility": ["mean", "std", "count"], | |
| } | |
| stats = df.groupby("video_id").agg(agg_map) | |
| # μ»¬λΌ ννν | |
| stats.columns = [ | |
| "num_raters", | |
| "action_mean", "action_std", "action_count", | |
| "physical_mean", "physical_std", "physical_count", | |
| ] | |
| stats = stats.reset_index() | |
| # 3-1) (μ ν) λ³λκ³μ(CV)λ μ°Έκ³ μ©μΌλ‘ μΆκ° | |
| stats["action_cv"] = stats["action_std"] / stats["action_mean"] | |
| stats["physical_cv"] = stats["physical_std"] / stats["physical_mean"] | |
| # μ μ₯ (λͺ¨λ λΉλμ€) | |
| stats.to_csv(out_stats_all, index=False) | |
| # 4) μ΅μ νκ°μ μ μ΄μλ§ νν°λ§ | |
| stats_filtered = stats[stats["num_raters"] >= min_raters].copy() | |
| stats_filtered.to_csv(out_stats_filtered, index=False) | |
| # 5) μμ½ νλ¦°νΈ | |
| print("β μ μ₯ μλ£") | |
| print(f"- λΉλμ€λ³ νκ°μ μ: {out_counts}") | |
| print(f"- λΉλμ€λ³ ν΅κ³(μ 체): {out_stats_all}") | |
| print(f"- λΉλμ€λ³ ν΅κ³(νκ°μ {min_raters}λͺ μ΄μ): {out_stats_filtered}") | |
| if __name__ == "__main__": | |
| parser = argparse.ArgumentParser(description="Human eval λΆμ μ€ν¬λ¦½νΈ") | |
| parser.add_argument("--input_csv", type=str, required=True, help="μλ³Έ CSV κ²½λ‘") | |
| parser.add_argument("--out_counts", type=str, default="num_raters_per_video.csv") | |
| parser.add_argument("--out_stats_all", type=str, default="video_stats_all.csv") | |
| parser.add_argument("--out_stats_filtered", type=str, default="video_stats_filtered.csv") | |
| parser.add_argument("--min_raters", type=int, default=2, help="μ΅μ νκ°μ μ κΈ°μ€") | |
| args = parser.parse_args() | |
| main( | |
| input_csv=args.input_csv, | |
| out_counts=args.out_counts, | |
| out_stats_all=args.out_stats_all, | |
| out_stats_filtered=args.out_stats_filtered, | |
| min_raters=args.min_raters, | |
| ) | |