Add pretrained notebook
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,3 +1,7 @@
|
|||||||
|
# Apple
|
||||||
|
.DS_Store
|
||||||
|
._.DS_Store
|
||||||
|
|
||||||
# Logging
|
# Logging
|
||||||
logs
|
logs
|
||||||
tmp
|
tmp
|
||||||
|
|||||||
@@ -23,6 +23,13 @@ repos:
|
|||||||
- id: ruff
|
- id: ruff
|
||||||
args: [--fix]
|
args: [--fix]
|
||||||
- id: ruff-format
|
- id: ruff-format
|
||||||
|
- repo: https://github.com/nbQA-dev/nbQA
|
||||||
|
rev: 1.8.4
|
||||||
|
hooks:
|
||||||
|
- id: nbqa-ruff
|
||||||
|
- id: nbqa-pyupgrade
|
||||||
|
args: ["--py310-plus"]
|
||||||
|
- id: nbqa-isort
|
||||||
- repo: https://github.com/python-poetry/poetry
|
- repo: https://github.com/python-poetry/poetry
|
||||||
rev: 1.8.0
|
rev: 1.8.0
|
||||||
hooks:
|
hooks:
|
||||||
|
|||||||
31
examples/notebook_utils.py
Normal file
31
examples/notebook_utils.py
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
from hydra import compose, initialize
|
||||||
|
from hydra.core.global_hydra import GlobalHydra
|
||||||
|
from omegaconf import OmegaConf
|
||||||
|
from omegaconf.dictconfig import DictConfig
|
||||||
|
|
||||||
|
CONFIG_DIR = "../lerobot/configs"
|
||||||
|
DEFAULT_CONFIG = "default"
|
||||||
|
|
||||||
|
|
||||||
|
def config_notebook(
|
||||||
|
policy: str = "diffusion",
|
||||||
|
env: str = "pusht",
|
||||||
|
device: str = "cpu",
|
||||||
|
config_name=DEFAULT_CONFIG,
|
||||||
|
config_path=CONFIG_DIR,
|
||||||
|
print_config: bool = False,
|
||||||
|
) -> DictConfig:
|
||||||
|
GlobalHydra.instance().clear()
|
||||||
|
initialize(config_path=config_path)
|
||||||
|
overrides = [
|
||||||
|
f"env={env}",
|
||||||
|
f"policy={policy}",
|
||||||
|
f"device={device}",
|
||||||
|
]
|
||||||
|
cfg = compose(config_name=config_name, overrides=overrides)
|
||||||
|
if print_config:
|
||||||
|
pprint(OmegaConf.to_container(cfg))
|
||||||
|
|
||||||
|
return cfg
|
||||||
56
examples/pretrained.ipynb
Normal file
56
examples/pretrained.ipynb
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"from pathlib import Path\n",
|
||||||
|
"\n",
|
||||||
|
"from IPython.display import Video\n",
|
||||||
|
"\n",
|
||||||
|
"from examples.notebook_utils import config_notebook\n",
|
||||||
|
"from lerobot.scripts.eval import eval\n",
|
||||||
|
"\n",
|
||||||
|
"OUT_DIR = Path(\"./outputs\")\n",
|
||||||
|
"POLICY = \"act\"\n",
|
||||||
|
"ENV = \"aloha\"\n",
|
||||||
|
"\n",
|
||||||
|
"# setup config\n",
|
||||||
|
"cfg = config_notebook(policy=POLICY, env=ENV, device=\"cpu\", print_config=True)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"eval(cfg, out_dir=OUT_DIR)\n",
|
||||||
|
"Video(OUT_DIR / \"eval\" / \"eval_episode_0.mp4\", embed=True)"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"kernelspec": {
|
||||||
|
"display_name": "lerobot",
|
||||||
|
"language": "python",
|
||||||
|
"name": "python3"
|
||||||
|
},
|
||||||
|
"language_info": {
|
||||||
|
"codemirror_mode": {
|
||||||
|
"name": "ipython",
|
||||||
|
"version": 3
|
||||||
|
},
|
||||||
|
"file_extension": ".py",
|
||||||
|
"mimetype": "text/x-python",
|
||||||
|
"name": "python",
|
||||||
|
"nbconvert_exporter": "python",
|
||||||
|
"pygments_lexer": "ipython3",
|
||||||
|
"version": "3.10.13"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 2
|
||||||
|
}
|
||||||
@@ -145,6 +145,7 @@ def eval(cfg: dict, out_dir=None):
|
|||||||
logging.info("make_env")
|
logging.info("make_env")
|
||||||
env = make_env(cfg, transform=offline_buffer.transform)
|
env = make_env(cfg, transform=offline_buffer.transform)
|
||||||
|
|
||||||
|
# TODO(aliberts, Cadene): fetch pretrained model from HF hub
|
||||||
if cfg.policy.pretrained_model_path:
|
if cfg.policy.pretrained_model_path:
|
||||||
policy = make_policy(cfg)
|
policy = make_policy(cfg)
|
||||||
policy = TensorDictModule(
|
policy = TensorDictModule(
|
||||||
|
|||||||
@@ -25,15 +25,6 @@ def train_cli(cfg: dict):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def train_notebook(out_dir=None, job_name=None, config_name="default", config_path="../configs"):
|
|
||||||
from hydra import compose, initialize
|
|
||||||
|
|
||||||
hydra.core.global_hydra.GlobalHydra.instance().clear()
|
|
||||||
initialize(config_path=config_path)
|
|
||||||
cfg = compose(config_name=config_name)
|
|
||||||
train(cfg, out_dir=out_dir, job_name=job_name)
|
|
||||||
|
|
||||||
|
|
||||||
def log_train_info(logger, info, step, cfg, offline_buffer, is_offline):
|
def log_train_info(logger, info, step, cfg, offline_buffer, is_offline):
|
||||||
loss = info["loss"]
|
loss = info["loss"]
|
||||||
grad_norm = info["grad_norm"]
|
grad_norm = info["grad_norm"]
|
||||||
|
|||||||
1602
poetry.lock
generated
1602
poetry.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -60,6 +60,13 @@ debugpy = "^1.8.1"
|
|||||||
pytest = "^8.1.0"
|
pytest = "^8.1.0"
|
||||||
|
|
||||||
|
|
||||||
|
[tool.poetry.group.examples]
|
||||||
|
optional = true
|
||||||
|
|
||||||
|
|
||||||
|
[tool.poetry.group.examples.dependencies]
|
||||||
|
jupyter = "^1.0.0"
|
||||||
|
|
||||||
[tool.ruff]
|
[tool.ruff]
|
||||||
line-length = 110
|
line-length = 110
|
||||||
target-version = "py310"
|
target-version = "py310"
|
||||||
|
|||||||
Reference in New Issue
Block a user