WayenVan commited on
Commit
ee67f51
·
1 Parent(s): f4a5df4

change builder name

Browse files
Files changed (2) hide show
  1. build.py → rnb-radar.py +73 -43
  2. test.py +22 -4
build.py → rnb-radar.py RENAMED
@@ -29,17 +29,6 @@ from datasets import GeneratorBasedBuilder, DatasetInfo, Features, Value, Split
29
  class PolarsBuilder(GeneratorBasedBuilder):
30
  VERSION = datasets.Version("1.0.0")
31
 
32
- def _infer_features(self, df: pl.DataFrame) -> Features:
33
- mapping = {}
34
- for col, dtype in zip(df.columns, df.dtypes):
35
- if dtype in (pl.Int8, pl.Int16, pl.Int32, pl.Int64):
36
- mapping[col] = Value("int64")
37
- elif dtype in (pl.Float32, pl.Float64):
38
- mapping[col] = Value("float32")
39
- else:
40
- mapping[col] = Value("string")
41
- return Features(mapping)
42
-
43
  @property
44
  def df(self):
45
  data_dir = self.config.data_dir
@@ -47,14 +36,33 @@ class PolarsBuilder(GeneratorBasedBuilder):
47
  raise ValueError("data_dir must be specified in the config")
48
  return build_table(data_dir)
49
 
50
- @property
51
- def features(self):
52
- return self._infer_features(self.df)
53
-
54
  def _info(self):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  return DatasetInfo(
56
  description="自定义 Builder,使用 Polars 自动推断 schema",
57
- features=self.features,
58
  supervised_keys=None,
59
  )
60
 
@@ -79,14 +87,36 @@ def build_table(data_root):
79
  radar_table = build_single_table(data_root, "radardata", parse_radar_data)
80
  rgbdata_table = build_single_table(data_root, "rgbdata", parse_rgbdata_data)
81
 
82
- data_table = depth_table.join(
83
- radar_table, on=["id", "index"], how="inner", suffix="_radar"
84
- ).join(rgbdata_table, on=["id", "index"], how="inner", suffix="_rgbdata")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  data_table = data_table.rename(
86
  {
87
- "file_path": "file_path_depthdata",
88
- "location": "location_depthdata",
89
- "subject": "subject_depthdata",
 
 
90
  }
91
  )
92
 
@@ -123,11 +153,11 @@ def parse_depth_data(source_relatvie_root, file_name):
123
  )
124
 
125
  return dict(
126
- id=parts[0],
127
- location=parts[1],
128
- subject=parts[2],
129
- index=int(parts[3]),
130
- file_path=os.path.join(
131
  source_relatvie_root, file_name
132
  ), # Use the relative path
133
  )
@@ -147,17 +177,17 @@ def parse_radar_data(source_relatvie_root, file_name):
147
  )
148
 
149
  return dict(
150
- id=parts[0],
151
- location=parts[1],
152
- subject=parts[2],
153
- freqency=int(parts[3]),
154
- dimension=parts[4],
155
- angle=int(parts[5]),
156
- distance=int(parts[6]),
157
- index=int(parts[7]),
158
- uname1=int(parts[8]),
159
- uname2=float(parts[9]),
160
- file_path=os.path.join(
161
  source_relatvie_root,
162
  file_name, # Use the relative path
163
  ),
@@ -179,11 +209,11 @@ def parse_rgbdata_data(source_relatvie_root, file_name):
179
  )
180
 
181
  return dict(
182
- id=parts[0],
183
- location=parts[1],
184
- subject=parts[2],
185
- index=int(parts[3]),
186
- file_path=os.path.join(
187
  source_relatvie_root, file_name
188
  ), # Use the relative path
189
  )
 
29
  class PolarsBuilder(GeneratorBasedBuilder):
30
  VERSION = datasets.Version("1.0.0")
31
 
 
 
 
 
 
 
 
 
 
 
 
32
  @property
33
  def df(self):
34
  data_dir = self.config.data_dir
 
36
  raise ValueError("data_dir must be specified in the config")
37
  return build_table(data_dir)
38
 
 
 
 
 
39
  def _info(self):
40
+ feats = Features(
41
+ {
42
+ "time": Value(dtype="string", id=None),
43
+ "location_depth": Value(dtype="string", id=None),
44
+ "subject_depth": Value(dtype="string", id=None),
45
+ "index_rgb_depth": Value(dtype="int64", id=None),
46
+ "file_path_depth": Value(dtype="string", id=None),
47
+ "index_radar": Value(dtype="int64", id=None),
48
+ "location_rgb": Value(dtype="string", id=None),
49
+ "subject_rgb": Value(dtype="string", id=None),
50
+ "file_path_rgb": Value(dtype="string", id=None),
51
+ "location_radar": Value(dtype="string", id=None),
52
+ "subject_radar": Value(dtype="string", id=None),
53
+ "length_radar_cube": Value(dtype="int64", id=None),
54
+ "dimension_radar": Value(dtype="string", id=None),
55
+ "window_size_radar": Value(dtype="int64", id=None),
56
+ "window_stride_radar": Value(dtype="int64", id=None),
57
+ "selected_range_bin": Value(dtype="int64", id=None),
58
+ "enthrophy": Value(dtype="float32", id=None),
59
+ "file_path_radar": Value(dtype="string", id=None),
60
+ }
61
+ )
62
+
63
  return DatasetInfo(
64
  description="自定义 Builder,使用 Polars 自动推断 schema",
65
+ features=feats,
66
  supervised_keys=None,
67
  )
68
 
 
87
  radar_table = build_single_table(data_root, "radardata", parse_radar_data)
88
  rgbdata_table = build_single_table(data_root, "rgbdata", parse_rgbdata_data)
89
 
90
+ depth_table = depth_table.with_columns(
91
+ ((pl.col("index_depth") + 1) // 2).alias("index_radar")
92
+ )
93
+ rgbdata_table = rgbdata_table.with_columns(
94
+ ((pl.col("index_rgb") + 1) // 2).alias("index_radar")
95
+ )
96
+ # print(radar_table)
97
+
98
+ t1 = depth_table.join(
99
+ rgbdata_table,
100
+ left_on=["time", "index_depth", "index_radar"],
101
+ right_on=["time", "index_rgb", "index_radar"],
102
+ ).rename({"index_depth": "index_rgb_depth"})
103
+
104
+ # print(t1)
105
+ # print(t1.columns)
106
+
107
+ data_table = t1.join(
108
+ radar_table,
109
+ left_on=["time", "index_radar"],
110
+ right_on=["time", "index_radar"],
111
+ how="inner",
112
+ )
113
  data_table = data_table.rename(
114
  {
115
+ # "file_path": "file_path_depthdata",
116
+ # "location": "location_depthdata",
117
+ # "subject": "subject_depthdata",
118
+ # "index_tmp": "index_rgb_depth",
119
+ # "index": "index_radar",
120
  }
121
  )
122
 
 
153
  )
154
 
155
  return dict(
156
+ time=parts[0],
157
+ location_depth=parts[1],
158
+ subject_depth=parts[2],
159
+ index_depth=int(parts[3]),
160
+ file_path_depth=os.path.join(
161
  source_relatvie_root, file_name
162
  ), # Use the relative path
163
  )
 
177
  )
178
 
179
  return dict(
180
+ time=parts[0],
181
+ location_radar=parts[1],
182
+ subject_radar=parts[2],
183
+ length_radar_cube=int(parts[3]),
184
+ dimension_radar=parts[4],
185
+ window_size_radar=int(parts[5]),
186
+ window_stride_radar=int(parts[6]),
187
+ index_radar=int(parts[7]),
188
+ selected_range_bin=int(parts[8]),
189
+ enthrophy=float(parts[9]),
190
+ file_path_radar=os.path.join(
191
  source_relatvie_root,
192
  file_name, # Use the relative path
193
  ),
 
209
  )
210
 
211
  return dict(
212
+ time=parts[0],
213
+ location_rgb=parts[1],
214
+ subject_rgb=parts[2],
215
+ index_rgb=int(parts[3]),
216
+ file_path_rgb=os.path.join(
217
  source_relatvie_root, file_name
218
  ), # Use the relative path
219
  )
test.py CHANGED
@@ -1,8 +1,26 @@
1
  from datasets import load_dataset
2
 
3
 
4
- dataset = load_dataset("./build.py", data_dir="./", split="train")
5
 
6
- print(dataset.to_pandas().head())
7
- for id in dataset.unique("id"):
8
- print(id)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from datasets import load_dataset
2
 
3
 
4
+ dataset = load_dataset("/root/projects/rnb-radar", data_dir='.')['train']
5
 
6
+
7
+
8
+ print(dataset.unique("selected_range_bin"))
9
+ print(dataset.unique("window_size_radar"))
10
+ print(dataset.unique("window_stride_radar"))
11
+ print(dataset.unique("dimension_radar"))
12
+
13
+ pl = dataset.to_polars()
14
+
15
+
16
+ print(dataset.to_polars())
17
+ print(dataset.features)
18
+ # dimension_radar
19
+ # window_size_radar
20
+ # window_stride_radar
21
+ # selected_range_bin
22
+ #
23
+ # ['2D']
24
+ # [2]
25
+ # [2]
26
+ # [78, 79, 81, 77, 80, 76, 82]