isl-org / Open3D

Open3D: A Modern Library for 3D Data Processing
http://www.open3d.org
Other
11.23k stars 2.28k forks source link

Cannot create multiple scenes in parallel #5201

Open hbanzhaf opened 2 years ago

hbanzhaf commented 2 years ago

Checklist

Describe the issue

I am running Open3D 0.15.2 in a fresh Python 3.8 conda environment. My goal is to do some computations in parallel using o3d.t.geometry.RaycastingScene(). Unfortunately, my code gets stuck when I run o3d.t.geometry.TriangleMesh.from_legacy(mesh). Please find an example below. Converting the mesh to a o3d.t.geometry.TriangleMesh in the main-function and passing it to the parallelized function is not an option for me. I am happy to hear about your insights.

Steps to reproduce the bug

import os
import open3d as o3d
from tqdm import tqdm
from tqdm.contrib.concurrent import process_map

def create_scene(path_to_mesh: str) -> None:
    mesh = o3d.io.read_triangle_mesh(path_to_mesh)
    mesh_t = o3d.t.geometry.TriangleMesh.from_legacy(mesh)
    scene = o3d.t.geometry.RaycastingScene()
    scene.add_triangles(mesh_t)

if __name__ == '__main__':
    path_to_mesh = o3d.data.BunnyMesh().path
    args = [path_to_mesh for _ in range(2)]
    process_map(create_scene, args, max_workers=2, desc='Creating scenes')

    # # for loop below succeeds
    # for arg in tqdm(args, 'Creating scenes'):
    #     create_scene(arg)

Open3D, Python and System information

- Operating system: Ubuntu 20.04
- Python version: Python 3.8
- Open3D version: 0.15.2
- How did you install Open3D?: pip
LC117 commented 1 year ago

It seems to run for me with the following change:

import os
import open3d as o3d
from tqdm import tqdm
from tqdm.contrib.concurrent import process_map

import multiprocessing
try:
    multiprocessing.set_start_method('forkserver')
except RuntimeError:  # context has already been set
    pass

def create_scene(path_to_mesh: str) -> None:
    mesh = o3d.io.read_triangle_mesh(path_to_mesh)
    mesh_t = o3d.t.geometry.TriangleMesh.from_legacy(mesh)
    scene = o3d.t.geometry.RaycastingScene()
    scene.add_triangles(mesh_t)

if __name__ == '__main__':
    path_to_mesh = o3d.data.BunnyMesh().path
    args = [path_to_mesh for _ in range(2)]
    process_map(create_scene, args, max_workers=2, desc='Creating scenes')