tensorflow / models

Models and examples built with TensorFlow
Other
77k stars 45.78k forks source link

AttributeError: module 'object_detection.protos.faster_rcnn_pb2' has no attribute 'AttentionPosition' while model_builders is getting imported #10563

Open Daremitsu1 opened 2 years ago

Daremitsu1 commented 2 years ago

While trying to run the following code:-

import os import tensorflow as tf from object_detection.utils import label_map_util from object_detection.utils import visualization_utils as viz_utils from object_detection.builders import model_builder from object_detection.utils import config_util

I am getting the following error:-


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [16], in <cell line: 5>()
      3 from object_detection.utils import label_map_util
      4 from object_detection.utils import visualization_utils as viz_utils
----> 5 from object_detection.builders import model_builder
      6 from object_detection.utils import config_util

File ~\anaconda3\envs\anprsys\lib\site-packages\object_detection\builders\model_builder.py:36, in <module>
     34 from object_detection.meta_architectures import ssd_meta_arch
     35 from object_detection.models import faster_rcnn_inception_resnet_v2_feature_extractor as frcnn_inc_res
---> 36 from object_detection.models import faster_rcnn_inception_v2_feature_extractor as frcnn_inc_v2
     37 from object_detection.models import faster_rcnn_nas_feature_extractor as frcnn_nas
     38 from object_detection.models import faster_rcnn_pnas_feature_extractor as frcnn_pnas

File ~\anaconda3\envs\anprsys\lib\site-packages\object_detection\meta_architectures\context_rcnn_meta_arch.py:42, in <module>
     37 from object_detection.utils import tf_version
     39 _UNINITIALIZED_FEATURE_EXTRACTOR = '__uninitialized__'
---> 42 class ContextRCNNMetaArch(faster_rcnn_meta_arch.FasterRCNNMetaArch):
     43   """Context R-CNN Meta-architecture definition."""
     45   def __init__(self,
     46                is_training,
     47                num_classes,
   (...)
     95                    faster_rcnn_pb2.AttentionPosition.POST_BOX_CLASSIFIER)
     96                ):

File ~\anaconda3\envs\anprsys\lib\site-packages\object_detection\meta_architectures\context_rcnn_meta_arch.py:95, in ContextRCNNMetaArch()
     42 class ContextRCNNMetaArch(faster_rcnn_meta_arch.FasterRCNNMetaArch):
     43   """Context R-CNN Meta-architecture definition."""
     45   def __init__(self,
     46                is_training,
     47                num_classes,
     48                image_resizer_fn,
     49                feature_extractor,
     50                number_of_stages,
     51                first_stage_anchor_generator,
     52                first_stage_target_assigner,
     53                first_stage_atrous_rate,
     54                first_stage_box_predictor_arg_scope_fn,
     55                first_stage_box_predictor_kernel_size,
     56                first_stage_box_predictor_depth,
     57                first_stage_minibatch_size,
     58                first_stage_sampler,
     59                first_stage_non_max_suppression_fn,
     60                first_stage_max_proposals,
     61                first_stage_localization_loss_weight,
     62                first_stage_objectness_loss_weight,
     63                crop_and_resize_fn,
     64                initial_crop_size,
     65                maxpool_kernel_size,
     66                maxpool_stride,
     67                second_stage_target_assigner,
     68                second_stage_mask_rcnn_box_predictor,
     69                second_stage_batch_size,
     70                second_stage_sampler,
     71                second_stage_non_max_suppression_fn,
     72                second_stage_score_conversion_fn,
     73                second_stage_localization_loss_weight,
     74                second_stage_classification_loss_weight,
     75                second_stage_classification_loss,
     76                second_stage_mask_prediction_loss_weight=1.0,
     77                hard_example_miner=None,
     78                parallel_iterations=16,
     79                add_summaries=True,
     80                clip_anchors_to_image=False,
     81                use_static_shapes=False,
     82                resize_masks=True,
     83                freeze_batchnorm=False,
     84                return_raw_detections_during_predict=False,
     85                output_final_box_features=False,
     86                output_final_box_rpn_features=False,
     87                attention_bottleneck_dimension=None,
     88                attention_temperature=None,
     89                use_self_attention=False,
     90                use_long_term_attention=True,
     91                self_attention_in_sequence=False,
     92                num_attention_heads=1,
     93                num_attention_layers=1,
     94                attention_position=(
---> 95                    faster_rcnn_pb2.AttentionPosition.POST_BOX_CLASSIFIER)
     96                ):
     97     """ContextRCNNMetaArch Constructor.
     98 
     99     Args:
   (...)
    253         grid_anchor_generator.GridAnchorGenerator.
    254     """
    255     super(ContextRCNNMetaArch, self).__init__(
    256         is_training,
    257         num_classes,
   (...)
    297         output_final_box_features=output_final_box_features,
    298         output_final_box_rpn_features=output_final_box_rpn_features)

AttributeError: module 'object_detection.protos.faster_rcnn_pb2' has no attribute 'AttentionPosition'

I went through the context_rcnn_meta_arch.py and seems like the attribute called 'AttentionPosition' is not present.

I have also cd models/research into C:\Users\USER\anaconda3\envs\anprsys\Lib\site-packages\models\research\ and also pasted the protoc.exe and ranprotoc object_detection/protos/*.proto --python_out=.

I am using Python version 3.9 with this project(since for Python 3.10 I was getting a sentencepiece error) and my tensorflow version is 2.8.0.

Please help regarding this problem.

arshanabbas commented 2 years ago

Is this error resolved? I am also facing the same problem!

imps1001 commented 1 year ago

Is this error resolved? I am also facing this issue.

HNanditha commented 1 year ago

AttributeError: module 'object_detection.protos.faster_rcnn_pb2' has no attribute 'AttentionPosition'

I am also getting the same error , please do help me.

a-sajjad72 commented 3 months ago

still getting error conda environment Python 3.10.14 Tensorflow Version: 2.13.1 object_detection Version: 0.1

testing the object_detection installation python object_detection/builders/model_builder_tf1_test.py