Spaces:
Sleeping
Sleeping
PH2D matched human<->H1 example pairs; cap clips at training length; GPU timing log
Browse files- .DS_Store +0 -0
- .gitattributes +1 -0
- app.py +22 -8
- examples/first_ph2d_human_pick.png +3 -0
- examples/first_ph2d_human_pour.png +3 -0
- examples/first_ph2d_robot_pick.png +3 -0
- examples/first_ph2d_robot_pour.png +3 -0
- examples/ph2d_human_pick.mp4 +3 -0
- examples/ph2d_human_pour.mp4 +3 -0
- examples/ph2d_robot_pick.mp4 +3 -0
- examples/ph2d_robot_pour.mp4 +3 -0
.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
.gitattributes
CHANGED
|
@@ -144,3 +144,4 @@ examples/out_egoegg_self.mp4 filter=lfs diff=lfs merge=lfs -text
|
|
| 144 |
examples/out_egoknit_to_robot.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 145 |
examples/out_gr1_self.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 146 |
examples/out_gta5_to_west.mp4 filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 144 |
examples/out_egoknit_to_robot.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 145 |
examples/out_gr1_self.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 146 |
examples/out_gta5_to_west.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 147 |
+
examples/*ph2d* filter=lfs diff=lfs merge=lfs -text
|
app.py
CHANGED
|
@@ -12,6 +12,7 @@ from __future__ import annotations
|
|
| 12 |
import functools
|
| 13 |
import sys
|
| 14 |
import tempfile
|
|
|
|
| 15 |
import traceback
|
| 16 |
from pathlib import Path
|
| 17 |
|
|
@@ -40,22 +41,25 @@ MODELS = {
|
|
| 40 |
}
|
| 41 |
ATOMIC_ACTIONS = ["idle", "w", "s", "a", "d", "camera_up", "camera_down", "camera_left", "camera_right"]
|
| 42 |
|
| 43 |
-
# (source video, first frame or None, model key)
|
|
|
|
|
|
|
| 44 |
TRANSFER_EXAMPLES = [
|
|
|
|
|
|
|
|
|
|
| 45 |
("ego_wash_fruit.mp4", None, "ego"),
|
| 46 |
("ego_fry_bread.mp4", None, "ego"),
|
| 47 |
("ego_fry_egg.mp4", None, "ego"),
|
| 48 |
("ego_wash_kitchen_dishes.mp4", None, "ego"),
|
| 49 |
-
("
|
| 50 |
-
("ego_knit_scarf.mp4", "first_gr1.png", "ego"),
|
| 51 |
-
("ego_fry_bread.mp4", "first_gr1.png", "ego"),
|
| 52 |
-
("ego_knit_scarf.mp4", "first_west.png", "mixed"),
|
| 53 |
("gta5.mp4", "first_west.png", "mixed"),
|
| 54 |
]
|
| 55 |
IDM_EXAMPLES = [
|
|
|
|
|
|
|
| 56 |
("ego_wash_fruit.mp4", "ego"),
|
| 57 |
("ego_fry_bread.mp4", "ego"),
|
| 58 |
-
("ego_fry_egg.mp4", "ego"),
|
| 59 |
("ego_knit_scarf.mp4", "ego"),
|
| 60 |
("gr1.mp4", "ego"),
|
| 61 |
("gta5.mp4", "mixed"),
|
|
@@ -96,6 +100,7 @@ def gpu_task(fn):
|
|
| 96 |
@spaces.GPU(duration=120)
|
| 97 |
@functools.wraps(fn)
|
| 98 |
def wrapper(*args):
|
|
|
|
| 99 |
try:
|
| 100 |
return fn(*args)
|
| 101 |
except gr.Error:
|
|
@@ -103,6 +108,8 @@ def gpu_task(fn):
|
|
| 103 |
except Exception as exc:
|
| 104 |
traceback.print_exc()
|
| 105 |
raise gr.Error(f"{type(exc).__name__}: {exc}") from None
|
|
|
|
|
|
|
| 106 |
|
| 107 |
return wrapper
|
| 108 |
|
|
@@ -117,6 +124,13 @@ def video_path(value) -> str:
|
|
| 117 |
return value.video.path if hasattr(value, "video") else value.path
|
| 118 |
|
| 119 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
def read_image(path: str) -> np.ndarray:
|
| 121 |
"""An image file as one uint8 frame ``[1, H, W, 3]``."""
|
| 122 |
return np.asarray(Image.open(path).convert("RGB"), dtype=np.uint8)[None]
|
|
@@ -190,7 +204,7 @@ def run_transfer(source_video, first_frame, model_key, guidance, steps, seed):
|
|
| 190 |
if not source_video:
|
| 191 |
raise gr.Error("Pick or upload a source video first.")
|
| 192 |
pipe = PIPES[model_key]
|
| 193 |
-
source =
|
| 194 |
actions = pipe.encode_source_actions(source)
|
| 195 |
frame = source[:1] if first_frame is None else read_image(first_frame)
|
| 196 |
latents = pipe.generate_latents(
|
|
@@ -209,7 +223,7 @@ def run_idm(source_video, model_key, block, head):
|
|
| 209 |
raise gr.Error("Pick or upload a video first.")
|
| 210 |
pipe = PIPES[model_key]
|
| 211 |
path = video_path(source_video)
|
| 212 |
-
actions = pipe.encode_source_actions(
|
| 213 |
anchors = {name: atomic_vector(name) for name in ATOMIC_ACTIONS} if model_key == "mixed" else None
|
| 214 |
overlay = tmp_path(".mp4")
|
| 215 |
EXTRACTORS[model_key].visualize(Path(path), Path(overlay), block=int(block), head=int(head))
|
|
|
|
| 12 |
import functools
|
| 13 |
import sys
|
| 14 |
import tempfile
|
| 15 |
+
import time
|
| 16 |
import traceback
|
| 17 |
from pathlib import Path
|
| 18 |
|
|
|
|
| 41 |
}
|
| 42 |
ATOMIC_ACTIONS = ["idle", "w", "s", "a", "d", "camera_up", "camera_down", "camera_left", "camera_right"]
|
| 43 |
|
| 44 |
+
# (source video, first frame or None, model key). Cross-embodiment pairs come from
|
| 45 |
+
# PH2D (human and Unitree H1 doing the same task on the same table), so only the
|
| 46 |
+
# embodiment changes between the source video and the first frame.
|
| 47 |
TRANSFER_EXAMPLES = [
|
| 48 |
+
("ph2d_human_pick.mp4", "first_ph2d_robot_pick.png", "ego"),
|
| 49 |
+
("ph2d_human_pour.mp4", "first_ph2d_robot_pour.png", "ego"),
|
| 50 |
+
("ph2d_robot_pick.mp4", "first_ph2d_human_pick.png", "ego"),
|
| 51 |
("ego_wash_fruit.mp4", None, "ego"),
|
| 52 |
("ego_fry_bread.mp4", None, "ego"),
|
| 53 |
("ego_fry_egg.mp4", None, "ego"),
|
| 54 |
("ego_wash_kitchen_dishes.mp4", None, "ego"),
|
| 55 |
+
("gr1.mp4", None, "ego"),
|
|
|
|
|
|
|
|
|
|
| 56 |
("gta5.mp4", "first_west.png", "mixed"),
|
| 57 |
]
|
| 58 |
IDM_EXAMPLES = [
|
| 59 |
+
("ph2d_human_pick.mp4", "ego"),
|
| 60 |
+
("ph2d_robot_pick.mp4", "ego"),
|
| 61 |
("ego_wash_fruit.mp4", "ego"),
|
| 62 |
("ego_fry_bread.mp4", "ego"),
|
|
|
|
| 63 |
("ego_knit_scarf.mp4", "ego"),
|
| 64 |
("gr1.mp4", "ego"),
|
| 65 |
("gta5.mp4", "mixed"),
|
|
|
|
| 100 |
@spaces.GPU(duration=120)
|
| 101 |
@functools.wraps(fn)
|
| 102 |
def wrapper(*args):
|
| 103 |
+
start = time.perf_counter()
|
| 104 |
try:
|
| 105 |
return fn(*args)
|
| 106 |
except gr.Error:
|
|
|
|
| 108 |
except Exception as exc:
|
| 109 |
traceback.print_exc()
|
| 110 |
raise gr.Error(f"{type(exc).__name__}: {exc}") from None
|
| 111 |
+
finally:
|
| 112 |
+
print(f"[{fn.__name__}] {time.perf_counter() - start:.1f}s on {torch.cuda.get_device_name()}", flush=True)
|
| 113 |
|
| 114 |
return wrapper
|
| 115 |
|
|
|
|
| 124 |
return value.video.path if hasattr(value, "video") else value.path
|
| 125 |
|
| 126 |
|
| 127 |
+
def read_source(pipe, path: str) -> np.ndarray:
|
| 128 |
+
"""The source video at the model's fps, capped at the clip length its world model was trained on.
|
| 129 |
+
|
| 130 |
+
Longer clips only extrapolate (and cost quadratically more attention)."""
|
| 131 |
+
return load_source_video(path, pipe.fps, max_frames=pipe.num_rgb_frames)
|
| 132 |
+
|
| 133 |
+
|
| 134 |
def read_image(path: str) -> np.ndarray:
|
| 135 |
"""An image file as one uint8 frame ``[1, H, W, 3]``."""
|
| 136 |
return np.asarray(Image.open(path).convert("RGB"), dtype=np.uint8)[None]
|
|
|
|
| 204 |
if not source_video:
|
| 205 |
raise gr.Error("Pick or upload a source video first.")
|
| 206 |
pipe = PIPES[model_key]
|
| 207 |
+
source = read_source(pipe, video_path(source_video))
|
| 208 |
actions = pipe.encode_source_actions(source)
|
| 209 |
frame = source[:1] if first_frame is None else read_image(first_frame)
|
| 210 |
latents = pipe.generate_latents(
|
|
|
|
| 223 |
raise gr.Error("Pick or upload a video first.")
|
| 224 |
pipe = PIPES[model_key]
|
| 225 |
path = video_path(source_video)
|
| 226 |
+
actions = pipe.encode_source_actions(read_source(pipe, path))
|
| 227 |
anchors = {name: atomic_vector(name) for name in ATOMIC_ACTIONS} if model_key == "mixed" else None
|
| 228 |
overlay = tmp_path(".mp4")
|
| 229 |
EXTRACTORS[model_key].visualize(Path(path), Path(overlay), block=int(block), head=int(head))
|
examples/first_ph2d_human_pick.png
ADDED
|
Git LFS Details
|
examples/first_ph2d_human_pour.png
ADDED
|
Git LFS Details
|
examples/first_ph2d_robot_pick.png
ADDED
|
Git LFS Details
|
examples/first_ph2d_robot_pour.png
ADDED
|
Git LFS Details
|
examples/ph2d_human_pick.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0238a5b551365e56cd41f4cff67df72bce232b0c32569bb896b879eb68932e17
|
| 3 |
+
size 400930
|
examples/ph2d_human_pour.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:de64f39e6290bb2ce3b4d5ffdd4e0cfe827338a2a12181d4f2efb8caaa07e504
|
| 3 |
+
size 719097
|
examples/ph2d_robot_pick.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a18238c9a6722947d34de1bb5014c5426d76539557f48a08b8ed7e1f02cc0fd5
|
| 3 |
+
size 850558
|
examples/ph2d_robot_pour.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:906164e7d98b55aa75874664a8835e5d3b95725464e930627a2885649f7875db
|
| 3 |
+
size 682754
|