likyoo / open-cd

A Change Detection Repo Standing on the Shoulders of Giants
https://arxiv.org/abs/2407.15317
Apache License 2.0
565 stars 78 forks source link

Problems with Inference with existing models #116

Open zhanzf opened 3 months ago

zhanzf commented 3 months ago

https://github.com/likyoo/open-cd/blob/main/docs/inference.md

When I try to test the inference with existing models, I encouter the following problems. I want to know how to resovle this problem. Thanks a lot.

(openmmlab) PS D:\***\open-cd> python
Python 3.8.19 (default, Mar 20 2024, 19:55:45) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from opencd.apis import OpenCDInferencer
>>> inferencer = OpenCDInferencer(model='changer_ex_r18_512x512_40k_levircd.py', weights='ChangerEx_r18-512x512_40k_levircd_20221223_120511.pth', classes=('unchanged', 'changed'), palette=[[0, 0, 0], [255, 255, 255]])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\***\open-cd\opencd\apis\opencd_inferencer.py", line 41, in __init__
    super().__init__(scope=scope, **kwargs)
  File "d:\***\mmsegmentation\mmseg\apis\mmseg_inferencer.py", line 81, in __init__
    super().__init__(
  File "D:\***\miniconda3\envs\openmmlab\lib\site-packages\mmengine\infer\infer.py", line 160, in __init__
    cfg, _weights = self._load_model_from_metafile(model)
  File "D:\***\miniconda3\envs\openmmlab\lib\site-packages\mmengine\infer\infer.py", line 374, in _load_model_from_metafile
    assert self.scope in MODULE2PACKAGE, (
AssertionError: opencd not in {'mmcls': 'mmcls', 'mmdet': 'mmdet', 'mmdet3d': 'mmdet3d', 'mmseg': 'mmsegmentation', 'mmaction': 'mmaction2', 'mmtrack': 'mmtrack', 'mmpose': 'mmpose', 'mmedit': 'mmedit', 'mmocr': 'mmocr', 'mmgen': 'mmgen', 'mmfewshot': 'mmfewshot', 'mmrazor': 'mmrazor', 'mmflow': 'mmflow', 'mmhuman3d': 'mmhuman3d', 'mmrotate': 'mmrotate', 'mmselfsup': 'mmselfsup', 'mmyolo': 'mmyolo', 'mmpretrain': 'mmpretrain', 'mmagic': 'mmagic'}!,please pass a valid scope.
>>>
BarcelonaTong commented 2 months ago

I had the same problem, is it solved now?

zhanzf commented 1 month ago

When @likyoo remind to confirm the path of model correct in #119 . I do the following change to the second command as below:

# Load models into memory
inferencer = OpenCDInferencer(model='changer_r18_levir_workdir/changer_ex_r18_512x512_40k_levircd.py', weights='changer_r18_levir_workdir/best_mIoU_iter_40000.pth', classes=('unchanged', 'changed'), palette=[[0, 0, 0], [255, 255, 255]])

The model and weight path from the train below:

python tools/train.py configs/changer/changer_ex_r18_512x512_40k_levircd.py --work-dir ./changer_r18_levir_workdir

Then the above problem been solved.