Skip to content

Commit bbfd71c

Browse files
authored
[visualization] Ignore 2d or 3d data for now (huggingface#809)
1 parent f0b0f95 commit bbfd71c

File tree

2 files changed

+58
-40
lines changed

2 files changed

+58
-40
lines changed

lerobot/scripts/visualize_dataset_html.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def show_episode(dataset_namespace, dataset_name, episode_id, dataset=dataset, e
158158
if major_version < 2:
159159
return "Make sure to convert your LeRobotDataset to v2 & above."
160160

161-
episode_data_csv_str, columns = get_episode_data(dataset, episode_id)
161+
episode_data_csv_str, columns, ignored_columns = get_episode_data(dataset, episode_id)
162162
dataset_info = {
163163
"repo_id": f"{dataset_namespace}/{dataset_name}",
164164
"num_samples": dataset.num_frames
@@ -218,6 +218,7 @@ def show_episode(dataset_namespace, dataset_name, episode_id, dataset=dataset, e
218218
videos_info=videos_info,
219219
episode_data_csv_str=episode_data_csv_str,
220220
columns=columns,
221+
ignored_columns=ignored_columns,
221222
)
222223

223224
app.run(host=host, port=port)
@@ -236,6 +237,14 @@ def get_episode_data(dataset: LeRobotDataset | IterableNamespace, episode_index)
236237
selected_columns = [col for col, ft in dataset.features.items() if ft["dtype"] == "float32"]
237238
selected_columns.remove("timestamp")
238239

240+
ignored_columns = []
241+
for column_name in selected_columns:
242+
shape = dataset.features[column_name]["shape"]
243+
shape_dim = len(shape)
244+
if shape_dim > 1:
245+
selected_columns.remove(column_name)
246+
ignored_columns.append(column_name)
247+
239248
# init header of csv with state and action names
240249
header = ["timestamp"]
241250

@@ -291,7 +300,7 @@ def get_episode_data(dataset: LeRobotDataset | IterableNamespace, episode_index)
291300
csv_writer.writerows(rows)
292301
csv_string = csv_buffer.getvalue()
293302

294-
return csv_string, columns
303+
return csv_string, columns, ignored_columns
295304

296305

297306
def get_episode_video_paths(dataset: LeRobotDataset, ep_index: int) -> list[str]:

lerobot/templates/visualize_dataset_template.html

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -224,49 +224,58 @@ <h1 class="text-xl font-bold mt-4 font-mono">
224224
</p>
225225
</div>
226226

227-
<table class="text-sm border-collapse border border-slate-700" x-show="currentFrameData">
228-
<thead>
229-
<tr>
230-
<th></th>
231-
<template x-for="(_, colIndex) in Array.from({length: columns.length}, (_, index) => index)">
232-
<th class="border border-slate-700">
233-
<div class="flex gap-x-2 justify-between px-2">
234-
<input type="checkbox" :checked="isColumnChecked(colIndex)"
235-
@change="toggleColumn(colIndex)">
236-
<p x-text="`${columns[colIndex].key}`"></p>
237-
</div>
238-
</th>
239-
</template>
240-
</tr>
241-
</thead>
242-
<tbody>
243-
<template x-for="(row, rowIndex) in rows">
244-
<tr class="odd:bg-gray-800 even:bg-gray-900">
245-
<td class="border border-slate-700">
246-
<div class="flex gap-x-2 max-w-64 font-semibold px-1 break-all">
247-
<input type="checkbox" :checked="isRowChecked(rowIndex)"
248-
@change="toggleRow(rowIndex)">
249-
</div>
250-
</td>
251-
<template x-for="(cell, colIndex) in row">
252-
<td x-show="cell" class="border border-slate-700">
253-
<div class="flex gap-x-2 justify-between px-2" :class="{ 'hidden': cell.isNull }">
254-
<div class="flex gap-x-2">
255-
<input type="checkbox" x-model="cell.checked" @change="updateTableValues()">
256-
<span x-text="`${!cell.isNull ? cell.label : null}`"></span>
257-
</div>
258-
<span class="w-14 text-right" x-text="`${!cell.isNull ? (typeof cell.value === 'number' ? cell.value.toFixed(2) : cell.value) : null}`"
259-
:style="`color: ${cell.color}`"></span>
227+
<div>
228+
<table class="text-sm border-collapse border border-slate-700" x-show="currentFrameData">
229+
<thead>
230+
<tr>
231+
<th></th>
232+
<template x-for="(_, colIndex) in Array.from({length: columns.length}, (_, index) => index)">
233+
<th class="border border-slate-700">
234+
<div class="flex gap-x-2 justify-between px-2">
235+
<input type="checkbox" :checked="isColumnChecked(colIndex)"
236+
@change="toggleColumn(colIndex)">
237+
<p x-text="`${columns[colIndex].key}`"></p>
260238
</div>
261-
</td>
239+
</th>
262240
</template>
263241
</tr>
264-
</template>
265-
</tbody>
266-
</table>
242+
</thead>
243+
<tbody>
244+
<template x-for="(row, rowIndex) in rows">
245+
<tr class="odd:bg-gray-800 even:bg-gray-900">
246+
<td class="border border-slate-700">
247+
<div class="flex gap-x-2 max-w-64 font-semibold px-1 break-all">
248+
<input type="checkbox" :checked="isRowChecked(rowIndex)"
249+
@change="toggleRow(rowIndex)">
250+
</div>
251+
</td>
252+
<template x-for="(cell, colIndex) in row">
253+
<td x-show="cell" class="border border-slate-700">
254+
<div class="flex gap-x-2 justify-between px-2" :class="{ 'hidden': cell.isNull }">
255+
<div class="flex gap-x-2">
256+
<input type="checkbox" x-model="cell.checked" @change="updateTableValues()">
257+
<span x-text="`${!cell.isNull ? cell.label : null}`"></span>
258+
</div>
259+
<span class="w-14 text-right" x-text="`${!cell.isNull ? (typeof cell.value === 'number' ? cell.value.toFixed(2) : cell.value) : null}`"
260+
:style="`color: ${cell.color}`"></span>
261+
</div>
262+
</td>
263+
</template>
264+
</tr>
265+
</template>
266+
</tbody>
267+
</table>
268+
269+
<div id="labels" class="hidden">
270+
</div>
267271

268-
<div id="labels" class="hidden">
272+
{% if ignored_columns|length > 0 %}
273+
<div class="m-2 text-orange-700 max-w-96">
274+
Columns {{ ignored_columns }} are NOT shown since the visualizer currently does not support 2D or 3D data.
275+
</div>
276+
{% endif %}
269277
</div>
278+
270279
</div>
271280
</div>
272281

0 commit comments

Comments
 (0)