AttributeError: module 'tensorflow._api.v2.sets' has no attribute 'set_intersection'

2.1k views Asked by At

Even though I tried, I couldn't solve this mistake.

https://www.youtube.com/watch?v=GSDbfGsxruA

I almost got to the last step when I added The Mask RCNN, but I'm stuck here.

Error Log

AttributeError                            Traceback (most recent call last)
<ipython-input-4-138183a2a830> in <module>
      1 # Create model object in inference mode.
----> 2 model = modellib.MaskRCNN(mode="inference", model_dir=MODEL_DIR, config=config)
      3 
      4 # Load weights trained on MS-COCO
      5 model.load_weights(COCO_MODEL_PATH, by_name=True)

~\**\Mask_RCNN\mrcnn\model.py in __init__(self, mode, config, model_dir)
   1838         self.model_dir = model_dir
   1839         self.set_log_dir()
-> 1840         self.keras_model = self.build(mode=mode, config=config)
   1841 
   1842     def build(self, mode, config):

~\**\Mask_RCNN\mrcnn\model.py in build(self, mode, config)
   2044             # output is [batch, num_detections, (y1, x1, y2, x2, class_id, score)] in
   2045             # normalized coordinates
-> 2046             detections = DetectionLayer(config, name="mrcnn_detection")(
   2047                 [rpn_rois, mrcnn_class, mrcnn_bbox, input_image_meta])
   2048 

**\anaconda3\lib\site-packages\tensorflow\python\keras\engine\base_layer.py in __call__(self, *args, **kwargs)
    949     # >> model = tf.keras.Model(inputs, outputs)
    950     if _in_functional_construction_mode(self, inputs, args, kwargs, input_list):
--> 951       return self._functional_construction_call(inputs, args, kwargs,
    952                                                 input_list)
    953 

**\anaconda3\lib\site-packages\tensorflow\python\keras\engine\base_layer.py in _functional_construction_call(self, inputs, args, kwargs, input_list)
   1088           layer=self, inputs=inputs, build_graph=True, training=training_value):
   1089         # Check input assumptions set after layer building, e.g. input shape.
-> 1090         outputs = self._keras_tensor_symbolic_call(
   1091             inputs, input_masks, args, kwargs)
   1092 

**\anaconda3\lib\site-packages\tensorflow\python\keras\engine\base_layer.py in _keras_tensor_symbolic_call(self, inputs, input_masks, args, kwargs)
    820       return nest.map_structure(keras_tensor.KerasTensor, output_signature)
    821     else:
--> 822       return self._infer_output_signature(inputs, args, kwargs, input_masks)
    823 
    824   def _infer_output_signature(self, inputs, args, kwargs, input_masks):

**\anaconda3\lib\site-packages\tensorflow\python\keras\engine\base_layer.py in _infer_output_signature(self, inputs, args, kwargs, input_masks)
    861           # TODO(kaftan): do we maybe_build here, or have we already done it?
    862           self._maybe_build(inputs)
--> 863           outputs = call_fn(inputs, *args, **kwargs)
    864 
    865         self._handle_activity_regularization(inputs, outputs)

**\anaconda3\lib\site-packages\tensorflow\python\autograph\impl\api.py in wrapper(*args, **kwargs)
    668       except Exception as e:  # pylint:disable=broad-except
    669         if hasattr(e, 'ag_error_metadata'):
--> 670           raise e.ag_error_metadata.to_exception(e)
    671         else:
    672           raise

AttributeError: in user code:

**\Mask_RCNN\mrcnn\model.py:810 call  *
    detections_batch = utils.batch_slice(
**\Mask_RCNN\mrcnn\utils.py:820 batch_slice  *
    output_slice = graph_fn(*inputs_slice)
**\Mask_RCNN\mrcnn\model.py:720 refine_detections_graph  *
    keep = tf.sets.set_intersection(tf.expand_dims(keep, 0),

AttributeError: module 'tensorflow._api.v2.sets' has no attribute 'set_intersection'

model.py arranged according to here.

https://github.com/matterport/Mask_RCNN/issues/1070#issuecomment-740430758

2

There are 2 answers

0
Jhon Wilker On

I managed to solve it by making the following substitutions, described in this link:https://github.com/tensorflow/tensorflow/issues/43982.

"tf.sets.set_intersection(...)

to:

tf.compat.v1.sets.set_intersection(...)

and:

import tensorflow as tf

to:

import tensorflow.compat.v1 as tf
0
AudioBubble On

As per the solution provided by SalahRahimi on GitHub regarding the same issue, the user was able to resolve the issue by doing the following changes.

The main issue here was the tensor flow version. mrcnn doesn't work with tensorflow.2.0, therefore I had to remove this version and re-install version 1.15. Note that it is not possible to install version 1.15 in Python3.8, so I switched to Python 3.7, which allowed me to install tensorflow 1.15. Now, this problem is resolved and I have been able to run the programme.