ImportError: cannot import name 'eval_pb2' from 'object_detection.protos'

オープン
#11,168 コメント 8 件 リアクション 0 件 担当者 1 名 GitHub で見る

@laxmareddyp がすでに取り組んでいます。

2024年2月23日 から。

評価

この issue はまだ評価されていません。

説明

models:research type:bug

Prerequisites

Please answer the following questions for yourself before submitting an issue.

  • I am using the latest TensorFlow Model Garden release and TensorFlow 2.
  • I am reporting the issue to the correct repository. (Model Garden official or research directory)
  • I checked to make sure that this issue has not been filed already.

1. The entire URL of the file you are using

https://github.com/tensorflow/models

2. Describe the bug

ImportError Traceback (most recent call last)
Cell In[27], line 3
1 import tensorflow as tf
2 from google.protobuf import text_format
----> 3 from object_detection.utils import config_util
4 from object_detection.protos import pipeline_pb2

File ~\anaconda3\Lib\site-packages\object_detection\utils\config_util.py:24
20 from google.protobuf import text_format
22 from tensorflow.python.lib.io import file_io
---> 24 from object_detection.protos import eval_pb2
25 from object_detection.protos import graph_rewriter_pb2
26 from object_detection.protos import input_reader_pb2

ImportError: cannot import name 'eval_pb2' from 'object_detection.protos' (C:\Users\RAVI\anaconda3\Lib\site-packages\object_detection\protos_init_.py)

3. Steps to reproduce

WORKSPACE_PATH = 'Tensorflow/workspace'
SCRIPTS_PATH = 'Tensorflow/scripts'
APIMODEL_PATH = 'Tensorflow/models'
ANNOTATION_PATH = WORKSPACE_PATH+'/annotations'
IMAGE_PATH = WORKSPACE_PATH+'/images'
MODEL_PATH = WORKSPACE_PATH+'/models'
PRETRAINED_MODEL_PATH = WORKSPACE_PATH+'/pre-trained-models'
CONFIG_PATH = MODEL_PATH+'/my_ssd_mobnet/pipeline.config'
CHECKPOINT_PATH = MODEL_PATH+'/my_ssd_mobnet/'

  1. Create Label Map
    labels = [{'name':'Hello', 'id':1},
    {'name':'Yes', 'id':2},
    {'name':'No', 'id':3},
    {'name':'Thanks', 'id':4},
    {'name':'I Love You', 'id':5},
    ]
    with open(ANNOTATION_PATH + '\label_map.pbtxt', 'w') as f:
    for label in labels:
    f.write('item { \n')
    f.write('\tname:'{}'\n'.format(label['name']))
    f.write('\tid:{}\n'.format(label['id']))
    f.write('}\n')

  2. Create TF records
    import os
    ​
    def create_tf_record(image_dir, annotation_path, output_path):
    os.system(f"python {SCRIPTS_PATH}/generate_tfrecord.py -x {image_dir} -l {annotation_path}/label_map.pbtxt -o {output_path}")
    print(f"Successfully created the TFRecord file: {output_path}")
    ​

Example usage:

train_image_dir = os.path.join(IMAGE_PATH, 'train')
test_image_dir = os.path.join(IMAGE_PATH, 'test')
train_output_path = os.path.join(ANNOTATION_PATH, 'train.record')
test_output_path = os.path.join(ANNOTATION_PATH, 'test.record')
​
create_tf_record(train_image_dir, ANNOTATION_PATH, train_output_path)
create_tf_record(test_image_dir, ANNOTATION_PATH, test_output_path)
​
import os
import urllib.request
import tarfile

def download_pretrained_model(model_name, model_dir):
model_url = f'http://download.tensorflow.org/models/object_detection/tf2/20200711/{model_name}.tar.gz'
model_path = os.path.join(model_dir, f"{model_name}.tar.gz")

# Download the model
urllib.request.urlretrieve(model_url, model_path)

# Extract the downloaded file
with tarfile.open(model_path, 'r:gz') as tar:
    tar.extractall(model_dir)

# Remove the compressed file
os.remove(model_path)

print(f"Download and extraction of {model_name} complete.")

Example usage:

pretrained_model_name = 'ssd_mobilenet_v2_fpnlite_320x320_coco17_tpu-8'
PRETRAINED_MODEL_PATH = 'Tensorflow/workspace/pre-trained-models' # Assuming this is your predefined path
download_pretrained_model(pretrained_model_name, PRETRAINED_MODEL_PATH)

  1. Copy Model Config to Training Folder
    CUSTOM_MODEL_NAME = 'my_ssd_mobnet'
    !mkdir {'Tensorflow\workspace\models\'+CUSTOM_MODEL_NAME}

  2. Update Config For Transfer Learning
    import tensorflow as tf
    from google.protobuf import text_format
    from object_detection.utils import config_util
    from object_detection.protos import pipeline_pb2
    ​

4. Expected behavior

Expected Behavior:
I expected to import the config_util module from object_detection.utils without encountering an ImportError.

Context:
I am working on setting up an object detection pipeline using TensorFlow Object Detection API version 2.15.0

5. Additional context

ImportError: cannot import name 'eval_pb2' from 'object_detection.protos' (C:\Users\RAVI\anaconda3\Lib\site-packages\object_detection\protos_init_.py)

6. System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 11

  • Mobile device name if the issue happens on a mobile device:

  • TensorFlow installed from (source or binary): Official website

  • TensorFlow version (use command below): v2.15.0-rc1-8-g6887368d6d4 2.15.0

  • Python version: 3.8.0

  • Bazel version (if compiling from source):

  • GCC/Compiler version (if compiling from source):

  • CUDA/cuDNN version: CUDA Toolkit v11.2 / CuDNN 8.1.0

  • GPU model and memory: AMD Radeon(TM) Graphics

Collect system information using our environment capture script.
https://github.com/tensorflow/tensorflow/tree/master/tools/tf_env_collect.sh

You can also obtain the TensorFlow version with:

  1. TensorFlow 2.0
    python -c "import tensorflow as tf; print(tf.version.GIT_VERSION, tf.version.VERSION)"
    --> v2.15.0-rc1-8-g6887368d6d4 2.15.0
    Screenshot 2024-02-23 231356
主要言語
Python
スター
77.6k
フォーク
44.8k
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

tensorflow/models のほかの issue

tensorflow/models の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。