Windows系统下如何通过Anaconda本地运行TensorFlow Object Detection API(禁用CMD)
Hey there! I’ve been in your shoes before—getting the Object Detection API up and running with Anaconda on Windows can feel tricky when Command Prompt isn’t cooperating. Let’s break this down step by step, using only Anaconda’s tools:
Step 1: Open Anaconda Prompt & Activate Your TensorFlow Environment
First, launch the Anaconda Prompt (you’ll find it in your Start Menu under Anaconda3). This is key because it automatically loads all your Anaconda environment configurations, which Command Prompt might not handle properly.
Once it’s open, activate your TensorFlow environment with:
conda activate your-tensorflow-env-name
Replace your-tensorflow-env-name with the actual name of the environment where you installed TensorFlow (e.g., tf2_env).
Step 2: Navigate to Your Object Detection API Directory
Use the cd command to move to the folder where you’ve downloaded/cloned the TensorFlow Object Detection API. For example, if your API is in C:\Projects\tensorflow\models\research\object_detection, run:
cd C:\Projects\tensorflow\models\research\object_detection
Pro tip: You can drag-and-drop the folder directly into the Anaconda Prompt window to auto-fill the path—saves typing errors!
Step 3: Set Up the Required PYTHONPATH
The Object Detection API needs its parent directories added to your Python path to work correctly. In the same Anaconda Prompt session, run these two commands (adjust the paths to match your setup):
set PYTHONPATH=%PYTHONPATH%;C:\Projects\tensorflow\models\research set PYTHONPATH=%PYTHONPATH%;C:\Projects\tensorflow\models\research\slim
Note: This sets the path temporarily for the current session. If you want it to persist every time you activate the environment, you can add these lines to a activate.bat file in your environment’s Scripts folder (e.g., C:\Users\YourName\anaconda3\envs\your-tensorflow-env-name\Scripts\activate.bat).
Step 4: Verify the Setup
To make sure everything’s working, run the API’s test script. For TensorFlow 2.x, use:
python object_detection/builders/model_builder_tf2_test.py
If you see lines ending with OK, you’re good to go! If you get module-not-found errors, double-check your PYTHONPATH paths and make sure you’re in the correct directory.
Quick Troubleshooting Tips
- If activating the environment fails: Run
conda env listto see all your Anaconda environments and confirm the name. - If
cdthrows an error: Make sure the directory path exists—check for typos in folder names or drive letters. - If test script fails: Ensure you’ve installed all required dependencies (like
protobuf,pillow,lxml, etc.) in your TensorFlow environment. You can install them withconda install protobuf pillow lxml matplotlib opencv-python.
内容的提问来源于stack exchange,提问作者Abigale Moore

