Closed Skylark0924 closed 2 years ago
We'd need to add something to habitat to allow it to piggy back off Mayavi's context to keep both in the same process (assuming mayavi is written correctly, of course). You can work around this by using habitat.VectorEnv
(https://github.com/facebookresearch/habitat-lab/blob/master/habitat/core/vector_env.py#L78) with 1 env as that'll run the habitat instance in a separate process
We'd need to add something to habitat to allow it to piggy back off Mayavi's context to keep both in the same process (assuming mayavi is written correctly, of course). You can work around this by using
habitat.VectorEnv
(https://github.com/facebookresearch/habitat-lab/blob/master/habitat/core/vector_env.py#L78) with 1 env as that'll run the habitat instance in a separate process
Awesome!! That's what I need! Here is my solution.
construct_envs
function in env_utils.py
Change the HabitatEnv
class as :
class HabitatEnv:
def __init__(self, config):
self.config = Config(config)
self.config.freeze()
self.scene_path = '/home/skylark/datasets/habitat/data/scene_datasets/mp3d'
# self.eng = NavRLEnv(config=self.config)
self.eng = construct_envs(config=self.config, env_class=NavRLEnv)
self.eng.reset()
env_config = {
'TASK_CONFIG': task_config,
'RL': {
'SUCCESS_REWARD': 2.5,
'SLACK_REWARD': -1e-3,
'REWARD_MEASURE': "distance_to_goal",
'SUCCESS_MEASURE': "spl",
'EPISODE_LENGTH': 300
},
'NUM_PROCESSES': 1,
'SIMULATOR_GPU_ID': 0
}
While it seems a little slow.
I got another problem.
How can I get the property of my Env class if it is packed in a VertorEnv
thread?
For example, I used to get the episode number by calling env.episodes
. But now it is unallowed in a VectorEnv. I just find a method called call_at
, but it's just for the function.
Hi @Skylark0924, Try new call_at function developed by @erikwijmans. Let us know if the issue was resolved.
Sorry for replying late, I finally use the plot3d function instead of mayavi. The solution you provided looks valuable for getting the property of one of the Env class in a VectorEnv thread. Thanks a lot and let's close this issue!
❓ Question
I wrote a script about using RGB & depth images to reconstruct a 3D map and display it using
Mayavi
. However, I met an extremely weird bug. I found that I can not show the Mayavi 3D image and its screenshot after creating a habitat environment.Command
To Reproduce
reconstruction.py
script:from PIL import Image from matplotlib.colors import ListedColormap import matplotlib.pyplot as plt from matplotlib.axes._axes import _log as matplotlib_axes_logger
from Env.habitat_dataset.NavRL_env import NavRLEnv from habitat.config import Config
matplotlib_axes_logger.setLevel('ERROR') np.warnings.filterwarnings('ignore')
def example_config():
task_config = habitat.get_config(
class HabitatEnv: def init(self, config): self.config = Config(config) self.config.freeze() self.scene_path = '/home/skylark/datasets/habitat/data/scene_datasets/mp3d'
def from_depth_to_xyz(depth, cam2world, hfov=90): """[summary]
===>input coordinate (2D)
height | (e.g.480)↓ x (first axis)
===>output coordinate (3D) (openGL coordinates convention) the robot is facing [-z] direction
x <-------o /| / | ↙ | z | ↓ y
########### =================== test ======================= ################# import cv2 from mayavi import mlab
class Recontruction_test(): def init(self):
other related
if name == "main":
For test the display of reconstruction and its screenshot
from typing import Optional, Type
import habitat from habitat import Config, Dataset from habitat_baselines.common.baseline_registry import baseline_registry
for top-down map vis
from habitat.utils.visualizations import maps
def get_env_class(env_name: str) -> Type[habitat.RLEnv]: r"""Return environment class based on name.
@baseline_registry.register_env(name="NavRLEnv") class NavRLEnv(habitat.RLEnv): def init(self, config: Config, dataset: Optional[Dataset] = None): self._rl_config = config.RL self._core_env_config = config.TASK_CONFIG self._reward_measure_name = self._rl_config.REWARD_MEASURE self._success_measure_name = self._rl_config.SUCCESS_MEASURE
2020-12-19 17:12:03.419 ( 35.411s) [ 5EBF740]vtkOpenGLRenderWindow.c:569 ERR| vtkXOpenGLRenderWindow (0x555c3b2b3140): GLEW could not be initialized: Unknown error 2020-12-19 17:12:03.419 ( 35.412s) [ 5EBF740] vtkOpenGLState.cxx:1380 WARN| Hardware does not support the number of textures defined. 2020-12-19 17:12:03.419 ( 35.412s) [ 5EBF740] vtkOpenGLState.cxx:1380 WARN| Hardware does not support the number of textures defined. 2020-12-19 17:12:04.330 ( 36.323s) [ 5EBF740] vtkOpenGLState.cxx:1380 WARN| Hardware does not support the number of textures defined. 2020-12-19 17:12:07.734 ( 39.727s) [ 5EBF740] vtkOpenGLState.cxx:1380 WARN| Hardware does not support the number of textures defined. 2020-12-19 17:12:12.712 ( 44.705s) [ 5EBF740] vtkOpenGLState.cxx:1380 WARN| Hardware does not support the number of textures defined. 2020-12-19 17:12:19.359 ( 51.352s) [ 5EBF740] vtkOpenGLState.cxx:1380 WARN| Hardware does not support the number of textures defined. 2020-12-19 17:12:27.739 ( 59.732s) [ 5EBF740] vtkOpenGLState.cxx:1380 WARN| Hardware does not support the number of textures defined. 2020-12-19 17:12:37.325 ( 69.317s) [ 5EBF740] vtkOpenGLState.cxx:1380 WARN| Hardware does not support the number of textures defined. 2020-12-19 17:12:48.577 ( 80.569s) [ 5EBF740] vtkOpenGLState.cxx:1380 WARN| Hardware does not support the number of textures defined. 2020-12-19 17:13:01.507 ( 93.499s) [ 5EBF740] vtkOpenGLState.cxx:1380 WARN| Hardware does not support the number of textures defined. 2020-12-19 17:13:16.279 ( 108.271s) [ 5EBF740] vtkOpenGLState.cxx:1380 WARN| Hardware does not support the number of textures defined. 2020-12-19 17:13:32.934 ( 124.926s) [ 5EBF740] vtkOpenGLState.cxx:1380 WARN| Hardware does not support the number of textures defined. 2020-12-19 17:13:51.069 ( 143.062s) [ 5EBF740] vtkOpenGLState.cxx:1380 WARN| Hardware does not support the number of textures defined. 2020-12-19 17:14:11.383 ( 163.376s) [ 5EBF740] vtkOpenGLState.cxx:1380 WARN| Hardware does not support the number of textures defined. I1219 17:14:13.038286 19251 PhysicsManager.cpp:33] Deconstructing PhysicsManager I1219 17:14:13.038314 19251 SemanticScene.h:41] Deconstructing SemanticScene I1219 17:14:13.041451 19251 SceneManager.h:25] Deconstructing SceneManager I1219 17:14:13.041463 19251 SceneGraph.h:26] Deconstructing SceneGraph I1219 17:14:13.042546 19251 Sensor.h:81] Deconstructing Sensor I1219 17:14:13.042873 19251 Sensor.h:81] Deconstructing Sensor I1219 17:14:13.043201 19251 Sensor.h:81] Deconstructing Sensor I1219 17:14:13.043211 19251 SceneGraph.h:26] Deconstructing SceneGraph I1219 17:14:13.055938 19251 Renderer.cpp:34] Deconstructing Renderer I1219 17:14:13.055974 19251 WindowlessContext.h:17] Deconstructing WindowlessContext I1219 17:14:14.646723 19251 Simulator.cpp:46] Deconstructing Simulator
Process finished with exit code 0
env = HabitatEnv(env_config)