facebookresearch / facebookresearch/detectron2
a problem with Deeplab for visualizing semantic segmentation
- Dominant language
- Python
- Stars
- 34.7k
- Forks
- 7.9k
- PR merge metrics
- No merged PRs in 30d
Description
I am trying to implement semantic segmentation on Google Colab by the instructions of the Deeplab project of Detectron2 but when I want to visualize the segments on an image, I face a problem that I cannot solve it.
** "Instructions To Reproduce the Issue and Full Logs":**
`!pip install pyyaml==5.1
!pip install exif==1.3.5
!pip install torch==1.8.1+cu111 torchvision==0.9.1+cu111 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html
!git clone --branch v0.6 https://github.com/facebookresearch/detectron2.git detectron2_repo
!pip install -e detectron2_repo
import detectron2
from detectron2.utils.logger import setup_logger
setup_logger()
import numpy as np
import cv2
import torch
from google.colab.patches import cv2_imshow
from detectron2 import model_zoo
from detectron2.engine import DefaultPredictor
from detectron2.config import get_cfg
from detectron2.utils.visualizer import Visualizer, ColorMode
from detectron2.data import MetadataCatalog
coco_metadata = MetadataCatalog.get("coco_2017_val")
from detectron2.projects import point_rend
from detectron2.projects import deeplab
from detectron2.projects.deeplab import add_deeplab_config
!pip install 'git+https://github.com/facebookresearch/fvcore.git@d39b53de2c1e363e2ceb27d321d403b4bdb2b7a7'
im=cv2.imread("./aachen_000005_000019_leftImg8bit.png")
cv2_imshow(im)
from detectron2.projects.deeplab.build_solver import build_lr_scheduler
from detectron2 import checkpoint
from fvcore.common.checkpoint import Checkpointer
cfg = get_cfg()
deeplab.add_deeplab_config(cfg)
cfg.load_yaml_with_base("detectron2_repo/projects/DeepLab/configs/Cityscapes-SemanticSegmentation/deeplab_v3_plus_R_103_os16_mg124_poly_90k_bs16.yaml")
cfg.merge_from_file("detectron2_repo/projects/DeepLab/configs/Cityscapes-SemanticSegmentation/deeplab_v3_plus_R_103_os16_mg124_poly_90k_bs16.yaml")
cfg.MODEL.WEIGHTS = "https://dl.fbaipublicfiles.com/detectron2/DeepLab/Cityscapes-SemanticSegmentation/deeplab_v3_plus_R_103_os16_mg124_poly_90k_bs16/28054032/model_final_a8a355.pkl"
predictor = DefaultPredictor(cfg)
outputs = predictor(im)
viz1=Visualizer(im[:,:,::-1], MetadataCatalog.get(cfg.DATASETS.TRAIN[0]), scale=1.0, instance_mode=ColorMode.SEGMENTATION)
### output=viz1.draw_sem_seg(outputs["sem_seg"].to("cpu"))
image2 = output.get_image()[:,:,::-1]
cv2_imshow(image2)`
### **The error that I faced is:**
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
in
1 viz1=Visualizer(im[:,:,::-1], MetadataCatalog.get(cfg.DATASETS.TRAIN[0]), scale=1.0, instance_mode=ColorMode.SEGMENTATION)
----> 2 output=viz1.draw_sem_seg(outputs["sem_seg"].to("cpu"))
/content/detectron2_repo/detectron2/utils/visualizer.py in draw_sem_seg(self, sem_seg, area_threshold, alpha)
449 if isinstance(sem_seg, torch.Tensor):
450 sem_seg = sem_seg.numpy()
--> 451 labels, areas = np.unique(sem_seg, return_counts=True)
452 sorted_idxs = np.argsort(-areas).tolist()
453 labels = labels[sorted_idxs]
TypeError: list indices must be integers or slices, not numpy.float32
**Expected behavior:**
I expected that I could draw semantic segmentation on the image.
**Environment**
2023-01-03 21:56:28 URL:https://raw.githubusercontent.com/facebookresearch/detectron2/main/detectron2/utils/collect_env.py [8391/8391] -> "collect_env.py" [1]
---------------------- ----------------------------------------------------------------
sys.platform linux
Python 3.8.16 (default, Dec 7 2022, 01:12:13) [GCC 7.5.0]
numpy 1.21.6
detectron2 failed to import
detectron2._C not built correctly: No module named 'detectron2'
Compiler ($CXX) c++ (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
CUDA compiler Build cuda_11.2.r11.2/compiler.29618528_0
DETECTRON2_ENV_MODULE
PyTorch 1.13.0+cu116 @/usr/local/lib/python3.8/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.14.0+cu116 @/usr/local/lib/python3.8/dist-packages/torchvision
torchvision arch flags 3.5, 5.0, 6.0, 7.0, 7.5, 8.0, 8.6
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.6
- 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.6.1
- Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=11.6, 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 -Werror=non-virtual-dtor -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wunused-local-typedefs -Wno-unused-parameter -Wno-unused-function -Wno-unused-result -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.13.0, USE_CUDA=ON, USE_CUDNN=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=ON, USE_MPI=OFF, USE_NCCL=ON, USE_NNPACK=ON, USE_OPENMP=ON, USE_ROCM=OFF,
Contributor guide
Research direction
Start with detectron2/utils/visualizer.py, especially draw_sem_seg, and reproduce the supplied Colab commands using the stated Detectron2, PyTorch, and NumPy versions. Inspect the type and values of outputs["sem_seg"] alongside the dataset metadata; done means the semantic segmentation visualization completes without the reported TypeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python, pytorch
- Domain
- computer-vision, machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100