-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
141 lines (114 loc) · 5.18 KB
/
main.py
File metadata and controls
141 lines (114 loc) · 5.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env python3
"""
OpenX-Explorer (oxview) - BridgeData V2 Dataset Viewer
Usage:
python main.py data --limit 100
python main.py data --dataset 1 --limit 100 # Select the 1st dataset
python main.py data --no-interactive # Non-interactive mode (auto-select first)
Automatically opens browser with real-time streaming to Rerun Web Viewer.
No rerun-cli installation needed, no manual file dragging required.
"""
import sys
from pathlib import Path
def check_dependencies():
"""Check if required dependencies are installed"""
try:
import tensorflow as tf
tf.config.set_visible_devices([], 'GPU')
print(f"[INFO] TensorFlow version: {tf.__version__}")
except ImportError:
print("[ERROR] TensorFlow not found. Please run: pip install -r requirements.txt")
sys.exit(1)
try:
import rerun as rr
print(f"[INFO] Rerun SDK version: {rr.__version__}")
except ImportError:
print("[ERROR] Rerun SDK not found. Please run: pip install -r requirements.txt")
sys.exit(1)
def print_banner():
"""Print startup banner"""
print("""
============================================================
OpenX-Explorer - BridgeData V2 Edition
Visualize robot datasets without PyTorch.
Just: pip install -r requirements.txt && python main.py data
============================================================
""")
def main():
"""Main function"""
import click
from oxview.loader import BridgeDataLoader, DatasetScanner
from oxview.viewer import RerunApp
@click.command()
@click.argument('data_root', type=click.Path(exists=True, path_type=Path))
@click.option('--limit', default=-1, help='Limit number of frames (-1 = all)')
@click.option('--split', default='train', help='Data split (train/val)')
@click.option('--dataset', '-d', default=None, type=int, help='Dataset index to load (1-based, auto-scan and select if not specified)')
@click.option('--no-interactive', is_flag=True, help='Non-interactive mode (auto-select first dataset)')
def cli(data_root: Path, limit: int, split: str, dataset: int, no_interactive: bool):
"""
BridgeData V2 Dataset Viewer
DATA_ROOT: Root folder containing dataset(s). Can be:
- A folder with multiple dataset subfolders
- A folder containing .tfrecord files directly
"""
print_banner()
data_root = data_root.resolve()
print(f"[INFO] Data root: {data_root}")
# Scan available datasets
scanner = DatasetScanner(data_root)
datasets = scanner.scan()
if not datasets:
print(f"[ERROR] No datasets found in {data_root}")
print("[INFO] Expected folder structure:")
print(" Option 1: data_root/dataset_a/*.tfrecord-*")
print(" Option 2: data_root/*.tfrecord-*")
sys.exit(1)
print(f"[INFO] Found {len(datasets)} dataset(s)")
# Select dataset
if dataset is not None:
# User specified via --dataset argument
if dataset < 1 or dataset > len(datasets):
print(f"[ERROR] Invalid dataset index: {dataset} (valid: 1-{len(datasets)})")
sys.exit(1)
selected = datasets[dataset - 1]
print(f"[INFO] Selected dataset [{dataset}]: {selected['name']}")
else:
# Interactive or non-interactive selection
selected = scanner.select_dataset(datasets, interactive=not no_interactive)
if selected is None:
sys.exit(1)
print(f"[INFO] Selected dataset: {selected['name']}")
dataset_path = selected['path']
# Display available dataset list to Rerun (via text log)
# This will be recorded as static data in the recording
try:
import rerun as rr
ds_list_md = "# Available Datasets\\n\\n"
for i, ds in enumerate(datasets, 1):
marker = "✓ " if ds['name'] == selected['name'] else " "
ds_list_md += f"{marker}[{i}] **{ds['name']}** ({ds['num_files']} files)\\n"
ds_list_md += f"\\n_Currently viewing: **{selected['name']}**_"
# Initialize rerun first to log static information
rr.init("OpenX-Explorer")
rr.log("info/datasets", rr.TextDocument(ds_list_md, media_type="text/markdown"), static=True)
except Exception as e:
# If this fails, it doesn't affect the main flow
print(f"[WARNING] Could not log dataset list: {e}")
# Initialize loader
try:
loader = BridgeDataLoader(dataset_path, split=split)
except ValueError as e:
print(f"[ERROR] {e}")
sys.exit(1)
stats = loader.get_statistics()
print(f"[INFO] Found {stats['num_tfrecord_files']} TFRecord files")
print(f"[INFO] Backend: TensorFlow-CPU")
print()
# Launch viewer (full auto: web streaming + auto browser)
app = RerunApp(loader, limit=limit)
app.run()
cli()
if __name__ == "__main__":
check_dependencies()
main()