Ubuntu 18.4: 'ModuleNotFoundError: No module named 'pycocotools._mask''

I am trying to use MeanAveragePrecision as described in here

Minimal example

conda create -n myenv python=3.9
conda activate myenv
pip install torch torchmetrics torchvision

Then the following code from the torchmetrics page:

import torch
from torchmetrics.detection.mean_ap import MeanAveragePrecision
preds = [
        boxes=torch.tensor([[258.0, 41.0, 606.0, 285.0]]),
target = [
        boxes=torch.tensor([[214.0, 41.0, 562.0, 285.0]]),
metric = MeanAveragePrecision()
metric.update(preds, target)
from pprint import pprint

This is working quite fine on my Mac, but not on Ubuntu 18.04, my main processing machine.
I am recieving the following error:

  File "/home/karsil/mAP_simple.py", line 2, in <module>
    from torchmetrics.detection.mean_ap import MeanAveragePrecision
  File "/home/karsil/miniconda3/envs/myenv/lib/python3.9/site-packages/torchmetrics/detection/mean_ap.py", line 31, in <module>
    import pycocotools.mask as mask_utils
  File "/home/karsil/models/research/pycocotools/mask.py", line 3, in <module>
    import pycocotools._mask as _mask
ModuleNotFoundError: No module named 'pycocotools._mask'

I’ve already found this solution from this forum and applied it with no change.

Glad for any help! :slight_smile: