chenhang98 / BPR

code for `Look Closer to Segment Better: Boundary Patch Refinement for Instance Segmentation`
Apache License 2.0
173 stars 23 forks source link

ModuleNotFoundError: No module named 'mmcv.runner' while trying to run this demo #46

Closed mohdsaqibxa closed 1 year ago

mohdsaqibxa commented 1 year ago

I am getting this error ModuleNotFoundError: No module named 'mmcv.runner' while trying to run this demo notebook https://github.com/chenhang98/BPR/blob/main/demo/inference_img.ipynb and import followings:

ModuleNotFoundError Traceback (most recent call last) Cell In[2], line 6 4 import numpy as np 5 import matplotlib.pyplot as plt ----> 6 from inference_img import _build_model, _build_dataloader, split, merge

File /mnt/batch/tasks/shared/LS_root/mounts/clusters/mohd-inst2/code/Users/mohd.saqib/Boundary_Refinement/BPR/demo/inference_img.py:14 11 from functools import partial 12 from torch.utils.data import Dataset, DataLoader ---> 14 from mmcv.runner import load_checkpoint 15 from mmseg.models import build_segmentor 16 from mmcv.parallel import MMDataParallel, DataContainer, collate

ModuleNotFoundError: No module named 'mmcv.runner'

Environment details: torch 1.10.1+cu113 torchvision 0.11.2+cu113 CUDA 11.3 mmcv 2.0.0rc4 mmengine 0.7.3 mmsegmentation 1.0.0

Any help is appreciated. Thanks

chenhang98 commented 1 year ago

This might be because the versions of mmcv and mmseg are not compatible. We have tested this repo on the following environment, for your reference.

mmcv-full                 1.1.6                    pypi_0    pypi
mmdet                     1.2.0+0f33c08             dev_0    <develop>
mmsegmentation            0.7.0                     dev_0    <develop>

pytorch and torchvision versions are 1.4.0 and 0.5.0 respectively, and the CUDA version is 10.0

mohdsaqibxa commented 1 year ago

Hi @chenhang98 Thanks for the reply. I tried installing above versions. I successfully installed mmcv-full and mmsegmentation. But I am not able to insatall 1.2.0+0f33c08, because they have removed it from the git repo.

And upon running without mmdet gives me this error.

from mmseg.models import build_segmentor
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/anaconda/envs/boundary_refine/lib/python3.8/site-packages/mmseg/models/__init__.py", line 1, in <module>
    from .backbones import *  # noqa: F401,F403
  File "/anaconda/envs/boundary_refine/lib/python3.8/site-packages/mmseg/models/backbones/__init__.py", line 1, in <module>
    from .fast_scnn import FastSCNN
  File "/anaconda/envs/boundary_refine/lib/python3.8/site-packages/mmseg/models/backbones/fast_scnn.py", line 7, in <module>
    from mmseg.models.decode_heads.psp_head import PPM
  File "/anaconda/envs/boundary_refine/lib/python3.8/site-packages/mmseg/models/decode_heads/__init__.py", line 13, in <module>
    from .point_head import PointHead
  File "/anaconda/envs/boundary_refine/lib/python3.8/site-packages/mmseg/models/decode_heads/point_head.py", line 6, in <module>
    from mmcv.ops import point_sample
  File "/mnt/batch/tasks/shared/LS_root/mounts/clusters/mohd-inst2/code/Users/mohd.saqib/Boundary_Refinement/mmcv/mmcv-1.1.6/mmcv/ops/__init__.py", line 1, in <module>
    from .bbox import bbox_overlaps
  File "/mnt/batch/tasks/shared/LS_root/mounts/clusters/mohd-inst2/code/Users/mohd.saqib/Boundary_Refinement/mmcv/mmcv-1.1.6/mmcv/ops/bbox.py", line 3, in <module>
    ext_module = ext_loader.load_ext('_ext', ['bbox_overlaps'])
  File "/mnt/batch/tasks/shared/LS_root/mounts/clusters/mohd-inst2/code/Users/mohd.saqib/Boundary_Refinement/mmcv/mmcv-1.1.6/mmcv/utils/ext_loader.py", line 11, in load_ext
    ext = importlib.import_module('mmcv.' + name)
  File "/anaconda/envs/boundary_refine/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'mmcv._ext'

Is there anyway to run the demo notebook with latest versions? Appreciate any help.

mohdsaqibxa commented 1 year ago

UPDATE:

By installing:

mmcv-full           1.4.0
mmdet               2.19.1
mmsegmentation      0.20.2

solves the above issues. But now, I am getting new issue by running this

import torch
import cv2
import os
import numpy as np
import matplotlib.pyplot as plt
from inference_img import _build_model, _build_dataloader, split, merge

cfg = "../configs/bpr/hrnet18s_128.py"
ckpt = "../ckpts/hrnet18s_128-24055c80.pth"
max_ins = 16         # set to lower value to save GPU memory
model = _build_model(cfg, ckpt)

Traceback (most recent call last):
  File "run.py", line 11, in <module>
    model = _build_model(cfg, ckpt)
  File "/mnt/batch/tasks/shared/LS_root/mounts/clusters/mohd-inst2/code/Users/mohd.saqib/Boundary_Refinement/BPR/demo/inference_img.py", line 134, in _build_model
    model = build_segmentor(cfg.model, train_cfg=None, test_cfg=cfg.test_cfg)
  File "/anaconda/envs/refine_boundary/lib/python3.8/site-packages/mmseg/models/builder.py", line 48, in build_segmentor
    return SEGMENTORS.build(
  File "/anaconda/envs/refine_boundary/lib/python3.8/site-packages/mmcv/utils/registry.py", line 212, in build
    return self.build_func(*args, **kwargs, registry=self)
  File "/anaconda/envs/refine_boundary/lib/python3.8/site-packages/mmcv/cnn/builder.py", line 27, in build_model_from_cfg
    return build_from_cfg(cfg, registry, default_args)
  File "/anaconda/envs/refine_boundary/lib/python3.8/site-packages/mmcv/utils/registry.py", line 44, in build_from_cfg
    raise KeyError(
KeyError: 'EncoderDecoderRefine is not in the models registry'
chenhang98 commented 1 year ago

Our repository is based on mmseg 0.7.0 with some modifications. Therefore, you need to install our repo instead of the official mmseg. For example, run pip install -e . after all the dependencies are installed.