You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TensorFlow Object Detection API测试报错:TypeError异常求助

Fix for "TypeError: new() got an unexpected keyword argument 'file'" in TensorFlow Object Detection API

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

  1. Check your current Protobuf version
    Run this command to confirm what version you’re using:

    pip show protobuf
    

    If the version is 3.21.0 or higher, that’s the source of the problem.

  2. Uninstall the incompatible Protobuf version

    pip uninstall -y protobuf
    
  3. Install 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.3
    
  4. Recompile your protobuf files (critical step!)
    Since your existing .proto files were likely compiled with the incompatible Protobuf version, you need to regenerate the Python protobuf files:
    Navigate to your models/research directory (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/research and models/research/slim to your PYTHONPATH if needed).

After following these steps, try running the test script again:

python object_detection/builders/model_builder_test.py

内容的提问来源于stack exchange,提问作者Ju Huyan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 10:08:56