Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'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?

like image 981
ryan Avatar asked Oct 29 '25 19:10

ryan


1 Answers

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.

like image 158
desertnaut Avatar answered Nov 01 '25 09:11

desertnaut



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!