open-mmlab / mmocr

OpenMMLab Text Detection, Recognition and Understanding Toolbox
https://mmocr.readthedocs.io/en/dev-1.x/
Apache License 2.0
4.18k stars 735 forks source link

[Bug] KeyError: 'LoadPanopticAnnotations is not in the mmocr::transform registry. Please check whether the value of `LoadPanopticAnnotations` is correct or it was registered as expected #2042

Open ozangungor12 opened 2 months ago

ozangungor12 commented 2 months ago

Prerequisite

Task

I have modified the scripts/configs, or I'm working on my own tasks/models/datasets.

Branch

main branch https://github.com/open-mmlab/mmocr

Environment

sys.platform: linux Python: 3.11.7 (main, Dec 8 2023, 18:56:58) [GCC 11.4.0] CUDA available: True numpy_random_seed: 2147483648 GPU 0,1,2: NVIDIA RTX A6000 CUDA_HOME: /usr/local/cuda NVCC: Cuda compilation tools, release 11.8, V11.8.89 GCC: x86_64-linux-gnu-gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 PyTorch: 2.1.2+cu118 PyTorch compiling details: PyTorch built with:

TorchVision: 0.16.2+cu118 OpenCV: 4.8.0 MMEngine: 0.10.2 MMOCR: 1.0.1+2caab0a

mmcv 2.1.0 mmdet 3.3.0 mmengine 0.10.2 mmocr 1.0.1

Reproduces the problem - code sample

from mmdet.apis import init_detector, inference_detector
from mmocr.apis import MMOCRInferencer

model = init_detector(
          self._config_file,
          checkpoint=self._checkpoint_file, 
          device=self._device
)

result = inference_detector(self._model, input)

self._ocr = MMOCRInferencer(
      det='PANet_CTW', 
      det_weights="weights/mmocr/panet_resnet18_fpem-ffm_600e_ctw1500_20220826_144818-980f32d0.pth", 
      rec='NRTR',
      rec_weights="weights/mmocr/nrtr_resnet31-1by8-1by4_6e_st_mj_20220916_103322-a6a2a123.pth",
      device=device_id,
  )

Reproduces the problem - command or script

git clone https://github.com/open-mmlab/mmocr.git
cd mmocr
pip install -v -e .

Reproduces the problem - error message

File "/usr/local/lib/python3.11/dist-packages/mmdet/apis/inference.py", line 159, in inference_detector
    test_pipeline = Compose(test_pipeline)
                    ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/mmcv/transforms/wrappers.py", line 66, in __init__
    transform = TRANSFORMS.build(transform)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/mmengine/registry/registry.py", line 570, in build
    return self.build_func(cfg, *args, **kwargs, registry=self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/mmengine/registry/build_functions.py", line 100, in build_from_cfg
    raise KeyError(
KeyError: 'LoadPanopticAnnotations is not in the mmocr::transform registry. Please check whether the value of `LoadPanopticAnnotations` is correct or it was registered as expected. More details can be found at https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#import-the-custom-module'

Additional information

My application consists of two steps, detecting an object with Panoptic Segmentation and applying OCR on the detected region.

When I try to use mmdet with mmocr, I get the error above. If I only use mmdet or mmocr, I don't have the error anymore. So if I only run the Panoptic Segmentation or if I run OCR on the full image without the detection step, I don't have any errors. But when I try to run them both in my script, I get the following error. Here are the versions I have in my docker image.

mmcv 2.1.0 mmdet 3.3.0 mmengine 0.10.2 mmocr 1.0.1

ozangungor12 commented 2 months ago

I also realized that the problem does not happen when I first run the mmocr and then the mmdet modules.

Also, there's a warning message displayed after I run the script above.

05/02 15:18:59 - mmengine - WARNING - Failed to search registry with scope "mmocr" in the "function" registry tree. As a workaround, the current "function" registry in "mmengine" is used to build instance. This may cause unexpected failure when running the built modules. Please check whether "mmocr" is a correct scope, or whether the registry is initialized.