Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: module 'tensorflow' has no attribute 'log' #9

Open
fm64hylian opened this issue Jul 21, 2020 · 1 comment
Open

AttributeError: module 'tensorflow' has no attribute 'log' #9

fm64hylian opened this issue Jul 21, 2020 · 1 comment

Comments

@fm64hylian
Copy link

Hi, I was running the Demo-Image.ipynb and stumbled on this error when running [7] COCO dataset object names:

AttributeError                            Traceback (most recent call last)
<ipython-input-7-cbc8b676b8a3> in <module>
      1 # COCO dataset object names
----> 2 model = modellib.MaskRCNN(
      3     mode="inference", model_dir=MODEL_DIR, config=config
      4 )
      5 model.load_weights(COCO_MODEL_PATH, by_name=True)

~\Desktop\AR_test\models\pretrained-models\R-CNN-mask\Mask-RCNN-Shiny-master\mrcnn\model.py in __init__(self, mode, config, model_dir)
   1821         self.model_dir = model_dir
   1822         self.set_log_dir()
-> 1823         self.keras_model = self.build(mode=mode, config=config)
   1824 
   1825     def build(self, mode, config):

~\Desktop\AR_test\models\pretrained-models\R-CNN-mask\Mask-RCNN-Shiny-master\mrcnn\model.py in build(self, mode, config)
   2014             # Proposal classifier and BBox regressor heads
   2015             mrcnn_class_logits, mrcnn_class, mrcnn_bbox =\
-> 2016                 fpn_classifier_graph(rpn_rois, mrcnn_feature_maps, input_image_meta,
   2017                                      config.POOL_SIZE, config.NUM_CLASSES,
   2018                                      train_bn=config.TRAIN_BN)

~\Desktop\AR_test\models\pretrained-models\R-CNN-mask\Mask-RCNN-Shiny-master\mrcnn\model.py in fpn_classifier_graph(rois, feature_maps, image_meta, pool_size, num_classes, train_bn)
    916     # ROI Pooling
    917     # Shape: [batch, num_boxes, pool_height, pool_width, channels]
--> 918     x = PyramidROIAlign([pool_size, pool_size],
    919                         name="roi_align_classifier")([rois, image_meta] + feature_maps)
    920     # Two 1024 FC layers (implemented with Conv2D for consistency)

c:\users\tukuru0005\pythonstuff\envs\imageseg\lib\site-packages\tensorflow\python\keras\engine\base_layer.py in __call__(self, *args, **kwargs)
    920                     not base_layer_utils.is_in_eager_or_tf_function()):
    921                   with auto_control_deps.AutomaticControlDependencies() as acd:
--> 922                     outputs = call_fn(cast_inputs, *args, **kwargs)
    923                     # Wrap Tensors in `outputs` in `tf.identity` to avoid
    924                     # circular dependencies.

c:\users\tukuru0005\pythonstuff\envs\imageseg\lib\site-packages\tensorflow\python\autograph\impl\api.py in wrapper(*args, **kwargs)
    263       except Exception as e:  # pylint:disable=broad-except
    264         if hasattr(e, 'ag_error_metadata'):
--> 265           raise e.ag_error_metadata.to_exception(e)
    266         else:
    267           raise

AttributeError: in user code:

    C:\Users\tukuru0005\Desktop\AR_test\models\pretrained-models\R-CNN-mask\Mask-RCNN-Shiny-master\mrcnn\model.py:387 call  *
        roi_level = log2_graph(tf.sqrt(h * w) / (224.0 / tf.sqrt(image_area)))
    C:\Users\tukuru0005\Desktop\AR_test\models\pretrained-models\R-CNN-mask\Mask-RCNN-Shiny-master\mrcnn\model.py:338 log2_graph  *
        return tf.log(x) / tf.log(2.0)

    AttributeError: module 'tensorflow' has no attribute 'log'

I tried both my PC (using different tensorflow versions) and google colab but it throws a similar error on colab:

AttributeError                            Traceback (most recent call last)
<ipython-input-21-cbc8b676b8a3> in <module>()
      1 # COCO dataset object names
      2 model = modellib.MaskRCNN(
----> 3     mode="inference", model_dir=MODEL_DIR, config=config
      4 )
      5 model.load_weights(COCO_MODEL_PATH, by_name=True)

6 frames
/content/Mask-RCNN-Shiny/mrcnn/model.py in __init__(self, mode, config, model_dir)
   1821         self.model_dir = model_dir
   1822         self.set_log_dir()
-> 1823         self.keras_model = self.build(mode=mode, config=config)
   1824 
   1825     def build(self, mode, config):

/content/Mask-RCNN-Shiny/mrcnn/model.py in build(self, mode, config)
   2016                 fpn_classifier_graph(rpn_rois, mrcnn_feature_maps, input_image_meta,
   2017                                      config.POOL_SIZE, config.NUM_CLASSES,
-> 2018                                      train_bn=config.TRAIN_BN)
   2019 
   2020             # Detections

/content/Mask-RCNN-Shiny/mrcnn/model.py in fpn_classifier_graph(rois, feature_maps, image_meta, pool_size, num_classes, train_bn)
    917     # Shape: [batch, num_boxes, pool_height, pool_width, channels]
    918     x = PyramidROIAlign([pool_size, pool_size],
--> 919                         name="roi_align_classifier")([rois, image_meta] + feature_maps)
    920     # Two 1024 FC layers (implemented with Conv2D for consistency)
    921     x = KL.TimeDistributed(KL.Conv2D(1024, (pool_size, pool_size), padding="valid"),

/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py in symbolic_fn_wrapper(*args, **kwargs)
     73         if _SYMBOLIC_SCOPE.value:
     74             with get_graph().as_default():
---> 75                 return func(*args, **kwargs)
     76         else:
     77             return func(*args, **kwargs)

/usr/local/lib/python3.6/dist-packages/keras/engine/base_layer.py in __call__(self, inputs, **kwargs)
    487             # Actually call the layer,
    488             # collecting output(s), mask(s), and shape(s).
--> 489             output = self.call(inputs, **kwargs)
    490             output_mask = self.compute_mask(inputs, previous_mask)
    491 

/content/Mask-RCNN-Shiny/mrcnn/model.py in call(self, inputs)
    385         # e.g. a 224x224 ROI (in pixels) maps to P4
    386         image_area = tf.cast(image_shape[0] * image_shape[1], tf.float32)
--> 387         roi_level = log2_graph(tf.sqrt(h * w) / (224.0 / tf.sqrt(image_area)))
    388         roi_level = tf.minimum(5, tf.maximum(
    389             2, 4 + tf.cast(tf.round(roi_level), tf.int32)))

/content/Mask-RCNN-Shiny/mrcnn/model.py in log2_graph(x)
    336 def log2_graph(x):
    337     """Implementatin of Log2. TF doesn't have a native implemenation."""
--> 338     return tf.log(x) / tf.log(2.0)
    339 
    340 

AttributeError: module 'tensorflow' has no attribute 'log'

according to this reply we should replace tf.log() by tf.math.log(), I haven't tried it yet but it may be good to update the repository as well

@fm64hylian
Copy link
Author

after following the reply I replaced in model.py by:

#line 338
tf.log() -> tf.math.log()
#lines 716 and 754
tf.sets.set_intersection() -> tf.sets.intersection() 
#lines 718 and 756
tf.sparse_tensor_to_dense() -> tf.sparse.to_dense()
#line 768
tf.to_float() -> tf.cast([tf.gather(class_ids, keep)], tf.float32)[..., tf.newaxis]

and a new error appeared on the same section:

---------------------------------------------------------------------------
InvalidArgumentError                      Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py in _create_c_op(graph, node_def, inputs, control_inputs, op_def)
   1653   try:
-> 1654     c_op = pywrap_tf_session.TF_FinishOperation(op_desc)
   1655   except errors.InvalidArgumentError as e:

InvalidArgumentError: Shape must be rank 2 but is rank 3 for '{{node mrcnn_detection/concat_1}} = ConcatV2[N=3, T=DT_FLOAT, Tidx=DT_INT32](mrcnn_detection/GatherV2_6, mrcnn_detection/strided_slice_28, mrcnn_detection/strided_slice_29, mrcnn_detection/concat_1/axis)' with input shapes: [?,4], [1,?,1], [?,1], [].

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
16 frames
<ipython-input-10-cbc8b676b8a3> in <module>()
      1 # COCO dataset object names
      2 model = modellib.MaskRCNN(
----> 3     mode="inference", model_dir=MODEL_DIR, config=config
      4 )
      5 model.load_weights(COCO_MODEL_PATH, by_name=True)

/content/drive/My Drive/Mask-RCNN-Shiny-master/mrcnn/model.py in __init__(self, mode, config, model_dir)
   1821         self.model_dir = model_dir
   1822         self.set_log_dir()
-> 1823         self.keras_model = self.build(mode=mode, config=config)
   1824 
   1825     def build(self, mode, config):

/content/drive/My Drive/Mask-RCNN-Shiny-master/mrcnn/model.py in build(self, mode, config)
   2022             # normalized coordinates
   2023             detections = DetectionLayer(config, name="mrcnn_detection")(
-> 2024                 [rpn_rois, mrcnn_class, mrcnn_bbox, input_image_meta])
   2025 
   2026             # Create masks for detections

/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py in symbolic_fn_wrapper(*args, **kwargs)
     73         if _SYMBOLIC_SCOPE.value:
     74             with get_graph().as_default():
---> 75                 return func(*args, **kwargs)
     76         else:
     77             return func(*args, **kwargs)

/usr/local/lib/python3.6/dist-packages/keras/engine/base_layer.py in __call__(self, inputs, **kwargs)
    487             # Actually call the layer,
    488             # collecting output(s), mask(s), and shape(s).
--> 489             output = self.call(inputs, **kwargs)
    490             output_mask = self.compute_mask(inputs, previous_mask)
    491 

/content/drive/My Drive/Mask-RCNN-Shiny-master/mrcnn/model.py in call(self, inputs)
    807             [rois, mrcnn_class, mrcnn_bbox, window],
    808             lambda x, y, w, z: refine_detections_graph(x, y, w, z, self.config),
--> 809             self.config.IMAGES_PER_GPU)
    810 
    811         # Reshape output

/content/drive/My Drive/Mask-RCNN-Shiny-master/mrcnn/utils.py in batch_slice(inputs, graph_fn, batch_size, names)
    823     for i in range(batch_size):
    824         inputs_slice = [x[i] for x in inputs]
--> 825         output_slice = graph_fn(*inputs_slice)
    826         if not isinstance(output_slice, (tuple, list)):
    827             output_slice = [output_slice]

/content/drive/My Drive/Mask-RCNN-Shiny-master/mrcnn/model.py in <lambda>(x, y, w, z)
    806         detections_batch = utils.batch_slice(
    807             [rois, mrcnn_class, mrcnn_bbox, window],
--> 808             lambda x, y, w, z: refine_detections_graph(x, y, w, z, self.config),
    809             self.config.IMAGES_PER_GPU)
    810 

/content/drive/My Drive/Mask-RCNN-Shiny-master/mrcnn/model.py in refine_detections_graph(rois, probs, deltas, window, config)
    768         tf.cast([tf.gather(class_ids, keep)], tf.float32)[..., tf.newaxis],
    769         tf.gather(class_scores, keep)[..., tf.newaxis]
--> 770         ], axis=1)
    771 
    772     # Pad with zeros if detections < DETECTION_MAX_INSTANCES

/usr/local/lib/python3.6/dist-packages/tensorflow/python/util/dispatch.py in wrapper(*args, **kwargs)
    178     """Call target, and fall back on dispatchers if there is a TypeError."""
    179     try:
--> 180       return target(*args, **kwargs)
    181     except (TypeError, ValueError):
    182       # Note: convert_to_eager_tensor currently raises a ValueError, not a

/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/array_ops.py in concat(values, axis, name)
   1604           dtype=dtypes.int32).get_shape().assert_has_rank(0)
   1605       return identity(values[0], name=name)
-> 1606   return gen_array_ops.concat_v2(values=values, axis=axis, name=name)
   1607 
   1608 

/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/gen_array_ops.py in concat_v2(values, axis, name)
   1187   _attr_N = len(values)
   1188   _, _, _op, _outputs = _op_def_library._apply_op_helper(
-> 1189         "ConcatV2", values=values, axis=axis, name=name)
   1190   _result = _outputs[:]
   1191   if _execute.must_record_gradient():

/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/op_def_library.py in _apply_op_helper(op_type_name, name, **keywords)
    742       op = g._create_op_internal(op_type_name, inputs, dtypes=None,
    743                                  name=scope, input_types=input_types,
--> 744                                  attrs=attr_protos, op_def=op_def)
    745 
    746     # `outputs` is returned as a separate return value so that the output

/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/func_graph.py in _create_op_internal(self, op_type, inputs, dtypes, input_types, name, attrs, op_def, compute_device)
    593     return super(FuncGraph, self)._create_op_internal(  # pylint: disable=protected-access
    594         op_type, inputs, dtypes, input_types, name, attrs, op_def,
--> 595         compute_device)
    596 
    597   def capture(self, tensor, name=None, shape=None):

/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py in _create_op_internal(self, op_type, inputs, dtypes, input_types, name, attrs, op_def, compute_device)
   3325           input_types=input_types,
   3326           original_op=self._default_original_op,
-> 3327           op_def=op_def)
   3328       self._create_op_helper(ret, compute_device=compute_device)
   3329     return ret

/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py in __init__(self, node_def, g, inputs, output_types, control_inputs, input_types, original_op, op_def)
   1815         op_def = self._graph._get_op_def(node_def.op)
   1816       self._c_op = _create_c_op(self._graph, node_def, inputs,
-> 1817                                 control_input_ops, op_def)
   1818       name = compat.as_str(node_def.name)
   1819     # pylint: enable=protected-access

/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py in _create_c_op(graph, node_def, inputs, control_inputs, op_def)
   1655   except errors.InvalidArgumentError as e:
   1656     # Convert to ValueError for backwards compatibility.
-> 1657     raise ValueError(str(e))
   1658 
   1659   return c_op

ValueError: Shape must be rank 2 but is rank 3 for '{{node mrcnn_detection/concat_1}} = ConcatV2[N=3, T=DT_FLOAT, Tidx=DT_INT32](mrcnn_detection/GatherV2_6, mrcnn_detection/strided_slice_28, mrcnn_detection/strided_slice_29, mrcnn_detection/concat_1/axis)' with input shapes: [?,4], [1,?,1], [?,1], [].

I understand it has something to do with the dimensions but both test images had the same size, different channels. any ideas? should I close this issue and open a new one with this information?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant