-
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathdata_collection_and_load.py
More file actions
40 lines (30 loc) · 1.05 KB
/
data_collection_and_load.py
File metadata and controls
40 lines (30 loc) · 1.05 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
import os
import tempfile
import time
import numpy as np
import robodm
if __name__ == "__main__":
path = os.path.join(tempfile.gettempdir(), "test_trajectory.vla")
# Create a trajectory
traj = robodm.Trajectory(path=path, mode="w")
# Add some data
for i in range(10):
traj.add(
"observation/image",
np.random.randint(0, 255, (224, 224, 3), dtype=np.uint8),
)
traj.add("observation/state", np.random.rand(10).astype(np.float32))
traj.add("action", np.random.rand(7).astype(np.float32))
time.sleep(0.1)
# Close the trajectory
traj.close()
print(f"Trajectory saved to {path}")
# Load the trajectory
traj = robodm.Trajectory(path=path, mode="r")
data = traj.load()
print(f"Loaded trajectory with {len(data['observation/image'])} timesteps")
print(f"Image shape: {data['observation/image'][0].shape}")
print(f"State shape: {data['observation/state'][0].shape}")
print(f"Action shape: {data['action'][0].shape}")
# Clean up
os.remove(path)