Config_util import problem

trying to run :
import tensorflow as tf
from object_detection.utils import config_util
from object_detection.protos import pipeline_pb2
from google.protobuf import text_format

i get as error :

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

File ~\Documents\yzdyzd\pyModel\TFODCourse\Tensorflow\models\research\object_detection\utils\config_util.py:28
24 import tensorflow.compat.v1 as tf
26 from tensorflow.python.lib.io import file_io
—> 28 from object_detection.protos import eval_pb2
29 from object_detection.protos import graph_rewriter_pb2
30 from object_detection.protos import input_reader_pb2

File ~\Documents\yzdyzd\pyModel\TFODCourse\Tensorflow\models\research\object_detection\protos\eval_pb2.py:36
11 _sym_db = _symbol_database.Default()
16 DESCRIPTOR = _descriptor.FileDescriptor(
17 name=‘object_detection/protos/eval.proto’,
18 package=‘object_detection.protos’,
(…)
22 serialized_pb=b’\n"object_detection/protos/eval.proto\x12\x17object_detection.protos"\xdf\n\n\nEvalConfig\x12\x15\n\nbatch_size\x18\x19 \x01(\r:\x01\x31\x12\x1e\n\x12num_visualizations\x18\x01 \x01(\r:\x02\x31\x30\x12\x1e\n\x0cnum_examples\x18\x02 \x01(\r:\x04\x35\x30\x30\x30\x42\x02\x18\x01\x12\x1f\n\x12\x65val_interval_secs\x18\x03 \x01(\r:\x03\x33\x30\x30\x12\x18\n\tmax_evals\x18\x04 \x01(\r:\x01\x30\x42\x02\x18\x01\x12\x19\n\nsave_graph\x18\x05 \x01(\x08:\x05\x66\x61lse\x12"\n\x18visualization_export_dir\x18\x06 \x01(\t:\x00\x12\x15\n\x0b\x65val_master\x18\x07 \x01(\t:\x00\x12\x13\n\x0bmetrics_set\x18\x08 \x03(\t\x12J\n\x14parameterized_metric\x18\x1f \x03(\x0b\x32,.object_detection.protos.ParameterizedMetric\x12\x15\n\x0b\x65xport_path\x18\t \x01(\t:\x00\x12!\n\x12ignore_groundtruth\x18\n \x01(\x08:\x05\x66\x61lse\x12"\n\x13use_moving_averages\x18\x0b \x01(\x08:\x05\x66\x61lse\x12"\n\x13\x65val_instance_masks\x18\x0c \x01(\x08:\x05\x66\x61lse\x12 \n\x13min_score_threshold\x18\r \x01(\x02:\x03\x30.5\x12&\n\x1amax_num_boxes_to_visualize\x18\x0e \x01(\x05:\x02\x32\x30\x12\x1a\n\x0bskip_scores\x18\x0f \x01(\x08:\x05\x66\x61lse\x12\x1a\n\x0bskip_labels\x18\x10 \x01(\x08:\x05\x66\x61lse\x12*\n\x1bvisualize_groundtruth_boxes\x18\x11 \x01(\x08:\x05\x66\x61lse\x12\x32\n#groundtruth_box_visualization_color\x18\x12 \x01(\t:\x05\x62lack\x12\x35\n&keep_image_id_for_visualization_export\x18\x13 \x01(\x08:\x05\x66\x61lse\x12$\n\x16retain_original_images\x18\x17 \x01(\x08:\x04true\x12+\n\x1cinclude_metrics_per_category\x18\x18 \x01(\x08:\x05\x66\x61lse\x12'\n\x18\x61ll_metrics_per_category\x18# \x01(\x08:\x05\x66\x61lse\x12R\n\x10super_categories\x18" \x03(\x0b\x32\x38.object_detection.protos.EvalConfig.SuperCategoriesEntry\x12\x1d\n\x12recall_lower_bound\x18\x1a \x01(\x02:\x01\x30\x12\x1d\n\x12recall_upper_bound\x18\x1b \x01(\x02:\x01\x31\x12\x38\n)retain_original_image_additional_channels\x18\x1c \x01(\x08:\x05\x66\x61lse\x12\x1e\n\x0f\x66orce_no_resize\x18\x1d \x01(\x08:\x05\x66\x61lse\x12%\n\x16use_dummy_loss_in_eval\x18\x1e \x01(\x08:\x05\x66\x61lse\x12<\n\rkeypoint_edge\x18 \x03(\x0b\x32%.object_detection.protos.KeypointEdge\x12\x33\n$skip_predictions_for_unlabeled_class\x18! \x01(\x08:\x05\x66\x61lse\x12\x33\n%image_classes_field_map_empty_to_ones\x18$ \x01(\x08:\x04true\x1a\x36\n\x14SuperCategoriesEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01"|\n\x13ParameterizedMetric\x12M\n\x15\x63oco_keypoint_metrics\x18\x01 \x01(\x0b\x32,.object_detection.protos.CocoKeypointMetricsH\x00\x42\x16\n\x14parameterized_metric"\xd3\x01\n\x13\x43ocoKeypointMetrics\x12\x13\n\x0b\x63lass_label\x18\x01 \x01(\t\x12i\n\x18keypoint_label_to_sigmas\x18\x02 \x03(\x0b\x32G.object_detection.protos.CocoKeypointMetrics.KeypointLabelToSigmasEntry\x1a<\n\x1aKeypointLabelToSigmasEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\x02:\x02\x38\x01"*\n\x0cKeypointEdge\x12\r\n\x05start\x18\x01 \x01(\x05\x12\x0b\n\x03\x65nd\x18\x02 \x01(\x05’
23 )
28 _EVALCONFIG_SUPERCATEGORIESENTRY = _descriptor.Descriptor(
29 name=‘SuperCategoriesEntry’,
30 full_name=‘object_detection.protos.EvalConfig.SuperCategoriesEntry’,
31 filename=None,
32 file=DESCRIPTOR,
33 containing_type=None,
34 create_key=_descriptor._internal_create_key,
35 fields=[
—> 36 _descriptor.FieldDescriptor(
37 name=‘key’, full_name=‘object_detection.protos.EvalConfig.SuperCategoriesEntry.key’, index=0,
38 number=1, type=9, cpp_type=9, label=1,
39 has_default_value=False, default_value=b"“.decode(‘utf-8’),
40 message_type=None, enum_type=None, containing_type=None,
41 is_extension=False, extension_scope=None,
42 serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key),
43 _descriptor.FieldDescriptor(
44 name=‘value’, full_name=‘object_detection.protos.EvalConfig.SuperCategoriesEntry.value’, index=1,
45 number=2, type=9, cpp_type=9, label=1,
46 has_default_value=False, default_value=b”".decode(‘utf-8’),
47 message_type=None, enum_type=None, containing_type=None,
48 is_extension=False, extension_scope=None,
49 serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key),
50 ],
51 extensions=[
52 ],
53 nested_types=[],
54 enum_types=[
55 ],
56 serialized_options=b’8\001’,
57 is_extendable=False,
58 syntax=‘proto2’,
59 extension_ranges=[],
60 oneofs=[
61 ],
62 serialized_start=1385,
63 serialized_end=1439,
64 )
66 _EVALCONFIG = _descriptor.Descriptor(
67 name=‘EvalConfig’,
68 full_name=‘object_detection.protos.EvalConfig’,
(…)
318 serialized_end=1439,
319 )
322 _PARAMETERIZEDMETRIC = _descriptor.Descriptor(
323 name=‘ParameterizedMetric’,
324 full_name=‘object_detection.protos.ParameterizedMetric’,
(…)
355 serialized_end=1565,
356 )

File ~\Documents\yzdyzd\MLYZD\TFODCourse\YYZD\lib\site-packages\google\protobuf\descriptor.py:561, in FieldDescriptor.new(cls, name, full_name, index, number, type, cpp_type, label, default_value, message_type, enum_type, containing_type, is_extension, extension_scope, options, serialized_options, has_default_value, containing_oneof, json_name, file, create_key)
555 def new(cls, name, full_name, index, number, type, cpp_type, label,
556 default_value, message_type, enum_type, containing_type,
557 is_extension, extension_scope, options=None,
558 serialized_options=None,
559 has_default_value=True, containing_oneof=None, json_name=None,
560 file=None, create_key=None): # pylint: disable=redefined-builtin
→ 561 _message.Message._CheckCalledFromGeneratedFile()
562 if is_extension:
563 return _message.default_pool.FindExtensionByName(full_name)

TypeError: Descriptors cannot not be created directly.
If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
If you cannot immediately regenerate your protos, some other possible workarounds are:

  1. Downgrade the protobuf package to 3.20.x or lower.
  2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).

More information: Changes made on May 6, 2022 | Protocol Buffers Documentation

any help?

@youssef_zmander,

Welcome to the Tensorflow Forum!

As suggested in the error message, you can downgrade protobuf version

pip install 'protobuf<=3.20.1' --force-reinstall

Thank you!

1 Like