Skip to content

Commit 67c5baf

Browse files
Added exploration code
1 parent b5acc9b commit 67c5baf

File tree

10 files changed

+95
-1
lines changed

10 files changed

+95
-1
lines changed

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,19 @@
11
# RoboHiveTorchRL-Prototype
2-
Small prototype to see if RoboHive can easily be used with TorchRL
2+
Small prototype to show RoboHive usage with TorchRL.
3+
4+
# Setup
5+
1. ```shell
6+
micromamba create -n robohive -f environment.yaml -y
7+
```
8+
2. ```shell
9+
micromamba activate robohive
10+
```
11+
3. ```shell
12+
robohive_init
13+
```
14+
15+
# Explore Random Environments
16+
1. ```shell
17+
python explore_robohive_envs.py
18+
```
19+
2. Look under the newly created `videos/` for videos of the explored envs. The script explores a few envs by default.

environment.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: robohive
2+
channels:
3+
- conda-forge
4+
dependencies:
5+
- python=3.9
6+
- pip
7+
- pip:
8+
- torchrl==0.5.0
9+
- torch==2.4.1
10+
- torchvision==0.19.1
11+
- torchaudio==2.4.1
12+
- robohive==0.7.0
13+
- gymnasium==0.29.1
14+
- numpy==1.26.4
15+
- av==13.0.0 # Required for torchrl video recorder

explore_robohive_envs.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import torch
2+
from torchrl.collectors.collectors import SyncDataCollector
3+
from torchrl.envs.utils import RandomPolicy
4+
from torchrl.record.loggers.csv import CSVLogger
5+
from torchrl.record import VideoRecorder
6+
from torchrl.envs import RoboHiveEnv
7+
from torchrl.envs.transforms import TransformedEnv
8+
9+
ENV_NAMES_TO_EXPLORE = [
10+
"DKittyStandRandom-v0",
11+
"FetchReachRandom-v0",
12+
"FK1_LdoorOpenRandom-v4",
13+
"FrankaPushRandom-v0",
14+
"MyoHandCupDrink-v0",
15+
"relocate-v1",
16+
"rpFrankaRobotiqData-v0"
17+
]
18+
19+
20+
def main():
21+
print(f"Envs : {RoboHiveEnv.available_envs}")
22+
envs = []
23+
for env_name in ENV_NAMES_TO_EXPLORE:
24+
print(f"Exploring {env_name}...")
25+
26+
video_logger = CSVLogger(exp_name=env_name, log_dir="videos", video_format="mp4", video_fps=30)
27+
recorder = VideoRecorder(logger=video_logger, tag="iteration", skip=2)
28+
29+
env = TransformedEnv(
30+
RoboHiveEnv(env_name=env_name,
31+
from_pixels=True,
32+
pixels_only=True,
33+
from_depths=False,
34+
frame_skip=None)
35+
)
36+
env.append_transform(recorder)
37+
envs.append(env)
38+
39+
policy = RandomPolicy(action_spec=env.action_spec)
40+
41+
device = torch.device('cpu')
42+
43+
collector = SyncDataCollector(
44+
create_env_fn=env,
45+
policy=policy,
46+
total_frames=200,
47+
max_frames_per_traj=50,
48+
frames_per_batch=200,
49+
device=device,
50+
storing_device=device,
51+
)
52+
53+
for _ in collector:
54+
continue
55+
56+
env.transform.dump()
57+
58+
for env in envs:
59+
env.close()
60+
61+
if __name__ == "__main__":
62+
main()
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1.72 MB
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)