When I use dist_train to train a model, I got an error like
from mmcv.ops import (ContextBlock, Conv2d, ConvTranspose2d, ConvWS2d,
ImportError: cannot import name 'ContextBlock'
And I have checked that ContextBlock in under mmcv.cnn.bricks. Do I install them in the wrong way?
My mmdet version is 2.3 and mmcv is 1.0.5, CUDA 10.2 and python3.6.
You need to check your environment to see whether there is an old version of mmcv. Or you need to uninstall mmcv 1.0.5 and pip install mmcv-full==1.0.5 with GPU.
Could this due to ContextBlock moving from ops to cnn in this commit: https://github.com/open-mmlab/mmcv/commit/42f03d84de551756ec5a149e37d05d06c4a1aacf?
That is the problem. I change the modern.opt __init__ file and it is working now
Zhexuan Zhou
发件人: Daniel Suess notifications@github.com
发送时间: Monday, August 17, 2020 7:04:22 PM
收件人: open-mmlab/mmdetection mmdetection@noreply.github.com
抄送: Zhexuan Zhou rmt_zhou@live.com; Author author@noreply.github.com
主题: Re: [open-mmlab/mmdetection] I got an error in training (#3546)
Could this due to ContextBlock moving from ops to cnn in this commit: open-mmlab/mmcv@42f03d8https://github.com/open-mmlab/mmcv/commit/42f03d84de551756ec5a149e37d05d06c4a1aacf?
―
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHubhttps://github.com/open-mmlab/mmdetection/issues/3546#issuecomment-674815755, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADDNA7NTNU7MKWQVZ2JPE6DSBEFDNANCNFSM4P57BYZQ.
For mmcv 1.1.2, modifying mmdet/ops/__init__.py with the import statements below works in my environment.
If we keep the file for back-compatibility, we further need to add if-else for multiple mmcv versions.
Making the file empty would be appropriate for many users.
try:
from mmcv.ops import (ContextBlock, ConvWS2d, conv_ws_2d,
GeneralizedAttention)
except ImportError:
from mmcv.cnn import (ContextBlock, ConvWS2d, conv_ws_2d,
GeneralizedAttention)
from mmcv.cnn import NonLocal2d as NonLocal2D
from mmcv.cnn import build_plugin_layer
from mmcv.ops import Conv2d, ConvTranspose2d, CornerPool
from mmcv.ops import DeformConv2d as DeformConv
from mmcv.ops import DeformConv2dPack as DeformConvPack
from mmcv.ops import DeformRoIPool as DeformRoIPooling
from mmcv.ops import DeformRoIPoolPack as DeformRoIPoolingPack
from mmcv.ops import Linear, MaskedConv2d, MaxPool2d
from mmcv.ops import ModulatedDeformConv2d as ModulatedDeformConv
from mmcv.ops import ModulatedDeformConv2dPack as ModulatedDeformConvPack
from mmcv.ops import \
ModulatedDeformRoIPoolPack as ModulatedDeformRoIPoolingPack
from mmcv.ops import (RoIAlign, RoIPool, SAConv2d, SigmoidFocalLoss,
SimpleRoIAlign, batched_nms)
from mmcv.ops import deform_conv2d as deform_conv
from mmcv.ops import deform_roi_pool as deform_roi_pooling
from mmcv.ops import get_compiler_version, get_compiling_cuda_version
from mmcv.ops import modulated_deform_conv2d as modulated_deform_conv
from mmcv.ops import (nms, nms_match, point_sample,
rel_roi_point_to_rel_img_point, roi_align, roi_pool,
sigmoid_focal_loss, soft_nms)
That is the problem. I change the modern.opt __init__ file and it is working now Zhexuan Zhou
…
________________________________ 发件人: Daniel Suess notifications@github.com 发送时间: Monday, August 17, 2020 7:04:22 PM 收件人: open-mmlab/mmdetection mmdetection@noreply.github.com 抄送: Zhexuan Zhou rmt_zhou@live.com; Author author@noreply.github.com 主题: Re: [open-mmlab/mmdetection] I got an error in training (#3546) Could this due to ContextBlock moving from ops to cnn in this commit: open-mmlab/mmcv@42f03d8<open-mmlab/mmcv@42f03d8>? ― You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub<#3546 (comment)>, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADDNA7NTNU7MKWQVZ2JPE6DSBEFDNANCNFSM4P57BYZQ.
Hi @ZhexuanZhou
Could You explain more detail about how to change "the modern.opt __init__ file", because I faced the same problem.
Thank You
Most helpful comment
For mmcv 1.1.2, modifying
mmdet/ops/__init__.pywith the import statements below works in my environment.If we keep the file for back-compatibility, we further need to add if-else for multiple mmcv versions.
Making the file empty would be appropriate for many users.