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

编译Proto文件后出现ImportError:无法导入string_int_label_map_pb2

Fix: ImportError: cannot import name 'string_int_label_map_pb2'

Hey, I've run into this exact issue before when working with the TensorFlow Object Detection API—let's walk through the fixes step by step:

1. Double-check where you ran the protoc command

The command protoc object_detection/protos/*.proto --python_out=. must be executed from the models/research directory. This ensures the generated .py files end up directly in the object_detection/protos folder (right next to their original .proto files). If you ran it elsewhere, the string_int_label_map_pb2.py file is probably in the wrong place.

Head to ~/Documents/imgmlreport/inception/classification_inception/models/research/object_detection/protos and confirm the string_int_label_map_pb2.py exists. If not, cd back to models/research and re-run the protoc command.

2. Add the required paths to your Python environment

Even if the .py file exists, Python might not be able to find it because the models/research and models/research/slim directories aren't in its default search path. You have two easy fixes here:

Option 1: Set paths temporarily in the terminal

Before running your script, run these commands (replace the paths with your actual username):

export PYTHONPATH=$PYTHONPATH:/home/your-username/Documents/imgmlreport/inception/classification_inception/models/research
export PYTHONPATH=$PYTHONPATH:/home/your-username/Documents/imgmlreport/inception/classification_inception/models/research/slim

Add these lines at the very top of your Python script to automatically add the paths every time you run it:

import sys
sys.path.append('/home/your-username/Documents/imgmlreport/inception/classification_inception/models/research')
sys.path.append('/home/your-username/Documents/imgmlreport/inception/classification_inception/models/research/slim')

3. Verify your protoc version is compatible

Different versions of the Object Detection API require specific protoc versions. For example:

  • TensorFlow 1.x works best with protoc 3.0.0–3.3.0
  • TensorFlow 2.x supports newer versions (like 3.19.0+)

Run protoc --version to check your current version. If it's too old or new, download the matching version and replace your current installation.

4. Ensure all .proto files were compiled successfully

Sometimes the wildcard *.proto might miss some files (due to permissions or corrupted files). Check that every .proto file in object_detection/protos has a corresponding .py file. If string_int_label_map.proto is missing its .py counterpart, compile it individually:

protoc object_detection/protos/string_int_label_map.proto --python_out=.

Try these steps one by one—this should resolve the import error!

内容的提问来源于stack exchange,提问作者송준석

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 07:04:22