2024-05-15 18:13:09 +08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
# Copyright 2024 The HuggingFace Inc. team. All rights reserved.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
2024-04-08 22:18:53 +08:00
|
|
|
import importlib
|
2024-04-18 20:47:42 +08:00
|
|
|
|
|
|
|
import gymnasium as gym
|
2024-01-29 20:49:30 +08:00
|
|
|
import pytest
|
Add Aloha env and ACT policy
WIP Aloha env tests pass
Rendering works (fps look fast tho? TODO action bounding is too wide [-1,1])
Update README
Copy past from act repo
Remove download.py add a WIP for Simxarm
Remove download.py add a WIP for Simxarm
Add act yaml (TODO: try train.py)
Training can runs (TODO: eval)
Add tasks without end_effector that are compatible with dataset, Eval can run (TODO: training and pretrained model)
Add AbstractEnv, Refactor AlohaEnv, Add rendering_hook in env, Minor modifications, (TODO: Refactor Pusht and Simxarm)
poetry lock
fix bug in compute_stats for action normalization
fix more bugs in normalization
fix training
fix import
PushtEnv inheriates AbstractEnv, Improve factory Normalization
Add _make_env to EnvAbstract
Add call_rendering_hooks to pusht env
SimxarmEnv inherites from AbstractEnv (NOT TESTED)
Add aloha tests artifacts + update pusht stats
fix image normalization: before env was in [0,1] but dataset in [0,255], and now both in [0,255]
Small fix on simxarm
Add next to obs
Add top camera to Aloha env (TODO: make it compatible with set of cameras)
Add top camera to Aloha env (TODO: make it compatible with set of cameras)
2024-03-08 17:47:39 +08:00
|
|
|
import torch
|
2024-04-05 21:35:20 +08:00
|
|
|
from gymnasium.utils.env_checker import check_env
|
2024-01-29 20:49:30 +08:00
|
|
|
|
2024-04-18 20:47:42 +08:00
|
|
|
import lerobot
|
2024-02-20 22:22:16 +08:00
|
|
|
from lerobot.common.envs.factory import make_env
|
2024-04-06 00:21:07 +08:00
|
|
|
from lerobot.common.envs.utils import preprocess_observation
|
2024-04-18 20:47:42 +08:00
|
|
|
from lerobot.common.utils.utils import init_hydra_config
|
|
|
|
|
|
|
|
from .utils import DEFAULT_CONFIG_PATH, DEVICE, require_env
|
2024-04-06 00:21:07 +08:00
|
|
|
|
2024-04-18 20:47:42 +08:00
|
|
|
OBS_TYPES = ["state", "pixels", "pixels_agent_pos"]
|
2024-02-25 18:50:23 +08:00
|
|
|
|
2024-01-29 20:49:30 +08:00
|
|
|
|
2024-04-18 20:47:42 +08:00
|
|
|
@pytest.mark.parametrize("obs_type", OBS_TYPES)
|
|
|
|
@pytest.mark.parametrize("env_name, env_task", lerobot.env_task_pairs)
|
|
|
|
@require_env
|
|
|
|
def test_env(env_name, env_task, obs_type):
|
|
|
|
if env_name == "aloha" and obs_type == "state":
|
|
|
|
pytest.skip("`state` observations not available for aloha")
|
|
|
|
|
2024-04-08 22:18:53 +08:00
|
|
|
package_name = f"gym_{env_name}"
|
|
|
|
importlib.import_module(package_name)
|
2024-04-18 20:47:42 +08:00
|
|
|
env = gym.make(f"{package_name}/{env_task}", obs_type=obs_type)
|
2024-04-09 17:58:59 +08:00
|
|
|
check_env(env.unwrapped, skip_render_check=True)
|
2024-04-09 16:41:20 +08:00
|
|
|
env.close()
|
2024-02-20 22:22:16 +08:00
|
|
|
|
2024-04-18 20:47:42 +08:00
|
|
|
|
|
|
|
@pytest.mark.parametrize("env_name", lerobot.available_envs)
|
|
|
|
@require_env
|
2024-02-26 01:42:47 +08:00
|
|
|
def test_factory(env_name):
|
2024-03-28 02:33:48 +08:00
|
|
|
cfg = init_hydra_config(
|
|
|
|
DEFAULT_CONFIG_PATH,
|
|
|
|
overrides=[f"env={env_name}", f"device={DEVICE}"],
|
|
|
|
)
|
Add Aloha env and ACT policy
WIP Aloha env tests pass
Rendering works (fps look fast tho? TODO action bounding is too wide [-1,1])
Update README
Copy past from act repo
Remove download.py add a WIP for Simxarm
Remove download.py add a WIP for Simxarm
Add act yaml (TODO: try train.py)
Training can runs (TODO: eval)
Add tasks without end_effector that are compatible with dataset, Eval can run (TODO: training and pretrained model)
Add AbstractEnv, Refactor AlohaEnv, Add rendering_hook in env, Minor modifications, (TODO: Refactor Pusht and Simxarm)
poetry lock
fix bug in compute_stats for action normalization
fix more bugs in normalization
fix training
fix import
PushtEnv inheriates AbstractEnv, Improve factory Normalization
Add _make_env to EnvAbstract
Add call_rendering_hooks to pusht env
SimxarmEnv inherites from AbstractEnv (NOT TESTED)
Add aloha tests artifacts + update pusht stats
fix image normalization: before env was in [0,1] but dataset in [0,255], and now both in [0,255]
Small fix on simxarm
Add next to obs
Add top camera to Aloha env (TODO: make it compatible with set of cameras)
Add top camera to Aloha env (TODO: make it compatible with set of cameras)
2024-03-08 17:47:39 +08:00
|
|
|
|
2024-05-04 00:33:16 +08:00
|
|
|
env = make_env(cfg, n_envs=1)
|
2024-04-08 22:18:53 +08:00
|
|
|
obs, _ = env.reset()
|
2024-04-25 17:47:38 +08:00
|
|
|
obs = preprocess_observation(obs)
|
|
|
|
|
|
|
|
# test image keys are float32 in range [0,1]
|
|
|
|
for key in obs:
|
|
|
|
if "image" not in key:
|
|
|
|
continue
|
2024-04-06 00:21:07 +08:00
|
|
|
img = obs[key]
|
Add Aloha env and ACT policy
WIP Aloha env tests pass
Rendering works (fps look fast tho? TODO action bounding is too wide [-1,1])
Update README
Copy past from act repo
Remove download.py add a WIP for Simxarm
Remove download.py add a WIP for Simxarm
Add act yaml (TODO: try train.py)
Training can runs (TODO: eval)
Add tasks without end_effector that are compatible with dataset, Eval can run (TODO: training and pretrained model)
Add AbstractEnv, Refactor AlohaEnv, Add rendering_hook in env, Minor modifications, (TODO: Refactor Pusht and Simxarm)
poetry lock
fix bug in compute_stats for action normalization
fix more bugs in normalization
fix training
fix import
PushtEnv inheriates AbstractEnv, Improve factory Normalization
Add _make_env to EnvAbstract
Add call_rendering_hooks to pusht env
SimxarmEnv inherites from AbstractEnv (NOT TESTED)
Add aloha tests artifacts + update pusht stats
fix image normalization: before env was in [0,1] but dataset in [0,255], and now both in [0,255]
Small fix on simxarm
Add next to obs
Add top camera to Aloha env (TODO: make it compatible with set of cameras)
Add top camera to Aloha env (TODO: make it compatible with set of cameras)
2024-03-08 17:47:39 +08:00
|
|
|
assert img.dtype == torch.float32
|
|
|
|
# TODO(rcadene): we assume for now that image normalization takes place in the model
|
|
|
|
assert img.max() <= 1.0
|
|
|
|
assert img.min() >= 0.0
|
2024-04-09 16:41:20 +08:00
|
|
|
|
|
|
|
env.close()
|