ryan
ryan

Reputation: 49

'No module named 'engine' error in Pytorch tutorial

I am following a tutorial on the PyTorch website and I can't figure out what package this import uses:

from engine import train_one_epoch, evaluate

I get an error saying:

Traceback (most recent call last):
  File "C:\Users\...\tv-training-code.py", line 13, in <module>
    from engine import train_one_epoch, evaluate
ModuleNotFoundError: No module named 'engine'

For reference, I am using Conda to run the program and I have the latest PyTorch version installed. Any ideas for what package I need to install to make this work?

Upvotes: 3

Views: 7546

Answers (1)

desertnaut
desertnaut

Reputation: 60318

There is an obvious omission to the subject tutorial, which has caused justified confusion to others, too; this question has been raised in the Pytorch forum as well - here is the accepted answer:

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.

Essentially, the necessary steps are shown in the colab notebook accompanying the tutorial:

%%shell

# Download TorchVision repo to use some files from
# references/detection
git clone https://github.com/pytorch/vision.git
cd vision
git checkout v0.8.2

cp references/detection/utils.py ../
cp references/detection/transforms.py ../
cp references/detection/coco_eval.py ../
cp references/detection/engine.py ../
cp references/detection/coco_utils.py ../

which must be executed before you attempt to import anything from the engine module.

Upvotes: 4

Related Questions