File size: 4,340 Bytes
7c424de | 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 | ---
license: mit
tags:
- world-model
- jepa
- dino-wm
- robotics
- pusht
library_name: stable-worldmodel
---
# DINO-WM (PreJEPA) β PushT Β· patch tokens + proprio
νλ μμ μΌλ¦° **DINOv2-small** λ°±λ³ΈμΌλ‘ latent μΈμ½λ©νκ³ , causal predictor λ‘
λ€μ latent μ μμΈ‘νλ world model (DINO-WM κ³μ΄, JEPA loss). ν½μ
μ¬κ΅¬μ± μμ.
- backbone: `dinov2_small` (frozen), `pixel_token=patch` β νλ μλΉ 256 ν¨μΉ Γ 384-d
- predictor: `CausalPredictor`, `dim=404` (= pixel 384 + proprio_emb 10 + action_emb 10)
- `history_size=3`, `num_pred=1`, `frameskip=5`
- λΆκ°μ
λ ₯: `proprio`(in_chans=4: agent pos+vel), `action`(in_chans=10 = raw 2 Γ frameskip 5)
- env: `swm/PushT-v1`
## νμΌ
| νμΌ | μ€λͺ
|
|---|---|
| `weights.pt` | λͺ¨λΈ κ°μ€μΉ (epoch 10) |
| `config.json` | ꡬ쑰 (hydra instantiate μ©) |
| `norm_stats.json` | proprio/action ZScore meanΒ·std (eval μ κ·ν 볡μ) |
## μ€μΉ
```bash
pip install stable-worldmodel # λλ μ μ₯μμμ editable μ€μΉ
```
## λ‘λ (public repo β λ΄μ₯ λ‘λ)
```python
import stable_worldmodel as swm
model = swm.wm.utils.load_pretrained("kotmul/dinowm_patch_prop_pusht")
model = model.eval().requires_grad_(False)
model.interpolate_pos_encoding = True
```
`load_pretrained` λ `config.json` + `weights.pt` λ₯Ό `<cache>/checkpoints/` μλλ‘ λ°μ
`instantiate(config)` ν κ°μ€μΉλ₯Ό λ‘λνλ€.
## μ κ·ν (μ€μ)
- **pixels**: ImageNet mean/std μ κ·ν ν 224Γ224
- **proprio / action**: μλ `norm_stats.json` μ ZScore (νμ΅κ³Ό λ°λμ λμΌν΄μΌ ν¨)
```python
import json, numpy as np
from huggingface_hub import hf_hub_download
norm = json.load(open(hf_hub_download("kotmul/dinowm_patch_prop_pusht", "norm_stats.json")))
p_mean, p_std = np.array(norm["proprio"]["mean"][0]), np.array(norm["proprio"]["std"][0])
a_mean, a_std = np.array(norm["action"]["mean"][0]), np.array(norm["action"]["std"][0])
```
## μΆλ‘ β νλ μ μΈμ½λ© & λ€μ μ€ν
μμΈ‘
```python
import torch, numpy as np
import stable_pretraining as spt
from torchvision.transforms import v2 as T
tf = T.Compose([
T.ToImage(), T.ToDtype(torch.float32, scale=True),
T.Normalize(**spt.data.dataset_stats.ImageNet), T.Resize(224),
])
H, FS = model.history_size, 5 # 3 history steps, frameskip 5
# frames_uint8: (H, 224, 224, 3) uint8 β history_size κ°μ μ°μ νλ μ(frameskip κ°κ²©)
# proprio_raw : (H, 4) κ° μ€ν
μ [agent_x, agent_y, agent_vx, agent_vy]
# action_raw : (H, FS*2) κ° model-step μ raw action FSκ° λ¬Άμ ([-1,1]^2 Γ FS)
pixels = torch.stack([tf(im) for im in frames_uint8])[None] # (1,H,3,224,224)
proprio = torch.tensor(((proprio_raw - p_mean) / p_std)[None], dtype=torch.float32) # (1,H,4)
action = ((action_raw.reshape(H, FS, 2) - a_mean) / a_std).reshape(H, FS * 2)
action = torch.tensor(action[None], dtype=torch.float32) # (1,H,10)
with torch.no_grad():
# (a) λ¨μΌ νλ μ μΈμ½λ© (patch latent)
emb_img = model._encode_image(pixels[:, :1]) # (1, 1, 256, 384)
# (b) λ€μ μ€ν
μμΈ‘ (action/proprio λ°μ)
info = {"pixels": pixels, "proprio": proprio, "action": action}
info = model.encode(info, target="emb", is_video=False)
pred = model.predict(info["emb"][:, :H]) # (1, H, 256, 404)
next_latent = pred[:, -1] # μμΈ‘ν λ€μ latent (1, 256, 404)
# 404 = pixel(384) + proprio_emb(10) + action_emb(10).
# planning cost λ±μλ λ³΄ν΅ action ꡬκ°(λ§μ§λ§ 10)μ μ μΈν actionless λΆλΆ μ¬μ©:
actionless = next_latent[..., :394]
```
## Planning / eval μμ μ°κΈ°
`stable-worldmodel` μ planning(eval) μ€ν¬λ¦½νΈλ 체ν¬ν¬μΈνΈ μμ `norm_stats.json` μ
μλμΌλ‘ μ°Ύμ νμ΅ λ μ κ·νλ₯Ό 볡μνλ€(option B). λ°λΌμ μΈ νμΌμ
`<cache>/checkpoints/<run>/` ν ν΄λμ λκ³ `policy` λ₯Ό κ·Έ `weights.pt` λ‘ μ§μ νλ©΄ λλ€:
```
<cache>/checkpoints/dinowm-pusht-patch-prop/
weights.pt
config.json
norm_stats.json # eval μ΄ μ¬κΈ°μ mean/std 볡μ
```
MPC(CEM) planning μ world model μ imagination μΌλ‘ κ΅΄λ € cost λ₯Ό μ΅μννκ³ ,
μ€μ env μμ μ€ννλ€. μμΈν μ§μ
μ μ 리ν¬μ§ν 리μ planning μ€ν¬λ¦½νΈλ₯Ό μ°Έκ³ .
|