File size: 2,581 Bytes
16231ab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python3
"""Training exclusions and CV folds of the final model.

Starts from the combined revision's train_exclude_combined.csv (the added datasets' pairs outside their training
subsets) and cv_folds_combined.csv, and removes the photos listed in data/drop_lists/ from training AND from scoring:
  tau_indoor_scenes.csv         TAU Urban AV scenes filmed indoors or in vehicles (airport, shopping mall, metro
                                station, metro, bus, tram; 1,539 pairs)
  manual_non_scene_frames.csv   photos checked by eye that show no place for their sound (431 pairs): YFCC frames of
                                pure sky (93) or indoor (22), two YFCC videos (waterfall close-up, car show with
                                loud music), near-black night frames (360+x 198, TAU 6; readable evening / night
                                scenes are kept) and five 360+x videos filmed indoors (cafe, three restaurants, a room
                                with a balcony)
Writes train_exclude_final.csv (view_id) and cv_folds_final.csv next to the inputs.
"""
import sys as _sys
from pathlib import Path as _Path
_SCRIPTS = next(_p for _p in _Path(__file__).resolve().parents if _p.name == "scripts")
_sys.path[:0] = [str(_SCRIPTS.parent), str(_SCRIPTS.parent / "models")] + [str(_d) for _d in sorted(_SCRIPTS.rglob("*")) if _d.is_dir() and _d.name != "__pycache__"]
import argparse
from pathlib import Path

import pandas as pd

p = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
p.add_argument("--revision-dir", type=Path, required=True,
               help="runs_main_all_datasets/direct_aq_dataset_gain/<rev>_allnew_ref40_usotw4")
p.add_argument("--drop-lists", type=Path, nargs="+",
               default=[Path("data/drop_lists/tau_indoor_scenes.csv"), Path("data/drop_lists/manual_non_scene_frames.csv")])
a = p.parse_args()

drop = set()
for f in a.drop_lists:
    v = pd.read_csv(f).view_id.astype(str)
    print(f"{f}: {len(v)} pairs")
    drop |= set(v)
base = pd.read_csv(a.revision_dir / "train_exclude_combined.csv")
ex = pd.DataFrame({"view_id": sorted(set(base.view_id.astype(str)) | drop)})
ex.to_csv(a.revision_dir / "train_exclude_final.csv", index=False)
folds = pd.read_csv(a.revision_dir / "cv_folds_combined.csv", low_memory=False)
kept = folds[~folds.view_id.astype(str).isin(drop)]
kept.to_csv(a.revision_dir / "cv_folds_final.csv", index=False)
print(f"train_exclude_final.csv: {len(base)} -> {len(ex)} view ids; cv_folds_final.csv: {len(folds)} -> {len(kept)} pairs")