Kurt Stolle commited on
Commit
0bb73c7
·
1 Parent(s): 4849086

Minor readability improvements

Browse files
Files changed (2) hide show
  1. examples.ipynb +24 -113
  2. scripts/build.py +3 -0
examples.ipynb CHANGED
@@ -14,7 +14,7 @@
14
  },
15
  {
16
  "cell_type": "code",
17
- "execution_count": 4,
18
  "metadata": {},
19
  "outputs": [
20
  {
@@ -22,110 +22,20 @@
22
  "output_type": "stream",
23
  "text": [
24
  "Sample csvps-val/000030\n",
25
- "{'frames': {'is_annotated': [False, False, False, False, True, False, False,\n",
26
- " False, False, True, False, False, False, False,\n",
27
- " True, False, False, False, False, True, False,\n",
28
- " False, False, False, True, False, False, False,\n",
29
- " False, True],\n",
30
- " 'number': ['000000', '000001', '000002', '000003', '000004',\n",
31
- " '000005', '000006', '000007', '000008', '000009',\n",
32
- " '000010', '000011', '000012', '000013', '000014',\n",
33
- " '000015', '000016', '000017', '000018', '000019',\n",
34
- " '000020', '000021', '000022', '000023', '000024',\n",
35
- " '000025', '000026', '000027', '000028', '000029'],\n",
36
- " 'primary_key': ['lindau_000037_000000', 'lindau_000037_000001',\n",
37
- " 'lindau_000037_000002', 'lindau_000037_000003',\n",
38
- " 'lindau_000037_000004', 'lindau_000037_000005',\n",
39
- " 'lindau_000037_000006', 'lindau_000037_000007',\n",
40
- " 'lindau_000037_000008', 'lindau_000037_000009',\n",
41
- " 'lindau_000037_000010', 'lindau_000037_000011',\n",
42
- " 'lindau_000037_000012', 'lindau_000037_000013',\n",
43
- " 'lindau_000037_000014', 'lindau_000037_000015',\n",
44
- " 'lindau_000037_000016', 'lindau_000037_000017',\n",
45
- " 'lindau_000037_000018', 'lindau_000037_000019',\n",
46
- " 'lindau_000037_000020', 'lindau_000037_000021',\n",
47
- " 'lindau_000037_000022', 'lindau_000037_000023',\n",
48
- " 'lindau_000037_000024', 'lindau_000037_000025',\n",
49
- " 'lindau_000037_000026', 'lindau_000037_000027',\n",
50
- " 'lindau_000037_000028', 'lindau_000037_000029'],\n",
51
- " 'timestamps': [0, 58925424, 117850824, 176776224, 235701592,\n",
52
- " 294627064, 353552488, 412478000, 471403416,\n",
53
- " 530328888, 589254288, 648179664, 707105072,\n",
54
- " 766030408, 824955840, 883881184, 942806640,\n",
55
- " 1001732056, 1060657528, 1119582984, 1178508320,\n",
56
- " 1237433744, 1296359088, 1355284520, 1414209856,\n",
57
- " 1473135304, 1532060720, 1590986120, 1649911576,\n",
58
- " 1708836952]}}\n",
59
  "Sample csvps-val/000031\n",
60
- "{'frames': {'is_annotated': [False, False, False, False, True, False, False,\n",
61
- " False, False, True, False, False, False, False,\n",
62
- " True, False, False, False, False, True, False,\n",
63
- " False, False, False, True, False, False, False,\n",
64
- " False, True],\n",
65
- " 'number': ['000000', '000001', '000002', '000003', '000004',\n",
66
- " '000005', '000006', '000007', '000008', '000009',\n",
67
- " '000010', '000011', '000012', '000013', '000014',\n",
68
- " '000015', '000016', '000017', '000018', '000019',\n",
69
- " '000020', '000021', '000022', '000023', '000024',\n",
70
- " '000025', '000026', '000027', '000028', '000029'],\n",
71
- " 'primary_key': ['lindau_000047_000000', 'lindau_000047_000001',\n",
72
- " 'lindau_000047_000002', 'lindau_000047_000003',\n",
73
- " 'lindau_000047_000004', 'lindau_000047_000005',\n",
74
- " 'lindau_000047_000006', 'lindau_000047_000007',\n",
75
- " 'lindau_000047_000008', 'lindau_000047_000009',\n",
76
- " 'lindau_000047_000010', 'lindau_000047_000011',\n",
77
- " 'lindau_000047_000012', 'lindau_000047_000013',\n",
78
- " 'lindau_000047_000014', 'lindau_000047_000015',\n",
79
- " 'lindau_000047_000016', 'lindau_000047_000017',\n",
80
- " 'lindau_000047_000018', 'lindau_000047_000019',\n",
81
- " 'lindau_000047_000020', 'lindau_000047_000021',\n",
82
- " 'lindau_000047_000022', 'lindau_000047_000023',\n",
83
- " 'lindau_000047_000024', 'lindau_000047_000025',\n",
84
- " 'lindau_000047_000026', 'lindau_000047_000027',\n",
85
- " 'lindau_000047_000028', 'lindau_000047_000029'],\n",
86
- " 'timestamps': [0, 58925416, 117850784, 176776216, 235701560,\n",
87
- " 294627000, 353552352, 412477776, 471403168,\n",
88
- " 530328552, 589253984, 648179336, 707104784,\n",
89
- " 766030160, 824955608, 883880992, 942806400,\n",
90
- " 1001731832, 1060657200, 1119582648, 1178508008,\n",
91
- " 1237433456, 1296358824, 1355284248, 1414209648,\n",
92
- " 1473135024, 1532060464, 1590985824, 1649911272,\n",
93
- " 1708836624]}}\n",
94
  "Sample csvps-val/000032\n",
95
- "{'frames': {'is_annotated': [False, False, False, False, True, False, False,\n",
96
- " False, False, True, False, False, False, False,\n",
97
- " True, False, False, False, False, True, False,\n",
98
- " False, False, False, True, False, False, False,\n",
99
- " False, True],\n",
100
- " 'number': ['000000', '000001', '000002', '000003', '000004',\n",
101
- " '000005', '000006', '000007', '000008', '000009',\n",
102
- " '000010', '000011', '000012', '000013', '000014',\n",
103
- " '000015', '000016', '000017', '000018', '000019',\n",
104
- " '000020', '000021', '000022', '000023', '000024',\n",
105
- " '000025', '000026', '000027', '000028', '000029'],\n",
106
- " 'primary_key': ['lindau_000057_000000', 'lindau_000057_000001',\n",
107
- " 'lindau_000057_000002', 'lindau_000057_000003',\n",
108
- " 'lindau_000057_000004', 'lindau_000057_000005',\n",
109
- " 'lindau_000057_000006', 'lindau_000057_000007',\n",
110
- " 'lindau_000057_000008', 'lindau_000057_000009',\n",
111
- " 'lindau_000057_000010', 'lindau_000057_000011',\n",
112
- " 'lindau_000057_000012', 'lindau_000057_000013',\n",
113
- " 'lindau_000057_000014', 'lindau_000057_000015',\n",
114
- " 'lindau_000057_000016', 'lindau_000057_000017',\n",
115
- " 'lindau_000057_000018', 'lindau_000057_000019',\n",
116
- " 'lindau_000057_000020', 'lindau_000057_000021',\n",
117
- " 'lindau_000057_000022', 'lindau_000057_000023',\n",
118
- " 'lindau_000057_000024', 'lindau_000057_000025',\n",
119
- " 'lindau_000057_000026', 'lindau_000057_000027',\n",
120
- " 'lindau_000057_000028', 'lindau_000057_000029'],\n",
121
- " 'timestamps': [0, 58925896, 117851752, 176777576, 235703424,\n",
122
- " 294629232, 353555104, 412480888, 471406760,\n",
123
- " 530332656, 589258512, 648184360, 707110176,\n",
124
- " 766036096, 824961936, 883887864, 942813704,\n",
125
- " 1001739592, 1060665480, 1119591288, 1178517152,\n",
126
- " 1237442936, 1296368816, 1355294616, 1414220496,\n",
127
- " 1473146352, 1532072200, 1590998064, 1649923840,\n",
128
- " 1708849704]}}\n"
129
  ]
130
  }
131
  ],
@@ -144,7 +54,7 @@
144
  "for i, sample in enumerate(ds):\n",
145
  " if i > 2: \n",
146
  " break\n",
147
- " meta_data = json.loads(sample[\"json\"].decode())\n",
148
  " print(\"Sample \" + sample[\"__key__\"])\n",
149
  " print(pformat(meta_data, compact=True))\n",
150
  " "
@@ -161,7 +71,7 @@
161
  },
162
  {
163
  "cell_type": "code",
164
- "execution_count": 13,
165
  "metadata": {},
166
  "outputs": [
167
  {
@@ -170,11 +80,11 @@
170
  "text": [
171
  "__key__ (<class 'str'>) csvps-val/000030/000000:000001\n",
172
  "camera.json (<class 'bytes'>) ...\n",
173
- "json (<class 'bytes'>) ...\n",
174
- "panoptic.png (<class 'list'>) 2\n",
175
- "depth.tiff (<class 'list'>) 2\n",
176
  "image.png (<class 'list'>) 2\n",
177
- "vehicle.json (<class 'list'>) 2\n"
 
178
  ]
179
  }
180
  ],
@@ -182,7 +92,7 @@
182
  "import collections\n",
183
  "import itertools\n",
184
  "\n",
185
- "def find_frame_keys(keys):\n",
186
  " r\"\"\"\n",
187
  " Returns a mapping from frame number to the keys of the sample that correspond to \n",
188
  " that frame.\n",
@@ -196,7 +106,7 @@
196
  " meta_keys.add(key)\n",
197
  " continue \n",
198
  " stem, other = key.split(\".\", 1)\n",
199
- " if stem.isdigit():\n",
200
  " frame_keys[stem].append(other)\n",
201
  " else:\n",
202
  " meta_keys.add(key)\n",
@@ -205,8 +115,9 @@
205
  "\n",
206
  "def generate_range(src, length: int = 2, *, missing_ok: bool =True):\n",
207
  " for sample in src:\n",
 
208
  " key = sample[\"__key__\"]\n",
209
- " frame_keys, meta_keys = find_frame_keys(sample.keys()) \n",
210
  " \n",
211
  " pair_keys = set(itertools.chain.from_iterable(frame_keys.values()))\n",
212
  " meta_data = {key: sample[key] for key in meta_keys}\n",
@@ -252,7 +163,7 @@
252
  },
253
  {
254
  "cell_type": "code",
255
- "execution_count": 14,
256
  "metadata": {},
257
  "outputs": [
258
  {
 
14
  },
15
  {
16
  "cell_type": "code",
17
+ "execution_count": 1,
18
  "metadata": {},
19
  "outputs": [
20
  {
 
22
  "output_type": "stream",
23
  "text": [
24
  "Sample csvps-val/000030\n",
25
+ "['000000', '000001', '000002', '000003', '000004', '000005', '000006', '000007',\n",
26
+ " '000008', '000009', '000010', '000011', '000012', '000013', '000014', '000015',\n",
27
+ " '000016', '000017', '000018', '000019', '000020', '000021', '000022', '000023',\n",
28
+ " '000024', '000025', '000026', '000027', '000028', '000029']\n",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  "Sample csvps-val/000031\n",
30
+ "['000000', '000001', '000002', '000003', '000004', '000005', '000006', '000007',\n",
31
+ " '000008', '000009', '000010', '000011', '000012', '000013', '000014', '000015',\n",
32
+ " '000016', '000017', '000018', '000019', '000020', '000021', '000022', '000023',\n",
33
+ " '000024', '000025', '000026', '000027', '000028', '000029']\n",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  "Sample csvps-val/000032\n",
35
+ "['000000', '000001', '000002', '000003', '000004', '000005', '000006', '000007',\n",
36
+ " '000008', '000009', '000010', '000011', '000012', '000013', '000014', '000015',\n",
37
+ " '000016', '000017', '000018', '000019', '000020', '000021', '000022', '000023',\n",
38
+ " '000024', '000025', '000026', '000027', '000028', '000029']\n"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  ]
40
  }
41
  ],
 
54
  "for i, sample in enumerate(ds):\n",
55
  " if i > 2: \n",
56
  " break\n",
57
+ " meta_data = json.loads(sample[\"frames.json\"].decode())\n",
58
  " print(\"Sample \" + sample[\"__key__\"])\n",
59
  " print(pformat(meta_data, compact=True))\n",
60
  " "
 
71
  },
72
  {
73
  "cell_type": "code",
74
+ "execution_count": 2,
75
  "metadata": {},
76
  "outputs": [
77
  {
 
80
  "text": [
81
  "__key__ (<class 'str'>) csvps-val/000030/000000:000001\n",
82
  "camera.json (<class 'bytes'>) ...\n",
83
+ "metadata.json (<class 'list'>) 2\n",
84
+ "vehicle.json (<class 'list'>) 2\n",
 
85
  "image.png (<class 'list'>) 2\n",
86
+ "panoptic.png (<class 'list'>) 2\n",
87
+ "depth.tiff (<class 'list'>) 2\n"
88
  ]
89
  }
90
  ],
 
92
  "import collections\n",
93
  "import itertools\n",
94
  "\n",
95
+ "def find_frame_keys(keys, frames):\n",
96
  " r\"\"\"\n",
97
  " Returns a mapping from frame number to the keys of the sample that correspond to \n",
98
  " that frame.\n",
 
106
  " meta_keys.add(key)\n",
107
  " continue \n",
108
  " stem, other = key.split(\".\", 1)\n",
109
+ " if stem in frames:\n",
110
  " frame_keys[stem].append(other)\n",
111
  " else:\n",
112
  " meta_keys.add(key)\n",
 
115
  "\n",
116
  "def generate_range(src, length: int = 2, *, missing_ok: bool =True):\n",
117
  " for sample in src:\n",
118
+ " frames = json.loads(sample.pop(\"frames.json\").decode())\n",
119
  " key = sample[\"__key__\"]\n",
120
+ " frame_keys, meta_keys = find_frame_keys(sample.keys(), frames) \n",
121
  " \n",
122
  " pair_keys = set(itertools.chain.from_iterable(frame_keys.values()))\n",
123
  " meta_data = {key: sample[key] for key in meta_keys}\n",
 
163
  },
164
  {
165
  "cell_type": "code",
166
+ "execution_count": null,
167
  "metadata": {},
168
  "outputs": [
169
  {
scripts/build.py CHANGED
@@ -57,6 +57,7 @@ def parse_args():
57
  ap.add_argument(
58
  "--splits", nargs="+", default=["train", "val", "test"], help="Splits to build."
59
  )
 
60
 
61
  # Positional
62
  ap.add_argument("manifest", type=Path, help="Path to the manifest CSV file.")
@@ -132,6 +133,7 @@ def find_sequence_files(
132
  *,
133
  data_dir: Path,
134
  dataset_name: str,
 
135
  missing_ok: bool = False,
136
  frame_inputs: T.Sequence[str] = ("image.png", "vehicle.json"),
137
  frame_annotations: T.Sequence[str] = ("panoptic.png", "depth.tiff"),
@@ -356,6 +358,7 @@ def main():
356
  shard_size=args.shard_size,
357
  dataset_name=f"{args.name}-{split_out}",
358
  missing_ok=True,
 
359
  )
360
 
361
 
 
57
  ap.add_argument(
58
  "--splits", nargs="+", default=["train", "val", "test"], help="Splits to build."
59
  )
60
+ ap.add_argument("--compression", "-c", default="", help="Compression to use")
61
 
62
  # Positional
63
  ap.add_argument("manifest", type=Path, help="Path to the manifest CSV file.")
 
133
  *,
134
  data_dir: Path,
135
  dataset_name: str,
136
+ compression: str,
137
  missing_ok: bool = False,
138
  frame_inputs: T.Sequence[str] = ("image.png", "vehicle.json"),
139
  frame_annotations: T.Sequence[str] = ("panoptic.png", "depth.tiff"),
 
358
  shard_size=args.shard_size,
359
  dataset_name=f"{args.name}-{split_out}",
360
  missing_ok=True,
361
+ compression=args.compression
362
  )
363
 
364