ModuleNotFoundError: No module named 'engine'

When I executed the source code.

The code is from the tutorial https://pytorch.org/tutorials/intermediate/torchvision_tutorial.html

It said that:

(base) [yq@local pytorch-examples]$python3 tv-training-code.py
Traceback (most recent call last):
  File "tv-training-code.py", line 13, in <module>
    from engine import train_one_epoch, evaluate
ModuleNotFoundError: No module named 'engine'

I don’t know which package is called ‘engine’ here.

From the tutorial:

In references/detection/ , we have a number of helper functions to simplify training and evaluating detection models. Here, we will use references/detection/engine.py , references/detection/utils.py and references/detection/transforms.py . Just copy them to your folder and use them here.

4 Likes

So how do we get the references/detection/ folders? What should we download and install? I have installed the pytorch, torchvision in my environment, but I could not find those files. Thanks

You could copy/paste these files fro the torchvision repository or clone it locally.

1 Like

git clone https://github.com/pytorch/vision
git clone https://github.com/cocodataset/cocoapi
In vision/references/detection: copy all .py file to [tv-training-code.py] directory
Copy cocoapi/PythonAPI/pycocotools to [tv-training-code.py] directory

5 Likes