google-research
81 строка · 2.9 Кб
1# coding=utf-8
2# Copyright 2024 The Google Research Authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16"""A collection of MuJoCo-based Reinforcement Learning environments.
17
18The suite provides a similar API to the original dm_control suite.
19Users can configure the distractions on top of the original tasks. The suite is
20targeted for loading environments directly with similar configurations as those
21used in the original paper. Each distraction wrapper can be used independently
22though.
23"""
24import numpy as np25
26DIFFICULTY_SCALE = dict(easy=0.1, medium=0.2, hard=0.3)27DIFFICULTY_NUM_VIDEOS = dict(easy=4, medium=8, hard=None)28DEFAULT_BACKGROUND_PATH = "$HOME/davis/"29
30
31def get_color_kwargs(scale, dynamic):32max_delta = scale33step_std = 0.03 * scale if dynamic else 0.034return dict(max_delta=max_delta, step_std=step_std)35
36
37def get_camera_kwargs(domain_name, scale, dynamic):38assert domain_name in ['reacher', 'cartpole', 'finger', 'cheetah',39'ball_in_cup', 'walker', 'humanoid']40assert scale >= 0.041assert scale <= 1.042return dict(43vertical_delta=np.pi / 2 * scale,44horizontal_delta=np.pi / 2 * scale,45# Limit camera to -90 / 90 degree rolls.46roll_delta=np.pi / 2. * scale,47vel_std=.1 * scale if dynamic else 0.,48max_vel=.4 * scale if dynamic else 0.,49roll_std=np.pi / 300 * scale if dynamic else 0.,50max_roll_vel=np.pi / 50 * scale if dynamic else 0.,51max_zoom_in_percent=.5 * scale,52max_zoom_out_percent=1.5 * scale,53limit_to_upper_quadrant='reacher' not in domain_name,54)55
56
57def get_background_kwargs(domain_name,58num_videos,59dynamic,60dataset_path,61dataset_videos=None,62shuffle=False,63video_alpha=1.0):64assert domain_name in ['reacher', 'cartpole', 'finger', 'cheetah',65'ball_in_cup', 'walker', 'humanoid']66if domain_name == 'reacher':67ground_plane_alpha = 0.068elif domain_name in ['walker', 'cheetah']:69ground_plane_alpha = 1.070else:71ground_plane_alpha = 0.372
73return dict(74num_videos=num_videos,75video_alpha=video_alpha,76ground_plane_alpha=ground_plane_alpha,77dynamic=dynamic,78dataset_path=dataset_path,79dataset_videos=dataset_videos,80shuffle_buffer_size=100 if shuffle else None,81)82