matterport / Mask_RCNN

Mask R-CNN for object detection and instance segmentation on Keras and TensorFlow
Other
24.69k stars 11.71k forks source link

In line 72# Create model object in inference mode. model = modellib.MaskRCNN(mode="inference", model_dir=MODEL_DIR, config=config) # Load weights trained on MS-COCO model.load_weights(COCO_MODEL_PATH, by_name=True) #2184

Open Shamoonmohd opened 4 years ago

Shamoonmohd commented 4 years ago

in line 72 I got error of attribute AttributeError Traceback (most recent call last)

in 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) D:\Anaconda3\envs\mask_rcnn\lib\site-packages\mask_rcnn-2.1-py3.6.egg\mrcnn\model.py in __init__(self, mode, config, model_dir) 1835 self.model_dir = model_dir 1836 self.set_log_dir() -> 1837 self.keras_model = self.build(mode=mode, config=config) 1838 1839 def build(self, mode, config): D:\Anaconda3\envs\mask_rcnn\lib\site-packages\mask_rcnn-2.1-py3.6.egg\mrcnn\model.py in build(self, mode, config) 1854 # Inputs 1855 input_image = KL.Input( -> 1856 shape=[None, None, config.IMAGE_SHAPE[2]], name="input_image") 1857 input_image_meta = KL.Input(shape=[config.IMAGE_META_SIZE], 1858 name="input_image_meta") D:\Anaconda3\envs\mask_rcnn\lib\site-packages\keras\engine\input_layer.py in Input(shape, batch_shape, name, dtype, sparse, tensor) 176 name=name, dtype=dtype, 177 sparse=sparse, --> 178 input_tensor=tensor) 179 # Return tensor including _keras_shape and _keras_history. 180 # Note that in this case train_output and test_output are the same pointer. D:\Anaconda3\envs\mask_rcnn\lib\site-packages\keras\legacy\interfaces.py in wrapper(*args, **kwargs) 89 warnings.warn('Update your `' + object_name + '` call to the ' + 90 'Keras 2 API: ' + signature, stacklevel=2) ---> 91 return func(*args, **kwargs) 92 wrapper._original_function = func 93 return wrapper D:\Anaconda3\envs\mask_rcnn\lib\site-packages\keras\engine\input_layer.py in __init__(self, input_shape, batch_size, batch_input_shape, dtype, input_tensor, sparse, name) 85 dtype=dtype, 86 sparse=self.sparse, ---> 87 name=self.name) 88 else: 89 self.is_placeholder = False D:\Anaconda3\envs\mask_rcnn\lib\site-packages\keras\backend\tensorflow_backend.py in placeholder(shape, ndim, dtype, sparse, name) 515 x = tf.sparse_placeholder(dtype, shape=shape, name=name) 516 else: --> 517 x = tf.placeholder(dtype, shape=shape, name=name) 518 x._keras_shape = shape 519 x._uses_learning_phase = False AttributeError: module 'tensorflow' has no attribute 'placeholder'
innat commented 4 years ago

Can you please format the coed with a code snippet. And also what tensorflow and keras version you're using in which OS?

mobiuscreek commented 4 years ago

You probably use tensorflow 2 and mask rcnn uses tensorflow>=1.3.0 as you can see from the requirements.

morganaribeiro commented 4 years ago

Could someone give me a hint about some way to fix this error below @innat @mobiuscreek @Shamoonmohd ? Current version used:

  1. TensorFlow 1.13.1
  2. Keras 2.1.6
WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.
WARNING:tensorflow:From /content/gdrive/My Drive/Fish-characteristic-measurement/Complete_code/mrcnn/model.py:775: to_float (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.cast instead.
---------------------------------------------------------------------------
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)
   1658   try:
-> 1659     c_op = c_api.TF_FinishOperation(op_desc)
   1660   except errors.InvalidArgumentError as e:

InvalidArgumentError: Dimension 1 in both shapes must be equal, but are 8 and 324. Shapes are [1024,8] and [1024,324]. for 'Assign_682' (op: 'Assign') with input shapes: [1024,8], [1024,324].

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
11 frames
<ipython-input-6-466612329d97> in <module>()
     95 
     96 # Load weights trained on MS-COCO
---> 97 model.load_weights(COCO_MODEL_PATH, by_name=True)
     98 
     99 # COCO Class names

/content/gdrive/My Drive/Fish-characteristic-measurement/Complete_code/mrcnn/model.py in load_weights(self, filepath, by_name, exclude)
   2117 
   2118         if by_name:
-> 2119             topology.load_weights_from_hdf5_group_by_name(f, layers)
   2120         else:
   2121             topology.load_weights_from_hdf5_group(f, layers)

/usr/local/lib/python3.6/dist-packages/keras/engine/topology.py in load_weights_from_hdf5_group_by_name(f, layers, skip_mismatch, reshape)
   3477                                             weight_values[i]))
   3478 
-> 3479     K.batch_set_value(weight_value_tuples)

/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py in batch_set_value(tuples)
   2370                 assign_placeholder = tf.placeholder(tf_dtype,
   2371                                                     shape=value.shape)
-> 2372                 assign_op = x.assign(assign_placeholder)
   2373                 x._assign_placeholder = assign_placeholder
   2374                 x._assign_op = assign_op

/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/variables.py in assign(self, value, use_locking, name, read_value)
   1760     """
   1761     assign = state_ops.assign(self._variable, value, use_locking=use_locking,
-> 1762                               name=name)
   1763     if read_value:
   1764       return assign

/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/state_ops.py in assign(ref, value, validate_shape, use_locking, name)
    221     return gen_state_ops.assign(
    222         ref, value, use_locking=use_locking, name=name,
--> 223         validate_shape=validate_shape)
    224   return ref.assign(value, name=name)
    225 

/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/gen_state_ops.py in assign(ref, value, validate_shape, use_locking, name)
     62   _, _, _op = _op_def_lib._apply_op_helper(
     63         "Assign", ref=ref, value=value, validate_shape=validate_shape,
---> 64                   use_locking=use_locking, name=name)
     65   _result = _op.outputs[:]
     66   _inputs_flat = _op.inputs

/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/op_def_library.py in _apply_op_helper(self, op_type_name, name, **keywords)
    786         op = g.create_op(op_type_name, inputs, output_types, name=scope,
    787                          input_types=input_types, attrs=attr_protos,
--> 788                          op_def=op_def)
    789       return output_structure, op_def.is_stateful, op
    790 

/usr/local/lib/python3.6/dist-packages/tensorflow/python/util/deprecation.py in new_func(*args, **kwargs)
    505                 'in a future version' if date is None else ('after %s' % date),
    506                 instructions)
--> 507       return func(*args, **kwargs)
    508 
    509     doc = _add_deprecated_arg_notice_to_docstring(

/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py in create_op(***failed resolving arguments***)
   3298           input_types=input_types,
   3299           original_op=self._default_original_op,
-> 3300           op_def=op_def)
   3301       self._create_op_helper(ret, compute_device=compute_device)
   3302     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)
   1821           op_def, inputs, node_def.attr)
   1822       self._c_op = _create_c_op(self._graph, node_def, grouped_inputs,
-> 1823                                 control_input_ops)
   1824 
   1825     # Initialize self._outputs.

/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py in _create_c_op(graph, node_def, inputs, control_inputs)
   1660   except errors.InvalidArgumentError as e:
   1661     # Convert to ValueError for backwards compatibility.
-> 1662     raise ValueError(str(e))
   1663 
   1664   return c_op

ValueError: Dimension 1 in both shapes must be equal, but are 8 and 324. Shapes are [1024,8] and [1024,324]. for 'Assign_682' (op: 'Assign') with input shapes: [1024,8], [1024,324].