如何在python中修复“AttributeError: module 'pycocotools' has no attribute 'mask'”错误

3

尽管我已经正确安装了pycocotools,但仍然遇到了一些问题。我还尝试在Colab上运行,因为它们已经预先安装了pycocotools。

安装方法:

!git clone https://github.com/cocodataset/cocoapi.git
%cd /content/cocoapi/PythonAPI
!make
!sudo make install
!sudo python setup.py install
%cd /content

AttributeError                            Traceback (most recent call last)

<ipython-input-11-6a1416ecd890> in <module>()
----> 1 new_mask = get_mask(label['segmentations'], mask)

/content/datasets/coco.py in get_mask(segmentations, mask)
     17 def get_mask(segmentations, mask):
     18     for segmentation in segmentations:
---> 19         rle = pycocotools.mask.frPyObjects(segmentation, mask.shape[0], mask.shape[1])
     20         mask[pycocotools.mask.decode(rle) > 0.5] = 0
     21     return mask

AttributeError: module 'pycocotools' has no attribute 'mask'

导致此错误的代码行: pycocotools.mask.frPyObjects(segmentation, mask.shape[0], mask.shape[1])


你是如何安装pycocotools的? - Dr. Snoopy
1个回答

1
如果您只导入了pycocotools,那么mask模块就没有被导入。
请尝试显式地导入mask:
import pycocotools.mask

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接