本文整理汇总了Python中mujoco_py.load_model_from_path方法的典型用法代码示例。如果您正苦于以下问题:Python mujoco_py.load_model_from_path方法的具体用法?Python mujoco_py.load_model_from_path怎么用?Python mujoco_py.load_model_from_path使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mujoco_py
的用法示例。
在下文中一共展示了mujoco_py.load_model_from_path方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import load_model_from_path [as 别名]
def __init__(self, model_path, _hp):
self._frame_height = _hp.viewer_image_height
self._frame_width = _hp.viewer_image_width
self._model_path = model_path
self.sim = MjSim(load_model_from_path(self._model_path))
self._base_adim, self._base_sdim = None, None #state/action dimension of Mujoco control
self._adim, self._sdim = None, None #state/action dimension presented to agent
self.num_objects, self._n_joints = None, None
self._goal_obj_pose = None
self._goaldistances = []
self._ncam = _hp.ncam
self.cameras = ['cam{}'.format(i) for i in range(self._ncam)]
self._last_obs = None
self._hp = _hp
self._save_buffer = []
示例2: _load_simulation
# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import load_model_from_path [as 别名]
def _load_simulation(self, model_handle: Any) -> Any:
"""Loads the simulation from the given model handle.
Args:
model_handle: Path to the Mujoco XML file to load.
Returns:
A mujoco_py MjSim object.
"""
if isinstance(model_handle, str):
if not os.path.isfile(model_handle):
raise ValueError(
'[MjPySimScene] Invalid model file path: {}'.format(
model_handle))
model = mujoco_py.load_model_from_path(model_handle)
sim = mujoco_py.MjSim(model)
else:
raise NotImplementedError(model_handle)
return sim
示例3: __init__
# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import load_model_from_path [as 别名]
def __init__(self, model_path, frame_skip):
if not path.exists(model_path):
raise IOError("File %s does not exist" % model_path)
self.frame_skip = frame_skip
self.model = mujoco_py.load_model_from_path(model_path)
self.sim = mujoco_py.MjSim(self.model)
self.data = self.sim.data
self.viewer = None
self._viewers = {}
self.metadata = {
'render.modes': ['human'],
'video.frames_per_second': int(np.round(1.0 / self.dt))
}
self.init_qpos = self.sim.data.qpos.ravel().copy()
self.init_qvel = self.sim.data.qvel.ravel().copy()
self.seed()
示例4: env_init
# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import load_model_from_path [as 别名]
def env_init(render = False):
camera_name = 'camera_main'
model = load_model_from_path(JACO_MODEL_PATH)
sim = MjSim(model)
control_scheme = CustomControlScheme(sim.data.ctrl)
if render:
viewer = CustomMjViewer(sim,
control_scheme,
camera_name=camera_name)
else:
viewer= False
return model,sim,control_scheme,viewer
示例5: __init__
# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import load_model_from_path [as 别名]
def __init__(self, model_path, initial_qpos, n_actions, n_substeps):
if model_path.startswith('/'):
fullpath = model_path
else:
fullpath = os.path.join(os.path.dirname(__file__), 'assets', model_path)
if not os.path.exists(fullpath):
raise IOError('File {} does not exist'.format(fullpath))
model = mujoco_py.load_model_from_path(fullpath)
self.sim = mujoco_py.MjSim(model, nsubsteps=n_substeps)
self.viewer = None
self.metadata = {
'render.modes': ['human', 'rgb_array'],
'video.frames_per_second': int(np.round(1.0 / self.dt))
}
self.seed()
self._env_setup(initial_qpos=initial_qpos)
self.initial_state = copy.deepcopy(self.sim.get_state())
self.goal = self._sample_goal()
obs = self._get_obs()
self.action_space = spaces.Box(-1., 1., shape=(n_actions,), dtype='float32')
self.observation_space = spaces.Dict(dict(
desired_goal=spaces.Box(-np.inf, np.inf, shape=obs['achieved_goal'].shape, dtype='float32'),
achieved_goal=spaces.Box(-np.inf, np.inf, shape=obs['achieved_goal'].shape, dtype='float32'),
observation=spaces.Box(-np.inf, np.inf, shape=obs['observation'].shape, dtype='float32'),
))
示例6: __init__
# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import load_model_from_path [as 别名]
def __init__(self, model_path, frame_skip):
if model_path.startswith("/"):
fullpath = model_path
else:
fullpath = os.path.join(os.path.dirname(__file__), "assets", model_path)
if not path.exists(fullpath):
raise IOError("File %s does not exist" % fullpath)
self.frame_skip = frame_skip
self.model = mujoco_py.load_model_from_path(fullpath)
self.sim = mujoco_py.MjSim(self.model)
self.data = self.sim.data
self.viewer = None
self.metadata = {
'render.modes': ['human', 'rgb_array'],
'video.frames_per_second': int(np.round(1.0 / self.dt))
}
self.init_qpos = self.sim.data.qpos.ravel().copy()
self.init_qvel = self.sim.data.qvel.ravel().copy()
observation, _reward, done, _info = self.step(np.zeros(self.model.nu))
assert not done
self.obs_dim = observation.size
bounds = self.model.actuator_ctrlrange.copy()
low = bounds[:, 0]
high = bounds[:, 1]
self.action_space = spaces.Box(low=low, high=high)
high = np.inf*np.ones(self.obs_dim)
low = -high
self.observation_space = spaces.Box(low, high)
self.seed()
示例7: __init__
# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import load_model_from_path [as 别名]
def __init__(self, action_noise=0.0, file_path=None, template_args=None):
# compile template
if file_path is None:
if self.__class__.FILE is None:
raise NotImplementedError("Mujoco file not specified")
file_path = osp.join(MODEL_DIR, self.__class__.FILE)
if file_path.endswith(".mako"):
lookup = mako.lookup.TemplateLookup(directories=[MODEL_DIR])
with open(file_path) as template_file:
template = mako.template.Template(
template_file.read(), lookup=lookup)
content = template.render(
opts=template_args if template_args is not None else {}, )
tmp_f, file_path = tempfile.mkstemp(suffix=".xml", text=True)
with open(file_path, 'w') as f:
f.write(content)
self.model = load_model_from_path(file_path)
os.close(tmp_f)
else:
self.model = load_model_from_path(file_path)
self.sim = MjSim(self.model)
self.data = self.sim.data
self.viewer = None
self.render_width = 512
self.render_height = 512
self.render_camera = None
self.init_qpos = self.sim.data.qpos
self.init_qvel = self.sim.data.qvel
self.init_qacc = self.sim.data.qacc
self.init_ctrl = self.sim.data.ctrl
self.qpos_dim = self.init_qpos.size
self.qvel_dim = self.init_qvel.size
self.ctrl_dim = self.init_ctrl.size
self.action_noise = action_noise
self.frame_skip = 1
self.dcom = None
self.current_com = None
self.reset()
super().__init__()
示例8: __init__
# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import load_model_from_path [as 别名]
def __init__(self, model_path, frame_skip):
if model_path.startswith("/"):
fullpath = model_path
else:
fullpath = os.path.join(os.path.dirname(__file__), "assets", model_path)
if not path.exists(fullpath):
raise IOError("File %s does not exist" % fullpath)
self.frame_skip = frame_skip
self.model = mujoco_py.load_model_from_path(fullpath)
self.sim = mujoco_py.MjSim(self.model)
self.data = self.sim.data
self.viewer = None
self._viewers = {}
self.metadata = {
'render.modes': ['human', 'rgb_array', 'depth_array'],
'video.frames_per_second': int(np.round(1.0 / self.dt))
}
self.init_qpos = self.sim.data.qpos.ravel().copy()
self.init_qvel = self.sim.data.qvel.ravel().copy()
observation, _reward, done, _info = self.step(np.zeros(self.model.nu))
assert not done
self.obs_dim = observation.size
bounds = self.model.actuator_ctrlrange.copy()
low = bounds[:, 0]
high = bounds[:, 1]
self.action_space = spaces.Box(low=low, high=high, dtype=np.float32)
high = np.inf*np.ones(self.obs_dim)
low = -high
self.observation_space = spaces.Box(low, high, dtype=np.float32)
self.seed()
示例9: __init__
# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import load_model_from_path [as 别名]
def __init__(self, model_path, initial_qpos, n_actions, n_substeps):
if model_path.startswith('/'):
fullpath = model_path
else:
fullpath = os.path.join(os.path.dirname(__file__), 'assets', model_path)
if not os.path.exists(fullpath):
raise IOError('File {} does not exist'.format(fullpath))
model = mujoco_py.load_model_from_path(fullpath)
self.sim = mujoco_py.MjSim(model, nsubsteps=n_substeps)
self.viewer = None
self.metadata = {
'render.modes': ['human', 'rgb_array'],
'video.frames_per_second': int(np.round(1.0 / self.dt))
}
self.seed()
self._env_setup(initial_qpos=initial_qpos)
self.initial_state = copy.deepcopy(self.sim.get_state())
self.goal = self._sample_goal()
obs = self._get_obs()
# self.action_space = spaces.Box(-1., 1., shape=(n_actions,), dtype='float32')
self.action_space = spaces.Box(-1., 1., shape=(2,), dtype='float32')
self.observation_space = spaces.Box(-np.inf, np.inf, shape=obs.shape, dtype=np.float32)
示例10: __init__
# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import load_model_from_path [as 别名]
def __init__(self, model_path, initial_qpos, n_actions, n_substeps, terminate_on_success=False):
if model_path.startswith('/'):
fullpath = model_path
else:
fullpath = os.path.join(os.path.dirname(__file__), 'assets', model_path)
if not os.path.exists(fullpath):
raise IOError('File {} does not exist'.format(fullpath))
model = mujoco_py.load_model_from_path(fullpath)
self.sim = mujoco_py.MjSim(model, nsubsteps=n_substeps)
self.viewer = None
self.metadata = {
'render.modes': ['human', 'rgb_array'],
'video.frames_per_second': int(np.round(1.0 / self.dt))
}
self.seed()
self._env_setup(initial_qpos=initial_qpos)
self.initial_state = copy.deepcopy(self.sim.get_state())
obs = self.reset()
self.action_space = spaces.Box(-1., 1., shape=(n_actions,), dtype='float32')
self.observation_space = spaces.Dict(dict(
obs=spaces.Box(-np.inf, np.inf, shape=obs['obs'].shape, dtype='float32'),
obs_task_params=spaces.Box(-np.inf, np.inf, shape=obs['obs_task_params'].shape, dtype='float32'),
))
self.terminate_on_success = terminate_on_success
示例11: __init__
# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import load_model_from_path [as 别名]
def __init__(self, model_path, frame_skip, rgb_rendering_tracking=True):
if model_path.startswith("/"):
fullpath = model_path
else:
fullpath = os.path.join(os.path.dirname(__file__), "assets", model_path)
if not path.exists(fullpath):
raise IOError("File %s does not exist" % fullpath)
self.frame_skip = frame_skip
self.model = mujoco_py.load_model_from_path(fullpath)
self.sim = mujoco_py.MjSim(self.model)
self.data = self.sim.data
self.viewer = None
self.rgb_rendering_tracking = rgb_rendering_tracking
self._viewers = {}
self.metadata = {
'render.modes': ['human', 'rgb_array', 'depth_array'],
'video.frames_per_second': int(np.round(1.0 / self.dt))
}
self.init_qpos = self.sim.data.qpos.ravel().copy()
self.init_qvel = self.sim.data.qvel.ravel().copy()
observation, _reward, done, _info = self.step(np.zeros(self.model.nu))
assert not done
# self.obs_dim = observation.size
bounds = self.model.actuator_ctrlrange.copy()
low = bounds[:, 0]
high = bounds[:, 1]
self.action_space = spaces.Box(low=low, high=high, dtype=np.float32)
# high = np.inf*np.ones(self.obs_dim)
# low = -high
# self.observation_space = spaces.Box(low, high, dtype=np.float32)
self.observation_space = spaces.Dict(dict(
image=spaces.Box(-np.inf, np.inf, shape=observation['image'].shape, dtype='float32'),
X=spaces.Box(-np.inf, np.inf, shape=observation['X'].shape, dtype='float32'),
))
self.seed()
示例12: __init__
# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import load_model_from_path [as 别名]
def __init__(self, model_path, frame_skip):
if model_path.startswith("/"):
fullpath = model_path
else:
fullpath = os.path.join(os.path.dirname(__file__), "assets", model_path)
if not path.exists(fullpath):
raise IOError("File %s does not exist" % fullpath)
self.frame_skip = frame_skip
self.model = mujoco_py.load_model_from_path(fullpath)
self.sim = mujoco_py.MjSim(self.model)
self.data = self.sim.data
self.viewer = None
self._viewers = {}
self.metadata = {
'render.modes': ['human', 'rgb_array', 'depth_array'],
'video.frames_per_second': int(np.round(1.0 / self.dt))
}
self.init_qpos = self.sim.data.qpos.ravel().copy()
self.init_qvel = self.sim.data.qvel.ravel().copy()
observation, _reward, done, _info = self.step(np.zeros(self.model.nu))
assert not done
bounds = self.model.actuator_ctrlrange.copy()
low = bounds[:, 0]
high = bounds[:, 1]
self.action_space = spaces.Box(low=low, high=high, dtype=np.float32)
self.observation_space = spaces.Dict(dict(
obs=spaces.Box(-np.inf, np.inf, shape=observation['obs'].shape, dtype='float32'),
obs_task_params=spaces.Box(-np.inf, np.inf, shape=observation['obs_task_params'].shape, dtype='float32'),
))
self.seed()
示例13: __init__
# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import load_model_from_path [as 别名]
def __init__(self, model_path, frame_skip):
if model_path.startswith("/"):
fullpath = model_path
else:
fullpath = os.path.join(os.path.dirname(__file__), "assets", model_path)
if not path.exists(fullpath):
raise IOError("File %s does not exist" % fullpath)
self.frame_skip = frame_skip
self.model = load_model_from_path(fullpath)
self.sim = MjSim(self.model)
self.data = self.sim.data
self.metadata = {
'render.modes': ['human', 'rgb_array'],
'video.frames_per_second': int(np.round(1.0 / self.dt))
}
self.mujoco_render_frames = False
self.init_qpos = self.data.qpos.ravel().copy()
self.init_qvel = self.data.qvel.ravel().copy()
try:
observation, _reward, done, _info = self.step(np.zeros(self.model.nu))
except NotImplementedError:
observation, _reward, done, _info = self._step(np.zeros(self.model.nu))
assert not done
self.obs_dim = np.sum([o.size for o in observation]) if type(observation) is tuple else observation.size
bounds = self.model.actuator_ctrlrange.copy()
low = bounds[:, 0]
high = bounds[:, 1]
self.action_space = spaces.Box(low, high, dtype=np.float32)
high = np.inf*np.ones(self.obs_dim)
low = -high
self.observation_space = spaces.Box(low, high, dtype=np.float32)
self.seed()
示例14: __init__
# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import load_model_from_path [as 别名]
def __init__(self, model_path, initial_qpos, n_actions, n_substeps):
if model_path.startswith('/'):
fullpath = model_path
else:
fullpath = os.path.join(os.path.dirname(__file__), 'assets', model_path)
if not os.path.exists(fullpath):
raise IOError('File {} does not exist'.format(fullpath))
model = mujoco_py.load_model_from_path(fullpath)
self.sim = mujoco_py.MjSim(model, nsubsteps=n_substeps)
self.viewer = None
self._viewers = {}
self.metadata = {
'render.modes': ['human', 'rgb_array'],
'video.frames_per_second': int(np.round(1.0 / self.dt))
}
self.seed()
self._env_setup(initial_qpos=initial_qpos)
self.initial_state = copy.deepcopy(self.sim.get_state())
self.goal = self._sample_goal()
obs = self._get_obs()
self.action_space = spaces.Box(-1., 1., shape=(n_actions,), dtype='float32')
self.observation_space = spaces.Dict(dict(
desired_goal=spaces.Box(-np.inf, np.inf, shape=obs['achieved_goal'].shape, dtype='float32'),
achieved_goal=spaces.Box(-np.inf, np.inf, shape=obs['achieved_goal'].shape, dtype='float32'),
observation=spaces.Box(-np.inf, np.inf, shape=obs['observation'].shape, dtype='float32'),
))
示例15: __init__
# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import load_model_from_path [as 别名]
def __init__(self, model_path, frame_skip):
if model_path.startswith("/"):
fullpath = model_path
else:
fullpath = os.path.join(os.path.dirname(__file__), "assets", model_path)
if not path.exists(fullpath):
raise IOError("File %s does not exist" % fullpath)
self.frame_skip = frame_skip
self.model = mujoco_py.load_model_from_path(fullpath)
self.sim = mujoco_py.MjSim(self.model)
self.data = self.sim.data
self.viewer = None
self._viewers = {}
self.metadata = {
'render.modes': ['human', 'rgb_array', 'depth_array'],
'video.frames_per_second': int(np.round(1.0 / self.dt))
}
self.init_qpos = self.sim.data.qpos.ravel().copy()
self.init_qvel = self.sim.data.qvel.ravel().copy()
self._set_action_space()
action = self.action_space.sample()
observation, _reward, done, _info = self.step(action)
assert not done
self._set_observation_space(observation)
self.seed()