models
models copied to clipboard
ImportError: cannot import name 'eval_pb2' from 'object_detection.protos'
Prerequisites
Please answer the following questions for yourself before submitting an issue.
- [x] I am using the latest TensorFlow Model Garden release and TensorFlow 2.
- [x] I am reporting the issue to the correct repository. (Model Garden official or research directory)
- [x] 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/'
-
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')
-
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)
-
Copy Model Config to Training Folder CUSTOM_MODEL_NAME = 'my_ssd_mobnet' !mkdir {'Tensorflow\workspace\models\'+CUSTOM_MODEL_NAME}
-
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:
- 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
how to solve this issue please tell me
Hi @Gaurav061003 ,
Could you please provide the reproducible code and share the exact repo which you are using for training the models if possible.
Thanks
##Reproducible code 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/'
-
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')
-
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)
-
Copy Model Config to Training Folder CUSTOM_MODEL_NAME = 'my_ssd_mobnet' !mkdir {'Tensorflow\workspace\models\'+CUSTOM_MODEL_NAME}
-
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
##exact repo C:\Users\RAVI\RealTimeObjectDetection-main\Tensorflow\models\research\object_detection
Hi @Gaurav061003,
Support for the older codebase has been discontinued. Could you kindly utilize the official Object Detection models provided by TensorFlow Model Garden.
I strongly suggest utilizing the TensorFlow Official Model Garden to circumvent issues related to outdated code commonly found in research codebases. Unlike the research repositories, the Official Model Garden is consistently updated and aligned with the latest changes in TensorFlow and other libraries.
Hope you understanding and Happy coding.
Thanks
but im using the updated version of [official Object Detection
hi, I met similar problem that 'cannot import module from 'object_detection.protos', have you solved it? @Gaurav061003 Thanks!
Hey! @Gaurav061003 I got stuck with the same error. did you find any solution. thanks!