TensorFlow Object Detection API测试报错:TypeError异常求助
Hey, I’ve dealt with this exact error before—it’s a classic Protobuf version compatibility issue with the TensorFlow Object Detection API. Let me walk you through how to resolve it:
Root Cause
The error you’re seeing happens because newer versions of Protobuf (3.21.0 and above) removed the file keyword argument that the Object Detection API's generated protobuf files rely on. If you installed a recent Protobuf version or compiled your proto files with a newer version, this mismatch causes the runtime error.
Step-by-Step Fix
Check your current Protobuf version
Run this command to confirm what version you’re using:pip show protobufIf the version is 3.21.0 or higher, that’s the source of the problem.
Uninstall the incompatible Protobuf version
pip uninstall -y protobufInstall a compatible Protobuf version
The Object Detection API works reliably with Protobuf 3.20.3 (this is the version most commonly recommended for older API releases):pip install protobuf==3.20.3Recompile your protobuf files (critical step!)
Since your existing.protofiles were likely compiled with the incompatible Protobuf version, you need to regenerate the Python protobuf files:
Navigate to yourmodels/researchdirectory (where your Object Detection API code lives) and run:protoc object_detection/protos/*.proto --python_out=.
Additional Notes
- If you’re using a Conda environment, make sure you activate it before running these commands to avoid messing with global packages.
- Double-check that you’ve set up the Object Detection API paths correctly (adding
models/researchandmodels/research/slimto yourPYTHONPATHif needed).
After following these steps, try running the test script again:
python object_detection/builders/model_builder_test.py
内容的提问来源于stack exchange,提问作者Ju Huyan

