Hello,
I would like to report an error in the DetInferencer._init_visualizer method (. When the visualizer is not defined in the configuration file, the function fails with the following error:
File ~/anaconda3/lib/python3.11/site-packages/mmdet/apis/det_inferencer.py:99, in DetInferencer.init(self, model, weights, device, scope, palette, show_progress)
97 self.palette = palette
98 init_default_scope(scope)
---> 99 super().init(
100 model=model, weights=weights, device=device, scope=scope)
101 self.model = revert_sync_batchnorm(self.model)
102 self.show_progress = show_progress
AttributeError: 'NoneType' object has no attribute 'dataset_meta'
The error arises because the result of the line super()._init_visualizer() is not checked, which can return None when the visualizer is not defined in the configuration file. In such a situation, the next instruction tries to assign a value to a None object, which causes a crash. To fix this issue, the code should look like this:
Returns:
Visualizer or None: Visualizer initialized with config.
"""
visualizer = super()._init_visualizer(cfg)
if visualizer is not None:
visualizer.dataset_meta = self.model.dataset_meta
return visualizer
With this change, the code checks if the visualizer is None before attempting to assign dataset_meta, preventing the crash.
Environment
sys.platform: win32
Python: 3.11.7 (tags/v3.11.7:fa7a6f2, Dec 4 2023, 19:24:49) [MSC v.1937 64 bit (AMD64)]
CUDA available: False
MUSA available: False
numpy_random_seed: 2147483648
MSVC: Microsoft (R) C/C++ wersja kompilatora optymalizującego 19.40.33811 dla x64
GCC: n/a
PyTorch: 2.1.2+cpu
PyTorch compiling details: PyTorch built with:
C++ Version: 199711
MSVC 192930151
Intel(R) Math Kernel Library Version 2020.0.2 Product Build 20200624 for Intel(R) 64 architecture applications
Bug fix
The error arises because the result of the line super()._init_visualizer() is not checked, which can return None when the visualizer is not defined in the configuration file. In such a situation, the next instruction tries to assign a value to a None object, which causes a crash. To fix this issue, the code should look like this:
Returns:
Visualizer or None: Visualizer initialized with config.
"""
visualizer = super()._init_visualizer(cfg)
if visualizer is not None:
visualizer.dataset_meta = self.model.dataset_meta
return visualizer
Hello, I would like to report an error in the DetInferencer._init_visualizer method (. When the visualizer is not defined in the configuration file, the function fails with the following error: File ~/anaconda3/lib/python3.11/site-packages/mmdet/apis/det_inferencer.py:99, in DetInferencer.init(self, model, weights, device, scope, palette, show_progress) 97 self.palette = palette 98 init_default_scope(scope) ---> 99 super().init( 100 model=model, weights=weights, device=device, scope=scope) 101 self.model = revert_sync_batchnorm(self.model) 102 self.show_progress = show_progress
File ~/anaconda3/lib/python3.11/site-packages/mmengine/infer/infer.py:183, in BaseInferencer.init(self, model, weights, device, scope, show_progress) 181 self.pipeline = self._init_pipeline(cfg) 182 self.collate_fn = self._init_collate(cfg) --> 183 self.visualizer = self._init_visualizer(cfg) 184 self.cfg = cfg 185 self.show_progress = show_progress
File ~/anaconda3/lib/python3.11/site-packages/mmdet/apis/det_inferencer.py:198, in DetInferencer._init_visualizer(self, cfg) 189 """Initialize visualizers. 190 191 Args: (...) 195 Visualizer or None: Visualizer initialized with config. 196 """ 197 visualizer = super()._init_visualizer(cfg) --> 198 visualizer.dataset_meta = self.model.dataset_meta 199 return visualizer
AttributeError: 'NoneType' object has no attribute 'dataset_meta'
The error arises because the result of the line super()._init_visualizer() is not checked, which can return None when the visualizer is not defined in the configuration file. In such a situation, the next instruction tries to assign a value to a None object, which causes a crash. To fix this issue, the code should look like this:
In mmdet/apis/det_inferencer.py
def _init_visualizer(self, cfg): """Initialize visualizers.
Args: cfg (Config): Configuration dictionary.
Returns: Visualizer or None: Visualizer initialized with config. """ visualizer = super()._init_visualizer(cfg) if visualizer is not None: visualizer.dataset_meta = self.model.dataset_meta return visualizer
With this change, the code checks if the visualizer is None before attempting to assign dataset_meta, preventing the crash.
Environment sys.platform: win32 Python: 3.11.7 (tags/v3.11.7:fa7a6f2, Dec 4 2023, 19:24:49) [MSC v.1937 64 bit (AMD64)] CUDA available: False MUSA available: False numpy_random_seed: 2147483648 MSVC: Microsoft (R) C/C++ wersja kompilatora optymalizującego 19.40.33811 dla x64 GCC: n/a PyTorch: 2.1.2+cpu PyTorch compiling details: PyTorch built with:
TorchVision: 0.16.2+cpu OpenCV: 4.8.1 MMEngine: 0.10.4 MMDetection: 3.3.0+ Error traceback If applicable, paste the error trackback here.
Bug fix The error arises because the result of the line super()._init_visualizer() is not checked, which can return None when the visualizer is not defined in the configuration file. In such a situation, the next instruction tries to assign a value to a None object, which causes a crash. To fix this issue, the code should look like this:
In mmdet/apis/det_inferencer.py
def _init_visualizer(self, cfg): """Initialize visualizers.
Args: cfg (Config): Configuration dictionary.
Returns: Visualizer or None: Visualizer initialized with config. """ visualizer = super()._init_visualizer(cfg) if visualizer is not None: visualizer.dataset_meta = self.model.dataset_meta return visualizer