facebookresearch / facebookresearch/detectron2

visualizer.draw_dataset_dict draws a segmentation mask for the "unlabeled" semantic category

Open
#4,680 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
34.7k
Forks
7.9k
PR merge metrics
No merged PRs in 30d

Description

Using [this guide](https://detectron2.readthedocs.io/en/latest/tutorials/datasets.html), I have registered a custom dataset to detectron2 for using in semantic segmentation of nuclei in histopathologic images. However, [Visualizer](https://detectron2.readthedocs.io/en/latest/modules/utils.html?highlight=draw_sem_seg#module-detectron2.utils.visualizer) shows me an image inversely masked.

## Instructions To Reproduce the Issue:

1. Full runnable code or full changes you made:
```python
def get_patho_dicts(train_dir):
im_paths = Path(f'{train_dir}/Tissue Images').glob('*')
dataset_dicts = []
for idx, im_path in enumerate(im_paths):
height, width = cv2.imread(str(im_path)).shape[:2]
record = {
'file_name': str(im_path),
'image_id': idx,
'height': height,
'width': width,
'sem_seg_file_name': f'{train_dir}/Masks/{im_path.stem}.png',
'segments_info': [ # Though this is related to panoptic segmentation based on doc, I wanted to try it too; which didn't help either.
{
'id': 255,
'category_id': 0,
},
],
}
dataset_dicts.append(record)
return dataset_dicts

for d in ['train']:
DatasetCatalog.register('monuseg1_' + d, lambda d = d: get_patho_dicts('MoNuSeg/train'))
MetadataCatalog.get('monuseg1_' + d).set(stuff_classes = ['nucleus'], stuff_colors=[(0,255,0)])

monuseg_metadata = MetadataCatalog.get("monuseg_train")
```
2. What exact command you run:

```python
dataset_dicts = get_patho_dicts('MoNuSeg/train')

for d in random.sample(dataset_dicts, 1):
print(d)
img = cv2.imread(d['file_name'], -1)
visualizer = Visualizer(img[:, :, ::-1], metadata=monuseg_metadata, scale=1)
out = visualizer.draw_dataset_dict(d)
cv2_imshow(out.get_image())
```

3. __Full logs__ or other relevant observations:

- Ground truth mask:
![image](https://user-images.githubusercontent.com/9105400/204092925-2853ccda-0e72-4b00-9722-06cf0400db09.png)

- Inversely masked image:
![image](https://user-images.githubusercontent.com/9105400/204092945-53ebdfb4-33b8-40f2-971d-028438fe1310.png)

## Expected behavior:

As the mask images are composed of a 1000 x 1000 x 1 array with pixels being either 0 or 255, the image should have been masked with pixels of 255. However, the other pixels are colored.

## Environment:

Paste the output of the following command:
```
---------------------- ----------------------------------------------------------------
sys.platform linux
Python 3.7.15 (default, Oct 12 2022, 19:14:55) [GCC 7.5.0]
numpy 1.21.6
detectron2 0.6 @/usr/local/lib/python3.7/dist-packages/detectron2
Compiler GCC 7.5
CUDA compiler CUDA 11.2
detectron2 arch flags 7.5
DETECTRON2_ENV_MODULE
PyTorch 1.12.1+cu113 @/usr/local/lib/python3.7/dist-packages/torch
PyTorch debug build False
GPU available Yes
GPU 0 Tesla T4 (arch=7.5)
Driver version 460.32.03
CUDA_HOME /usr/local/cuda
Pillow 7.1.2
torchvision 0.13.1+cu113 @/usr/local/lib/python3.7/dist-packages/torchvision
torchvision arch flags 3.5, 5.0, 6.0, 7.0, 7.5, 8.0, 8.6
fvcore 0.1.5.post20221122
iopath 0.1.9
cv2 4.6.0
---------------------- ----------------------------------------------------------------
PyTorch built with:
- GCC 9.3
- C++ Version: 201402
- Intel(R) Math Kernel Library Version 2020.0.0 Product Build 20191122 for Intel(R) 64 architecture applications
- Intel(R) MKL-DNN v2.6.0 (Git Hash 52b5f107dd9cf10910aaa19cb47f3abf9b349815)
- OpenMP 201511 (a.k.a. OpenMP 4.5)
- LAPACK is enabled (usually provided by MKL)
- NNPACK is enabled
- CPU capability usage: AVX2
- CUDA Runtime 11.3
- NVCC architecture flags: -gencode;arch=compute_37,code=sm_37;-gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_70,code=sm_70;-gencode;arch=compute_75,code=sm_75;-gencode;arch=compute_80,code=sm_80;-gencode;arch=compute_86,code=sm_86
- CuDNN 8.3.2 (built against CUDA 11.5)
- Magma 2.5.2
- Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=11.3, CUDNN_VERSION=8.3.2, CXX_COMPILER=/opt/rh/devtoolset-9/root/usr/bin/c++, CXX_FLAGS= -fabi-version=11 -Wno-deprecated -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -fopenmp -DNDEBUG -DUSE_KINETO -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -DEDGE_PROFILER_USE_KINETO -O2 -fPIC -Wno-narrowing -Wall -Wextra -Werror=return-type -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-unused-parameter -Wno-unused-function -Wno-unused-result -Wno-unused-local-typedefs -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-stringop-overflow -Wno-psabi -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Werror=format -Werror=cast-function-type -Wno-stringop-overflow, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, TORCH_VERSION=1.12.1, USE_CUDA=ON, USE_CUDNN=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=OFF, USE_MPI=OFF, USE_NCCL=ON, USE_NNPACK=ON, USE_OPENMP=ON, USE_ROCM=OFF,
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.