syCen commited on
Commit
ceb99c8
·
verified ·
1 Parent(s): 1bdcf8a

Create check_active.py

Browse files
Files changed (1) hide show
  1. check_active.py +46 -0
check_active.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Quick check: how many clips actually contain contact (nonzero) frames?
3
+ If most clips are all-zero, the VAE will collapse to predicting 0.
4
+
5
+ Usage:
6
+ python check_clip_activity.py --clips ... --stats ... --source_root ... --modality contact --n 200
7
+ """
8
+ import argparse, sys, os
9
+ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
10
+ from physical_dataset import PhysicalClipDataset
11
+ import numpy as np
12
+
13
+ ap = argparse.ArgumentParser()
14
+ ap.add_argument("--clips", required=True)
15
+ ap.add_argument("--stats", required=True)
16
+ ap.add_argument("--source_root", required=True)
17
+ ap.add_argument("--modality", default="contact")
18
+ ap.add_argument("--n", type=int, default=200, help="how many clips to scan")
19
+ args = ap.parse_args()
20
+
21
+ ds = PhysicalClipDataset(args.clips, args.stats, args.source_root, args.modality)
22
+ n = min(args.n, len(ds))
23
+ print(f"scanning {n}/{len(ds)} clips...")
24
+
25
+ all_zero = 0
26
+ active_fracs = []
27
+ contact_frame_counts = [] # how many of the 17 frames have any contact
28
+ for i in range(n):
29
+ item = ds[i]
30
+ m = item["active_mask"] # (1,T,H,W)
31
+ af = float(m.mean())
32
+ active_fracs.append(af)
33
+ if af == 0.0:
34
+ all_zero += 1
35
+ # frames with any contact
36
+ per_frame = m[0].reshape(m.shape[1], -1).sum(1) # (T,)
37
+ contact_frame_counts.append(int((per_frame > 0).sum()))
38
+
39
+ active_fracs = np.array(active_fracs)
40
+ cfc = np.array(contact_frame_counts)
41
+ print(f"\nall-zero clips: {all_zero}/{n} ({100*all_zero/n:.1f}%)")
42
+ print(f"active frac: mean={active_fracs.mean():.4f} max={active_fracs.max():.4f}")
43
+ print(f"contact frames per clip (of 17): mean={cfc.mean():.1f} "
44
+ f"min={cfc.min()} max={cfc.max()}")
45
+ print(f"clips with >=1 contact frame: {(cfc>0).sum()}/{n} ({100*(cfc>0).sum()/n:.1f}%)")
46
+ print(f"clips with >=8 contact frames: {(cfc>=8).sum()}/{n}")