facebookresearch / facebookresearch/segment-anything
Using Segmentation model in as pre-processing
- Dominant language
- Jupyter Notebook
- Stars
- 54.9k
- Forks
- 6.4k
- PR merge metrics
- No merged PRs in 30d
Description
Hello,
For pre-processing my images, I use the SAM Large model to work with masks from the original image.
In the _getitem_ of my CustomDataset class, the original image is read then sent to the SAM model, then pre-processed from these masks before being returned.
Here's a pseudocode of the function
```
def __getitem__(self, idx):
img = load_image(idx)
masks = mask_generator.generate(img)
img_preprocessed = preprocess(img, masks)
return img_preprocessed
```
However, when I iterate over loaders I have the following issues
```
RuntimeError: Cannot re-initialize CUDA in forked subprocess. To use CUDA with multiprocessing, you must use the 'spawn' start method
```
I solved the problem by adding the line
```
torch.multiprocessing.set_start_method('spawn')
```
However after this, iteration over my DataLoader only works with num_workers=0. When it is strictly positive, the DataLoader iteration does not converge and does not even show an error.
I have absolutly no idea where it can come from. Please, do you have an idea ?
Thank you
Contributor guide
Research direction
The report only provides pseudocode for CustomDataset.__getitem__ and mentions SAM Large, DataLoader, num_workers, and torch.multiprocessing.set_start_method('spawn'); no repository file or test is identified. Start by reproducing the CUDA multiprocessing behavior with num_workers=0 and then compare it with positive worker counts; done would require a confirmed, documented fix or a clearly scoped repository change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 15/100