首页 > 解决方案 > Cannot run Object Detector issues on Windows (ImportError: cannot import name 'string_int_label_map_pb2' from 'object_detection.protos')

问题描述

I'm trying to setup the tensorflow OD package and I tried installing it from the repo, but it doesn't seem to be working.

I followed the installation steps (object_detection) and tried running the test files object_detection.builders.model_builder_tf2_test.py with no avail.

  1. The protoc executable is not recognized
  2. I got a tf_utils missing message at one point
  3. And ended up with ImportError: cannot import name 'string_int_label_map_pb2' from 'object_detection.protos'

I'm a novice playing with this tool, has anybody ran into these issues?

I found these related issues and tried several things, but each step I make forward unlocks another issue.

标签: pythontensorflowobject-detectionobject-detection-apiprotoc

解决方案


After some attempts, starting from a new environment, I put together the steps to make it work.

Create Environment from YML

  1. Use this barebone setup to create a new environment (see snippet below)
  2. Clone the Object Detector (OD) repository
  3. Download protobuf (google) win64 ZIP
  4. Run code below from {rootdir}
    cd models/research
    # Compile protos.
    protoc object_detection/protos/*.proto --python_out=.
    # Install TensorFlow Object Detection API.
    cp object_detection\packages\tf2\setup.py .
    # Step below is important even if some comments online (2021-02-23) suggest it is deprecated
    python -m pip install --use-feature=2020-resolver .
    # The step below was added, after unsuccessful previous attempts, from [this related issue][1]
    pip install .
    
  5. To validate setup, run either of the following
    • python object_detection.builders.model_builder_tf2_test.py
    • import object_detection.builders.model_builder_tf2_test

# This file may be used to create an environment using:
# $ conda create --name <env> --file <this file>
# platform: win-64
@EXPLICIT
https://repo.anaconda.com/pkgs/main/win-64/ca-certificates-2021.1.19-haa95532_0.conda
https://repo.anaconda.com/pkgs/main/win-64/vs2015_runtime-14.27.29016-h5e58377_2.conda
https://repo.anaconda.com/pkgs/main/win-64/vc-14.2-h21ff451_1.conda
https://repo.anaconda.com/pkgs/main/win-64/openssl-1.1.1i-h2bbff1b_0.conda
https://repo.anaconda.com/pkgs/main/win-64/zlib-1.2.11-h62dcd97_4.conda
https://repo.anaconda.com/pkgs/main/win-64/sqlite-3.33.0-h2a8f88b_0.conda
https://repo.anaconda.com/pkgs/main/win-64/python-3.8.0-hff0d562_2.conda
https://repo.anaconda.com/pkgs/main/win-64/certifi-2020.12.5-py38haa95532_0.conda
https://repo.anaconda.com/pkgs/main/noarch/wheel-0.36.2-pyhd3eb1b0_0.conda
https://repo.anaconda.com/pkgs/main/win-64/wincertstore-0.2-py38_0.conda
https://repo.anaconda.com/pkgs/main/win-64/setuptools-52.0.0-py38haa95532_0.conda
https://repo.anaconda.com/pkgs/main/win-64/pip-20.3.3-py38haa95532_0.conda


推荐阅读