isl-org / isl-org/Open3D

use open3d in pytorch Dataset class error

Open
#5,683 5 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
C++
Stars
14k
Forks
2.6k
Avg merge
5d 18h
Merged PRs (30d)
6

Description

### Checklist

- [X] I have searched for [similar issues](https://github.com/isl-org/Open3D/issues).
- [X] For Python issues, I have tested with the [latest development wheel](http://www.open3d.org/docs/latest/getting_started.html#development-version-pip).
- [X] I have checked the [release documentation](http://www.open3d.org/docs/release/) and the [latest documentation](http://www.open3d.org/docs/latest/) (for `master` branch).

### Describe the issue

same as i mentioned before
[https://github.com/isl-org/Open3D/issues/5597](url)
When I try to use open3d to calculate the normal vector in my custom Dataset class I get the following error

- If import open3d in the **_get_normal_** function,The data and the deep learning model cannot be loaded to the gpu at the same time during training. Loading one of them separately or running on the cpu will not report an error
- If open3d is referenced in the python file header of the custom Dataset class, an error will be reported when enumerating train_loader

### Steps to reproduce the bug

```python
this is dataset file:

import numpy as np
from torch.utils.data import Dataset
import open3d as o3d

def get_normal(cld):
# import open3d as o3d
cld = cld.astype(np.float32)
cloud = o3d.geometry.PointCloud()
cloud.points = o3d.utility.Vector3dVector(cld)
cloud.estimate_normals(search_param=o3d.geometry.KDTreeSearchParamKNN(knn=50))
return np.asarray(cloud.normals, dtype=np.float32)

class DATASET(Dataset):
def __init__(self):
some_variable = 0
def __getitem__(self, index):
arr = np.random.randn(100,3)
arr = get_normal(arr)
return arr
def __len__(self):
return 100

this is train file:

from mydataset import DATASET
from torch.utils.data import DataLoader
from torch import nn

class LeNet(nn.Module):
def __init__(self, num_class=10):
super().__init__()
self.features = nn.Sequential(
nn.Conv2d(1, 6, kernel_size=5, padding=2),
nn.AvgPool2d(kernel_size=2, stride=2),
nn.Conv2d(6, 16, kernel_size=5),
nn.ReLU(),
nn.AvgPool2d(kernel_size=2, stride=2),
nn.Flatten()
)
self.classifier = nn.Sequential(
nn.Linear(16 * 5 * 5, 120),
nn.ReLU(),
nn.Linear(120, 84),
nn.Linear(84, 10))
def forward(self, x):
x = self.features(x)
x = self.classfier(x)
return x

# model = LeNet().to("cuda:0")
model = LeNet()

train_set = DATASET()
train_loader = DataLoader(train_set, batch_size=4, shuffle=True, num_workers=2)
for i, data in enumerate(train_loader):
data = data.to("cuda:0")
print(data)
```

### Error message

error1:

Traceback (most recent call last):
File "/home/lht/data/test/train.py", line 33, in
data = data.to("cuda:0")
RuntimeError: CUDA error: unspecified launch failure
CUDA kernel errors might be asynchronously reported at some other API call,so the stacktrace below might be incorrect.
For debugging consider passing CUDA_LAUNCH_BLOCKING=1.

error2:

ERROR: Unexpected segmentation fault encountered in worker.
ERROR: Unexpected segmentation fault encountered in worker.
Traceback (most recent call last):
File "/home/lht/anaconda3/envs/6d-pose/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1163, in _try_get_data
data = self._data_queue.get(timeout=timeout)
File "/home/lht/anaconda3/envs/6d-pose/lib/python3.8/multiprocessing/queues.py", line 107, in get
if not self._poll(timeout):
File "/home/lht/anaconda3/envs/6d-pose/lib/python3.8/multiprocessing/connection.py", line 257, in poll
return self._poll(timeout)
File "/home/lht/anaconda3/envs/6d-pose/lib/python3.8/multiprocessing/connection.py", line 424, in _poll
r = wait([self], timeout)
File "/home/lht/anaconda3/envs/6d-pose/lib/python3.8/multiprocessing/connection.py", line 931, in wait
ready = selector.select(timeout)
File "/home/lht/anaconda3/envs/6d-pose/lib/python3.8/selectors.py", line 415, in select
fd_event_list = self._selector.poll(timeout)
File "/home/lht/anaconda3/envs/6d-pose/lib/python3.8/site-packages/torch/utils/data/_utils/signal_handling.py", line 66, in handler
_error_if_any_worker_fails()
RuntimeError: DataLoader worker (pid 9304) is killed by signal: Segmentation fault.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/lht/data/test/train.py", line 32, in
for i, data in enumerate(train_loader):
File "/home/lht/anaconda3/envs/6d-pose/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 681, in __next__
data = self._next_data()
File "/home/lht/anaconda3/envs/6d-pose/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1359, in _next_data
idx, data = self._get_data()
File "/home/lht/anaconda3/envs/6d-pose/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1325, in _get_data
success, data = self._try_get_data()
File "/home/lht/anaconda3/envs/6d-pose/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1176, in _try_get_data
raise RuntimeError('DataLoader worker (pid(s) {}) exited unexpectedly'.format(pids_str)) from e
RuntimeError: DataLoader worker (pid(s) 9304) exited unexpectedly

Process finished with exit code 1

### Expected behavior

Normal vectors can be handled normally in the dataset class like python-pcl

### Open3D, Python and System information

```markdown
- Operating system: Ubuntu 20.04
- Python version: Python 3.8.13
- Open3D version: 0.16.0
- System architecture: x86
- Is this a remote workstation?: no
- How did you install Open3D?: pip

pytorch 1.12.1+cu116
cuda 11.6
```

### Additional information

_No response_

@ssheorey

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.