Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] “please pass a valid scope. ” in the thirdpart project #1581

Open
2 tasks done
zhanzf opened this issue Oct 4, 2024 · 1 comment
Open
2 tasks done

[Bug] “please pass a valid scope. ” in the thirdpart project #1581

zhanzf opened this issue Oct 4, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@zhanzf
Copy link

zhanzf commented Oct 4, 2024

Prerequisite

Environment

OrderedDict([('sys.platform', 'win32'), ('Python', '3.8.19 (default, Mar 20 2024, 19:55:45) [MSC v.1916 64 bit (AMD64)]'), ('CUDA available', True), ('MUSA available', False), ('numpy_random_seed', 2147483648), ('GPU 0', 'NVIDIA GeForce RTX 3070 Ti Laptop GPU'), ('CUDA_HOME', 'D:\Program Files\CUDA118\Dev'), ('NVCC', 'Cuda compilation tools, release 11.8, V11.8.89'), ('MSVC', '用于 x64 的 Microsoft (R) C/C++ 优化编译器 19.36.32532 版'), ('GCC', 'n/a'), ('PyTorch', '1.13.1+cu117'), ('PyTorch compiling details', 'PyTorch built with:\n - C++ Version: 199711\n - MSVC 192829337\n - Intel(R) Math Kernel Library Version 2020.0.2 Product Build 20200624 for Intel(R) 64 architecture applications\n - Intel(R) MKL-DNN v2.6.0 (Git Hash 52b5f107dd9cf10910aaa19cb47f3abf9b349815)\n - OpenMP 2019\n - LAPACK is enabled (usually provided by MKL)\n - CPU capability usage: AVX2\n - CUDA Runtime 11.7\n - 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_61,code=sm_61;-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;-gencode;arch=compute_37,code=compute_37\n - CuDNN 8.5\n - Magma 2.5.4\n - Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=11.7, CUDNN_VERSION=8.5.0, CXX_COMPILER=C:/actions-runner/_work/pytorch/pytorch/builder/windows/tmp_bin/sccache-cl.exe, CXX_FLAGS=/DWIN32 /D_WINDOWS /GR /EHsc /w /bigobj -DUSE_PTHREADPOOL -openmp:experimental -IC:/actions-runner/_work/pytorch/pytorch/builder/windows/mkl/include -DNDEBUG -DUSE_KINETO -DLIBKINETO_NOCUPTI -DUSE_FBGEMM -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -DEDGE_PROFILER_USE_KINETO, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, TORCH_VERSION=1.13.1, 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=OFF, USE_NNPACK=OFF, USE_OPENMP=ON, USE_ROCM=OFF, \n'), ('TorchVision', '0.14.1+cu117'), ('OpenCV', '4.10.0'), ('MMEngine', '0.10.5')])

Reproduces the problem - command or script

FIrstly, Install the thirdpart project Open-CD:
https://github.com/likyoo/open-cd/blob/main/docs/install.md

conda create -n opencd python=3.8
# install pytorch 1.13.1
pip install torch==1.13.1+cu117 torchvision==0.14.1+cu117 torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cu117
# Install OpenMMLab Toolkits as Python packages
pip install -U openmim
mim install mmengine==0.10.4
mim install mmcv==2.1.0
mim install mmpretrain==1.2.0
pip install mmsegmentation==1.2.2
pip install mmdet==3.3.0
git clone https://github.com/likyoo/open-cd.git
cd open-cd
pip install -v -e .
pip install ftfy
pip install regex

Secondly, do some infer testing:
https://github.com/likyoo/open-cd/blob/mocs/inference.mdain/docs/inference.md

>>> from opencd.apis import OpenCDInferencer
>>> # Load models into memory
>>> 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]])
>>> # Inference
>>> inferencer([['demo_A.png', 'demo_B.png']], show=False, out_dir='OUTPUT_PATH')

Reproduces the problem - error message

(opencd) PS D:\LocalAI\DL\CD\open-cd2\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 "", line 1, in
File "D:\LocalAI\DL\CD\open-cd2\open-cd\opencd\apis\opencd_inferencer.py", line 41, in init
super().init(scope=scope, **kwargs)
File "D:\Users\zhanz\miniconda3\envs\opencd\lib\site-packages\mmseg\apis\mmseg_inferencer.py", line 81, in init
super().init(
File "D:\Users\zhanz\miniconda3\envs\opencd\lib\site-packages\mmengine\infer\infer.py", line 160, in init
cfg, _weights = self._load_model_from_metafile(model)
File "D:\Users\zhanz\miniconda3\envs\opencd\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.
quit()

Additional information

How can I let the opencd work if I can't modify the MODULE2PACKAGE?
or there is any other method can I do to bypass the assert check?

@zhanzf zhanzf added the bug Something isn't working label Oct 4, 2024
@zhanzf zhanzf changed the title [Bug] “please pass a valid scope. ” in my thirdpart project [Bug] “please pass a valid scope. ” in the thirdpart project Oct 4, 2024
@tibor-reiss
Copy link

tibor-reiss commented Oct 22, 2024

Hi @zhanzf, please try to specify the correct path to the model file (and weights file), because otherwise you end up in this else which throws the error. But even if one would add opencd to MODULE2PACKAGE, it would fail later because self._load_model_from_metafile(model) assumes a certain layout, e.g. it needs model-index.yml (see e.g. mmsegmentation) which open-cd does not have.

Other option is to monkeypatch MODULE2PACKAGE - it's an ugly hack, but there is nothing which can't be done in python ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants