tensorflow / tensorflow/models

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

Open
#10,563 4 comments 0 reactions 3 assignees View on GitHub

Nobody has claimed this yet.

models:research type:bug
Dominant language
Python
Stars
77.7k
Forks
44.8k
PR merge metrics
No merged PRs in 30d

Description

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 ran protoc 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.