运行TensorFlow模型时遇ModuleNotFoundError及retry模块缺失问题求助
Hey there, let's work through those two errors you're facing when running your TensorFlow model. These are super common with the TensorFlow Object Detection API, so here's how to squash them:
1. Fixing ModuleNotFoundError: No module named 'nets'
The nets module is part of TensorFlow Slim, which isn't installed by default when you grab TensorFlow via pip. Here's what to do:
Add the Slim directory to your Python path:
First, make sure you have the TensorFlow Models repository code (it includes theslimfolder wherenetslives). Once you have it, you can either:- Add this code at the very top of your script to dynamically include the path:
import sys sys.path.append('/absolute/path/to/models/research/slim') - Or set it permanently in PyCharm: Go to
File > Settings > Project: [Your Project Name] > Python Interpreter > Show All→ Select your Python 3.6 interpreter → ClickShow paths for the selected interpreter→ Hit the+button and add the absolute path to theslimfolder.
- Add this code at the very top of your script to dynamically include the path:
Install Slim as a package (optional):
Navigate to theslimdirectory in your terminal and run:pip install .This makes
netsavailable system-wide for your Python 3.6 environment.
2. Fixing the "Use the retry module or similar alternatives" Error
This error pops up because the Object Detection API relies on the retry module, which isn't included in the default TensorFlow installation. Here's the fix:
Install the missing dependency:
Run this command in your terminal (make sure you're using your Python 3.6 environment):pip install retryDouble-check all required dependencies:
Head to theresearchdirectory of your TensorFlow Models code and run:pip install -r requirements.txtThis installs every package the Object Detection API needs, just to be safe.
Don't forget to compile Protobuf files:
A common missed step is compiling the Protobuf definitions, which can cause hidden dependency issues. In theresearchdirectory, run:protoc object_detection/protos/*.proto --python_out=.Also, make sure the
researchdirectory itself is added to your Python path (same method as theslimfolder above) to ensure all modules are found.
内容的提问来源于stack exchange,提问作者vrd.gn

