Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Sync from huggingface/lerobot-dataset-visualizer via hub-sync
Browse files
src/app/[org]/[dataset]/[episode]/actions.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
| 1 |
-
"use server";
|
| 2 |
-
|
| 3 |
-
import { getDatasetVersionAndInfo } from "@/utils/versionUtils";
|
| 4 |
-
import type { DatasetMetadata } from "@/utils/parquetUtils";
|
| 5 |
-
import {
|
| 6 |
-
loadAllEpisodeLengthsV3,
|
| 7 |
-
loadAllEpisodeFrameInfo,
|
| 8 |
-
loadCrossEpisodeActionVariance,
|
| 9 |
-
loadEpisodeFlatChartData,
|
| 10 |
-
type EpisodeLengthStats,
|
| 11 |
-
type EpisodeFramesData,
|
| 12 |
-
type CrossEpisodeVarianceData,
|
| 13 |
-
} from "./fetch-data";
|
| 14 |
-
|
| 15 |
-
export async function fetchEpisodeLengthStats(
|
| 16 |
-
org: string,
|
| 17 |
-
dataset: string,
|
| 18 |
-
): Promise<EpisodeLengthStats | null> {
|
| 19 |
-
const repoId = `${org}/${dataset}`;
|
| 20 |
-
const { version, info } = await getDatasetVersionAndInfo(repoId);
|
| 21 |
-
if (version !== "v3.0") return null;
|
| 22 |
-
return loadAllEpisodeLengthsV3(repoId, version, info.fps);
|
| 23 |
-
}
|
| 24 |
-
|
| 25 |
-
export async function fetchEpisodeFrames(
|
| 26 |
-
org: string,
|
| 27 |
-
dataset: string,
|
| 28 |
-
): Promise<EpisodeFramesData> {
|
| 29 |
-
const repoId = `${org}/${dataset}`;
|
| 30 |
-
const { version, info } = await getDatasetVersionAndInfo(repoId);
|
| 31 |
-
return loadAllEpisodeFrameInfo(
|
| 32 |
-
repoId,
|
| 33 |
-
version,
|
| 34 |
-
info as unknown as DatasetMetadata,
|
| 35 |
-
);
|
| 36 |
-
}
|
| 37 |
-
|
| 38 |
-
export async function fetchCrossEpisodeVariance(
|
| 39 |
-
org: string,
|
| 40 |
-
dataset: string,
|
| 41 |
-
): Promise<CrossEpisodeVarianceData | null> {
|
| 42 |
-
const repoId = `${org}/${dataset}`;
|
| 43 |
-
const { version, info } = await getDatasetVersionAndInfo(repoId);
|
| 44 |
-
return loadCrossEpisodeActionVariance(
|
| 45 |
-
repoId,
|
| 46 |
-
version,
|
| 47 |
-
info as unknown as DatasetMetadata,
|
| 48 |
-
info.fps,
|
| 49 |
-
);
|
| 50 |
-
}
|
| 51 |
-
|
| 52 |
-
export async function fetchEpisodeChartData(
|
| 53 |
-
org: string,
|
| 54 |
-
dataset: string,
|
| 55 |
-
episodeId: number,
|
| 56 |
-
): Promise<Record<string, number>[]> {
|
| 57 |
-
const repoId = `${org}/${dataset}`;
|
| 58 |
-
const { version, info } = await getDatasetVersionAndInfo(repoId);
|
| 59 |
-
return loadEpisodeFlatChartData(
|
| 60 |
-
repoId,
|
| 61 |
-
version,
|
| 62 |
-
info as unknown as DatasetMetadata,
|
| 63 |
-
episodeId,
|
| 64 |
-
);
|
| 65 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/app/[org]/[dataset]/[episode]/episode-viewer.tsx
CHANGED
|
@@ -22,7 +22,7 @@ import { hasURDFSupport } from "@/lib/so101-robot";
|
|
| 22 |
import {
|
| 23 |
computeColumnMinMax,
|
| 24 |
getEpisodeDataSafe,
|
| 25 |
-
|
| 26 |
loadAllEpisodeFrameInfo,
|
| 27 |
loadCrossEpisodeActionVariance,
|
| 28 |
type EpisodeData,
|
|
@@ -361,10 +361,7 @@ function EpisodeViewerInner({
|
|
| 361 |
if (org && dataset) {
|
| 362 |
const repoId = `${org}/${dataset}`;
|
| 363 |
getDatasetVersionAndInfo(repoId)
|
| 364 |
-
.then(({
|
| 365 |
-
if (version !== "v3.0") return null;
|
| 366 |
-
return loadAllEpisodeLengthsV3(repoId, version, info.fps);
|
| 367 |
-
})
|
| 368 |
.then((result) => {
|
| 369 |
if (!mountedRef.current) return;
|
| 370 |
setEpisodeLengthStats(result);
|
|
|
|
| 22 |
import {
|
| 23 |
computeColumnMinMax,
|
| 24 |
getEpisodeDataSafe,
|
| 25 |
+
loadAllEpisodeLengths,
|
| 26 |
loadAllEpisodeFrameInfo,
|
| 27 |
loadCrossEpisodeActionVariance,
|
| 28 |
type EpisodeData,
|
|
|
|
| 361 |
if (org && dataset) {
|
| 362 |
const repoId = `${org}/${dataset}`;
|
| 363 |
getDatasetVersionAndInfo(repoId)
|
| 364 |
+
.then(({ info }) => loadAllEpisodeLengths(repoId, info.fps))
|
|
|
|
|
|
|
|
|
|
| 365 |
.then((result) => {
|
| 366 |
if (!mountedRef.current) return;
|
| 367 |
setEpisodeLengthStats(result);
|
src/app/[org]/[dataset]/[episode]/fetch-data.ts
CHANGED
|
@@ -131,7 +131,6 @@ export type DatasetDisplayInfo = {
|
|
| 131 |
robot_type: string | null;
|
| 132 |
codebase_version: string;
|
| 133 |
total_tasks: number;
|
| 134 |
-
dataset_size_mb: number;
|
| 135 |
cameras: CameraInfo[];
|
| 136 |
};
|
| 137 |
|
|
@@ -464,12 +463,6 @@ export async function getEpisodeData(
|
|
| 464 |
robot_type: rawInfo.robot_type ?? null,
|
| 465 |
codebase_version: rawInfo.codebase_version,
|
| 466 |
total_tasks: rawInfo.total_tasks ?? 0,
|
| 467 |
-
dataset_size_mb:
|
| 468 |
-
Math.round(
|
| 469 |
-
((rawInfo.data_files_size_in_mb ?? 0) +
|
| 470 |
-
(rawInfo.video_files_size_in_mb ?? 0)) *
|
| 471 |
-
10,
|
| 472 |
-
) / 10,
|
| 473 |
cameras,
|
| 474 |
};
|
| 475 |
|
|
@@ -502,7 +495,6 @@ async function getEpisodeDataV2(
|
|
| 502 |
robot_type: null,
|
| 503 |
codebase_version: version,
|
| 504 |
total_tasks: 0,
|
| 505 |
-
dataset_size_mb: 0,
|
| 506 |
cameras: [],
|
| 507 |
};
|
| 508 |
|
|
@@ -637,7 +629,6 @@ async function getEpisodeDataV3(
|
|
| 637 |
robot_type: null,
|
| 638 |
codebase_version: version,
|
| 639 |
total_tasks: 0,
|
| 640 |
-
dataset_size_mb: 0,
|
| 641 |
cameras: [],
|
| 642 |
};
|
| 643 |
|
|
@@ -1061,9 +1052,9 @@ export function computeColumnMinMax(
|
|
| 1061 |
* Load all episode lengths from the episodes metadata parquet files (v3.0).
|
| 1062 |
* Returns min/max/mean/median/std and a histogram, or null if unavailable.
|
| 1063 |
*/
|
| 1064 |
-
|
|
|
|
| 1065 |
repoId: string,
|
| 1066 |
-
version: string,
|
| 1067 |
fps: number,
|
| 1068 |
): Promise<EpisodeLengthStats | null> {
|
| 1069 |
try {
|
|
|
|
| 131 |
robot_type: string | null;
|
| 132 |
codebase_version: string;
|
| 133 |
total_tasks: number;
|
|
|
|
| 134 |
cameras: CameraInfo[];
|
| 135 |
};
|
| 136 |
|
|
|
|
| 463 |
robot_type: rawInfo.robot_type ?? null,
|
| 464 |
codebase_version: rawInfo.codebase_version,
|
| 465 |
total_tasks: rawInfo.total_tasks ?? 0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 466 |
cameras,
|
| 467 |
};
|
| 468 |
|
|
|
|
| 495 |
robot_type: null,
|
| 496 |
codebase_version: version,
|
| 497 |
total_tasks: 0,
|
|
|
|
| 498 |
cameras: [],
|
| 499 |
};
|
| 500 |
|
|
|
|
| 629 |
robot_type: null,
|
| 630 |
codebase_version: version,
|
| 631 |
total_tasks: 0,
|
|
|
|
| 632 |
cameras: [],
|
| 633 |
};
|
| 634 |
|
|
|
|
| 1052 |
* Load all episode lengths from the episodes metadata parquet files (v3.0).
|
| 1053 |
* Returns min/max/mean/median/std and a histogram, or null if unavailable.
|
| 1054 |
*/
|
| 1055 |
+
/** Works for every version: the package reads v2's episodes.jsonl and v3's episode index alike. */
|
| 1056 |
+
export async function loadAllEpisodeLengths(
|
| 1057 |
repoId: string,
|
|
|
|
| 1058 |
fps: number,
|
| 1059 |
): Promise<EpisodeLengthStats | null> {
|
| 1060 |
try {
|
src/components/stats-panel.tsx
CHANGED
|
@@ -13,11 +13,17 @@ interface StatsPanelProps {
|
|
| 13 |
}
|
| 14 |
|
| 15 |
function formatTotalTime(totalFrames: number, fps: number): string {
|
| 16 |
-
const totalSec = totalFrames / fps;
|
| 17 |
const hours = Math.floor(totalSec / 3600);
|
| 18 |
const minutes = Math.floor((totalSec % 3600) / 60);
|
|
|
|
| 19 |
if (hours > 0) return `${hours}h ${minutes}m`;
|
| 20 |
-
return `${minutes}m`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
}
|
| 22 |
|
| 23 |
/** SVG bar chart for the episode-length histogram */
|
|
@@ -62,7 +68,7 @@ function EpisodeLengthHistogram({
|
|
| 62 |
y={y}
|
| 63 |
width={barWidth}
|
| 64 |
height={barH}
|
| 65 |
-
className="fill-
|
| 66 |
rx={Math.min(2, barWidth / 4)}
|
| 67 |
/>
|
| 68 |
{bin.count > 0 && barWidth >= 8 && (
|
|
@@ -211,15 +217,22 @@ function StatsPanel({
|
|
| 211 |
<div className="grid grid-cols-3 md:grid-cols-5 gap-4 mb-4">
|
| 212 |
<Card
|
| 213 |
label="Shortest"
|
| 214 |
-
value={
|
| 215 |
/>
|
|
|
|
| 216 |
<Card
|
| 217 |
label="Longest"
|
| 218 |
-
value={
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
/>
|
| 220 |
-
<Card label="Mean" value={`${els.meanEpisodeLength}s`} />
|
| 221 |
-
<Card label="Median" value={`${els.medianEpisodeLength}s`} />
|
| 222 |
-
<Card label="Std Dev" value={`${els.stdEpisodeLength}s`} />
|
| 223 |
</div>
|
| 224 |
</div>
|
| 225 |
|
|
|
|
| 13 |
}
|
| 14 |
|
| 15 |
function formatTotalTime(totalFrames: number, fps: number): string {
|
| 16 |
+
const totalSec = Math.round(totalFrames / fps);
|
| 17 |
const hours = Math.floor(totalSec / 3600);
|
| 18 |
const minutes = Math.floor((totalSec % 3600) / 60);
|
| 19 |
+
const seconds = totalSec % 60;
|
| 20 |
if (hours > 0) return `${hours}h ${minutes}m`;
|
| 21 |
+
if (minutes > 0) return `${minutes}m ${seconds}s`;
|
| 22 |
+
return `${seconds}s`;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
function formatSeconds(value: number | undefined): string {
|
| 26 |
+
return value === undefined ? "–" : `${value.toFixed(2)}s`;
|
| 27 |
}
|
| 28 |
|
| 29 |
/** SVG bar chart for the episode-length histogram */
|
|
|
|
| 68 |
y={y}
|
| 69 |
width={barWidth}
|
| 70 |
height={barH}
|
| 71 |
+
className="fill-cyan-400/70 hover:fill-cyan-300 transition-colors"
|
| 72 |
rx={Math.min(2, barWidth / 4)}
|
| 73 |
/>
|
| 74 |
{bin.count > 0 && barWidth >= 8 && (
|
|
|
|
| 217 |
<div className="grid grid-cols-3 md:grid-cols-5 gap-4 mb-4">
|
| 218 |
<Card
|
| 219 |
label="Shortest"
|
| 220 |
+
value={formatSeconds(els.shortestEpisodes[0]?.lengthSeconds)}
|
| 221 |
/>
|
| 222 |
+
{/* longestEpisodes is sorted longest first. */}
|
| 223 |
<Card
|
| 224 |
label="Longest"
|
| 225 |
+
value={formatSeconds(els.longestEpisodes[0]?.lengthSeconds)}
|
| 226 |
+
/>
|
| 227 |
+
<Card label="Mean" value={formatSeconds(els.meanEpisodeLength)} />
|
| 228 |
+
<Card
|
| 229 |
+
label="Median"
|
| 230 |
+
value={formatSeconds(els.medianEpisodeLength)}
|
| 231 |
+
/>
|
| 232 |
+
<Card
|
| 233 |
+
label="Std Dev"
|
| 234 |
+
value={formatSeconds(els.stdEpisodeLength)}
|
| 235 |
/>
|
|
|
|
|
|
|
|
|
|
| 236 |
</div>
|
| 237 |
</div>
|
| 238 |
|