其他分享
首页 > 其他分享> > maskrcnn在win10 报错 AttributeError: module ‘torch.distributed‘ has no attribute ‘deprecated‘

maskrcnn在win10 报错 AttributeError: module ‘torch.distributed‘ has no attribute ‘deprecated‘

作者:互联网

运行maskrcnn的demo时报错:

  File "D:\Anacoda\envs\maskrcnn\lib\site-packages\maskrcnn_benchmark\modeling\make_layers.py", line 10, in <module>
    from maskrcnn_benchmark.layers import Conv2d
  File "D:\Anacoda\envs\maskrcnn\lib\site-packages\maskrcnn_benchmark\layers\__init__.py", line 13, in <module>
    from .roi_pool import ROIPool
  File "D:\Anacoda\envs\maskrcnn\lib\site-packages\maskrcnn_benchmark\layers\roi_pool.py", line 10, in <module>
    from apex import amp
  File "D:\Anacoda\envs\maskrcnn\lib\site-packages\apex-0.1-py3.6-win-amd64.egg\apex\__init__.py", line 5, in <module>
    from . import parallel
  File "D:\Anacoda\envs\maskrcnn\lib\site-packages\apex-0.1-py3.6-win-amd64.egg\apex\parallel\__init__.py", line 8, in <module>
    ReduceOp = torch.distributed.deprecated.reduce_op
AttributeError: module 'torch.distributed' has no attribute 'deprecated'

找到报错中定位的apex文件位置,如

    from .roi_pool import ROIPool
  File "D:\Anacoda\envs\maskrcnn\lib\site-packages\maskrcnn_benchmark\layers\roi_pool.py", line 10, in <module>

点击进入roi_poolroi_align.py文件,注释掉

from maskrcnn_benchmark import _C
# from apex import amp
    # @amp.float_function
    def forward(self, input, rois):
        return roi_pool(input, rois, self.output_size, self.spatial_scale)

将nms.py文件

from maskrcnn_benchmark import _C

from apex import amp

# Only valid with fp32 inputs - give AMP the hint
nms = amp.float_function(_C.nms)

更改为

rom maskrcnn_benchmark import _C

# from apex import amp

# Only valid with fp32 inputs - give AMP the hint
# nms = amp.float_function(_C.nms)
nms=_C.nms

之后使用命令

python webcam.py --min-image-size 224

就可以不依赖apex运行 demo
请添加图片描述

标签:roi,no,apex,attribute,py,benchmark,maskrcnn,报错,import
来源: https://blog.csdn.net/lhe159324/article/details/121534858