pytorch 官方提供案例,进行目标检测入门

​https://pytorch.org/tutorials/intermediate/torchvision_tutorial.html​

使用过程中出现下面的错误。

---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-10-66e4964d4996> in <module>
----> 1 from engine import train_one_epoch, evaluate
2 import utils
3
4
5 def main():

/data01/tt/Pytorch-object-detection/engine.py in <module>
6 import torchvision.models.detection.mask_rcnn
7
----> 8 from coco_utils import get_coco_api_from_dataset
9 from coco_eval import CocoEvaluator
10 import utils

/data01/tt/Pytorch-object-detection/coco_utils.py in <module>
7 import torchvision
8
----> 9 from pycocotools import mask as coco_mask
10 from pycocotools.coco import COCO
11

ModuleNotFoundError: No module named 'pycocotools'

解决方案

执行下面的安装命令即可

$ pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI

对应的运行日志如下

$ pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI

Looking in indexes: http://mirrors.aliyun.com/pypi/simple/
Collecting git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI
Cloning https://github.com/philferriere/cocoapi.git to /tmp/pip-req-build-f19ff0ab
Running command git clone -q https://github.com/philferriere/cocoapi.git /tmp/pip-req-build-f19ff0ab

Building wheels for collected packages: pycocotools
Building wheel for pycocotools (setup.py) ... done
Stored in directory: /tmp/pip-ephem-wheel-cache-56_9uxo7/wheels/69/2b/12/2fa959e49f73d26cff202c2f4e5079096c9c57c8a8509fd75c
Successfully built pycocotools
Installing collected packages: pycocotools
Successfully installed pycocotools-2.0