ksikka Claude Sonnet 4.6 commited on
Commit
71ee09b
·
1 Parent(s): c310e69

add dataset viewer: parquet files with embedded images and keypoints

Browse files
README.md CHANGED
@@ -11,6 +11,13 @@ tags:
11
  pretty_name: Fly Anipose (Lightning Pose subset)
12
  size_categories:
13
  - 1K<n<10K
 
 
 
 
 
 
 
14
  ---
15
 
16
  # Fly Anipose — Lightning Pose Multiview Dataset
 
11
  pretty_name: Fly Anipose (Lightning Pose subset)
12
  size_categories:
13
  - 1K<n<10K
14
+ configs:
15
+ - config_name: default
16
+ data_files:
17
+ - split: ind
18
+ path: data/ind-train-*.parquet
19
+ - split: ood
20
+ path: data/ood-test-*.parquet
21
  ---
22
 
23
  # Fly Anipose — Lightning Pose Multiview Dataset
data/ind-train-00000-of-00001.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d83bf5168f9f171a4af691553d730d676a1bc65bc1dd82eb5b2e7e5ed31947ab
3
+ size 443199363
data/ood-test-00000-of-00001.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a614e672cd0ea04a0faabed8aa50441e77519067313eacc1bf697ba54187f813
3
+ size 349177834
scripts/build_parquet.py ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Build Parquet files for HuggingFace dataset viewer.
3
+
4
+ Reads Lightning Pose CSVs and corresponding PNG frames, then writes
5
+ Parquet files with embedded images to data/ for the HF viewer.
6
+
7
+ Usage (from repo root):
8
+ python scripts/build_parquet.py
9
+ """
10
+
11
+ import csv
12
+ import io
13
+ from pathlib import Path
14
+
15
+ import datasets
16
+ from datasets import Dataset, Features, Image, Value, Sequence
17
+
18
+ REPO_ROOT = Path(__file__).parent.parent
19
+ DATA_OUT = REPO_ROOT / "data"
20
+
21
+ VIEWS = ["Cam-A", "Cam-B", "Cam-C", "Cam-D", "Cam-E", "Cam-F"]
22
+
23
+ KEYPOINTS = [
24
+ "L1A", "L1B", "L1C", "L1D", "L1E",
25
+ "L2A", "L2B", "L2C", "L2D", "L2E",
26
+ "L3A", "L3B", "L3C", "L3D", "L3E",
27
+ "R1A", "R1B", "R1C", "R1D", "R1E",
28
+ "R2A", "R2B", "R2C", "R2D", "R2E",
29
+ "R3A", "R3B", "R3C", "R3D", "R3E",
30
+ ]
31
+
32
+ FEATURES = Features(
33
+ {
34
+ "image": Image(),
35
+ "session": Value("string"),
36
+ "view": Value("string"),
37
+ "split": Value("string"),
38
+ "frame": Value("string"),
39
+ **{f"{kp}_x": Value("float32") for kp in KEYPOINTS},
40
+ **{f"{kp}_y": Value("float32") for kp in KEYPOINTS},
41
+ }
42
+ )
43
+
44
+
45
+ def parse_csv(csv_path: Path, view: str, split: str) -> list[dict]:
46
+ rows = []
47
+ with open(csv_path) as f:
48
+ reader = csv.reader(f)
49
+ # Skip 3-row header: scorer, bodyparts, coords
50
+ next(reader)
51
+ next(reader)
52
+ next(reader)
53
+ for row in reader:
54
+ img_rel_path = row[0]
55
+ img_path = REPO_ROOT / img_rel_path
56
+ if not img_path.exists():
57
+ print(f" WARNING: missing {img_path}, skipping")
58
+ continue
59
+
60
+ coords = row[1:] # 60 values: x0,y0,x1,y1,...
61
+
62
+ record: dict = {
63
+ "image": {"path": None, "bytes": img_path.read_bytes()},
64
+ "session": "_".join(Path(img_rel_path).parent.name.split("_")[:-1]),
65
+ "view": view,
66
+ "split": split,
67
+ "frame": Path(img_rel_path).name,
68
+ }
69
+
70
+ for i, kp in enumerate(KEYPOINTS):
71
+ x_str = coords[i * 2]
72
+ y_str = coords[i * 2 + 1]
73
+ record[f"{kp}_x"] = float(x_str) if x_str else float("nan")
74
+ record[f"{kp}_y"] = float(y_str) if y_str else float("nan")
75
+
76
+ rows.append(record)
77
+ return rows
78
+
79
+
80
+ def build_split(csv_suffix: str, split_name: str) -> list[dict]:
81
+ all_rows = []
82
+ for view in VIEWS:
83
+ csv_path = REPO_ROOT / f"CollectedData_{view}{csv_suffix}.csv"
84
+ if not csv_path.exists():
85
+ print(f"Skipping missing {csv_path}")
86
+ continue
87
+ print(f" Reading {csv_path.name} ...")
88
+ rows = parse_csv(csv_path, view, split_name)
89
+ print(f" {len(rows)} rows")
90
+ all_rows.extend(rows)
91
+ return all_rows
92
+
93
+
94
+ def main():
95
+ DATA_OUT.mkdir(exist_ok=True)
96
+
97
+ print("Building InD split ...")
98
+ ind_rows = build_split("", "ind")
99
+ ind_ds = Dataset.from_list(ind_rows, features=FEATURES)
100
+ out = DATA_OUT / "ind-train-00000-of-00001.parquet"
101
+ ind_ds.to_parquet(str(out))
102
+ print(f"Wrote {out} ({out.stat().st_size / 1e6:.1f} MB, {len(ind_rows)} rows)")
103
+
104
+ print("Building OOD split ...")
105
+ ood_rows = build_split("_new", "ood")
106
+ ood_ds = Dataset.from_list(ood_rows, features=FEATURES)
107
+ out = DATA_OUT / "ood-test-00000-of-00001.parquet"
108
+ ood_ds.to_parquet(str(out))
109
+ print(f"Wrote {out} ({out.stat().st_size / 1e6:.1f} MB, {len(ood_rows)} rows)")
110
+
111
+
112
+ if __name__ == "__main__":
113
+ main()