Mask_rcnn: ValueError: Tried to convert 'shape' to a tensor and failed. Error: None values not supported.

Created on 25 Oct 2018  路  22Comments  路  Source: matterport/Mask_RCNN

I am running the below step - on my work environment to reproduce the code (using the kaggle data set)

I spent some time and not able to figure it out. Please help me.

I am using pyhon 3.6 and keras - 2.1.6-tf version and Linux


Create model in inference modefrom - < inspect_nucleus_model.ipynb > file - I am trying to run the below code (with default setting) and getting the error (copied far below). I

with tf.device(DEVICE):

model = modellib.MaskRCNN(mode = "inference", model_dir = LOGS_DIR, config = config)


ValueError Traceback (most recent call last)
/miniconda/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py in _apply_op_helper(self, op_type_name, name, **keywords)
509 as_ref=input_arg.is_ref,
--> 510 preferred_dtype=default_dtype)
511 except TypeError as err:

/miniconda/lib/python3.6/site-packages/tensorflow/python/framework/ops.py in internal_convert_to_tensor(value, dtype, name, as_ref, preferred_dtype, ctx)
1106 if ret is None:
-> 1107 ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
1108

/miniconda/lib/python3.6/site-packages/tensorflow/python/ops/array_ops.py in _autopacking_conversion_function(v, dtype, name, as_ref)
959 return NotImplemented
--> 960 return _autopacking_helper(v, inferred_dtype, name or "packed")
961

/miniconda/lib/python3.6/site-packages/tensorflow/python/ops/array_ops.py in _autopacking_helper(list_or_tuple, dtype, name)
921 elems_as_tensors.append(
--> 922 constant_op.constant(elem, dtype=dtype, name=str(i)))
923 return gen_array_ops.pack(elems_as_tensors, name=scope)

/miniconda/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py in constant(value, dtype, shape, name, verify_shape)
195 tensor_util.make_tensor_proto(
--> 196 value, dtype=dtype, shape=shape, verify_shape=verify_shape))
197 dtype_value = attr_value_pb2.AttrValue(type=tensor_value.tensor.dtype)

/miniconda/lib/python3.6/site-packages/tensorflow/python/framework/tensor_util.py in make_tensor_proto(values, dtype, shape, verify_shape)
423 if values is None:
--> 424 raise ValueError("None values not supported.")
425 # if dtype is provided, forces numpy array to be the type

ValueError: None values not supported.

During handling of the above exception, another exception occurred:

ValueError Traceback (most recent call last)
/miniconda/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py in _apply_op_helper(self, op_type_name, name, **keywords)
523 observed = ops.internal_convert_to_tensor(
--> 524 values, as_ref=input_arg.is_ref).dtype.name
525 except ValueError as err:

/miniconda/lib/python3.6/site-packages/tensorflow/python/framework/ops.py in internal_convert_to_tensor(value, dtype, name, as_ref, preferred_dtype, ctx)
1106 if ret is None:
-> 1107 ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
1108

/miniconda/lib/python3.6/site-packages/tensorflow/python/ops/array_ops.py in _autopacking_conversion_function(v, dtype, name, as_ref)
959 return NotImplemented
--> 960 return _autopacking_helper(v, inferred_dtype, name or "packed")
961

/miniconda/lib/python3.6/site-packages/tensorflow/python/ops/array_ops.py in _autopacking_helper(list_or_tuple, dtype, name)
921 elems_as_tensors.append(
--> 922 constant_op.constant(elem, dtype=dtype, name=str(i)))
923 return gen_array_ops.pack(elems_as_tensors, name=scope)

/miniconda/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py in constant(value, dtype, shape, name, verify_shape)
195 tensor_util.make_tensor_proto(
--> 196 value, dtype=dtype, shape=shape, verify_shape=verify_shape))
197 dtype_value = attr_value_pb2.AttrValue(type=tensor_value.tensor.dtype)

/miniconda/lib/python3.6/site-packages/tensorflow/python/framework/tensor_util.py in make_tensor_proto(values, dtype, shape, verify_shape)
423 if values is None:
--> 424 raise ValueError("None values not supported.")
425 # if dtype is provided, forces numpy array to be the type

ValueError: None values not supported.

During handling of the above exception, another exception occurred:

ValueError Traceback (most recent call last)
in ()
2 print (LOGS_DIR)
3 with tf.device(DEVICE):
----> 4 model = modellib.MaskRCNN(mode = "inference", model_dir = LOGS_DIR, config = config)

/project/bioinformatics/Rajaram_lab/s183574/myCopy/Nuclei-Counting-Segmentation/mrcnn/model.py in __init__(self, mode, config, model_dir)
1839 self.model_dir = model_dir
1840 self.set_log_dir()
-> 1841 self.keras_model = self.build(mode=mode, config=config)
1842
1843 def build(self, mode, config):

/project/bioinformatics/Rajaram_lab/s183574/myCopy/Nuclei-Counting-Segmentation/mrcnn/model.py in build(self, mode, config)
2040 config.POOL_SIZE, config.NUM_CLASSES,
2041 train_bn=config.TRAIN_BN,
-> 2042 fc_layers_size=config.FPN_CLASSIF_FC_LAYERS_SIZE)
2043
2044 # Detections

/project/bioinformatics/Rajaram_lab/s183574/myCopy/Nuclei-Counting-Segmentation/mrcnn/model.py in fpn_classifier_graph(rois, feature_maps, image_meta, pool_size, num_classes, train_bn, fc_layers_size)
954 # Reshape to [batch, num_rois, NUM_CLASSES, (dy, dx, log(dh), log(dw))]
955 s = K.int_shape(x)
--> 956 mrcnn_bbox = KL.Reshape((s[1], num_classes, 4), name="mrcnn_bbox")(x)
957
958 return mrcnn_class_logits, mrcnn_probs, mrcnn_bbox

/miniconda/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py in __call__(self, inputs, args, *kwargs)
686
687 if not in_deferred_mode:
--> 688 outputs = self.call(inputs, args, *kwargs)
689 if outputs is None:
690 raise ValueError('A layer\'s call method should return a Tensor '

/miniconda/lib/python3.6/site-packages/tensorflow/python/keras/layers/core.py in call(self, inputs)
438 def call(self, inputs):
439 return array_ops.reshape(inputs,
--> 440 (array_ops.shape(inputs)[0],) + self.target_shape)
441
442 def get_config(self):

/miniconda/lib/python3.6/site-packages/tensorflow/python/ops/gen_array_ops.py in reshape(tensor, shape, name)
6195 if _ctx is None or not _ctx._eager_context.is_eager:
6196 _, _, _op = _op_def_lib._apply_op_helper(
-> 6197 "Reshape", tensor=tensor, shape=shape, name=name)
6198 _result = _op.outputs[:]
6199 _inputs_flat = _op.inputs

/miniconda/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py in _apply_op_helper(self, op_type_name, name, **keywords)
526 raise ValueError(
527 "Tried to convert '%s' to a tensor and failed. Error: %s" %
--> 528 (input_name, err))
529 prefix = ("Input '%s' of '%s' Op has type %s that does not match" %
530 (input_name, op_type_name, observed))

ValueError: Tried to convert 'shape' to a tensor and failed. Error: None values not supported.

as_ref=input_arg.is_ref,
--> 510 preferred_dtype=default_dtype)
511 except TypeError as err:

/miniconda/lib/python3.6/site-packages/tensorflow/python/framework/ops.py in internal_convert_to_tensor(value, dtype, name, as_ref, preferred_dtype, ctx)
1106 if ret is None:
-> 1107 ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
1108

/miniconda/lib/python3.6/site-packages/tensorflow/python/ops/array_ops.py in _autopacking_conversion_function(v, dtype, name, as_ref)
959 return NotImplemented
--> 960 return _autopacking_helper(v, inferred_dtype, name or "packed")
961

/miniconda/lib/python3.6/site-packages/tensorflow/python/ops/array_ops.py in _autopacking_helper(list_or_tuple, dtype, name)
921 elems_as_tensors.append(
--> 922 constant_op.constant(elem, dtype=dtype, name=str(i)))
923 return gen_array_ops.pack(elems_as_tensors, name=scope)

/miniconda/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py in constant(value, dtype, shape, name, verify_shape)
195 tensor_util.make_tensor_proto(
--> 196 value, dtype=dtype, shape=shape, verify_shape=verify_shape))
197 dtype_value = attr_value_pb2.AttrValue(type=tensor_value.tensor.dtype)

/miniconda/lib/python3.6/site-packages/tensorflow/python/framework/tensor_util.py in make_tensor_proto(values, dtype, shape, verify_shape)
423 if values is None:
--> 424 raise ValueError("None values not supported.")
425 # if dtype is provided, forces numpy array to be the type

ValueError: None values not supported.

During handling of the above exception, another exception occurred:

ValueError Traceback (most recent call last)
/miniconda/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py in _apply_op_helper(self, op_type_name, name, **keywords)
523 observed = ops.internal_convert_to_tensor(
--> 524 values, as_ref=input_arg.is_ref).dtype.name
525 except ValueError as err:

/miniconda/lib/python3.6/site-packages/tensorflow/python/framework/ops.py in internal_convert_to_tensor(value, dtype, name, as_ref, preferred_dtype, ctx)
1106 if ret is None:
-> 1107 ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
1108

/miniconda/lib/python3.6/site-packages/tensorflow/python/ops/array_ops.py in _autopacking_conversion_function(v, dtype, name, as_ref)
959 return NotImplemented
--> 960 return _autopacking_helper(v, inferred_dtype, name or "packed")
961

/miniconda/lib/python3.6/site-packages/tensorflow/python/ops/array_ops.py in _autopacking_helper(list_or_tuple, dtype, name)
921 elems_as_tensors.append(
--> 922 constant_op.constant(elem, dtype=dtype, name=str(i)))
923 return gen_array_ops.pack(elems_as_tensors, name=scope)

/miniconda/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py in constant(value, dtype, shape, name, verify_shape)
195 tensor_util.make_tensor_proto(
--> 196 value, dtype=dtype, shape=shape, verify_shape=verify_shape))
197 dtype_value = attr_value_pb2.AttrValue(type=tensor_value.tensor.dtype)

/miniconda/lib/python3.6/site-packages/tensorflow/python/framework/tensor_util.py in make_tensor_proto(values, dtype, shape, verify_shape)
423 if values is None:
--> 424 raise ValueError("None values not supported.")
425 # if dtype is provided, forces numpy array to be the type

ValueError: None values not supported.

During handling of the above exception, another exception occurred:

ValueError Traceback (most recent call last)
in ()
2 print (LOGS_DIR)
3 with tf.device(DEVICE):
----> 4 model = modellib.MaskRCNN(mode = "inference", model_dir = LOGS_DIR, config = config)

/project/bioinformatics/Rajaram_lab/s183574/myCopy/Nuclei-Counting-Segmentation/mrcnn/model.py in __init__(self, mode, config, model_dir)
1839 self.model_dir = model_dir
1840 self.set_log_dir()
-> 1841 self.keras_model = self.build(mode=mode, config=config)
1842
1843 def build(self, mode, config):

/project/bioinformatics/Rajaram_lab/s183574/myCopy/Nuclei-Counting-Segmentation/mrcnn/model.py in build(self, mode, config)
2040 config.POOL_SIZE, config.NUM_CLASSES,
2041 train_bn=config.TRAIN_BN,
-> 2042 fc_layers_size=config.FPN_CLASSIF_FC_LAYERS_SIZE)
2043
2044 # Detections

/project/bioinformatics/Rajaram_lab/s183574/myCopy/Nuclei-Counting-Segmentation/mrcnn/model.py in fpn_classifier_graph(rois, feature_maps, image_meta, pool_size, num_classes, train_bn, fc_layers_size)
954 # Reshape to [batch, num_rois, NUM_CLASSES, (dy, dx, log(dh), log(dw))]
955 s = K.int_shape(x)
--> 956 mrcnn_bbox = KL.Reshape((s[1], num_classes, 4), name="mrcnn_bbox")(x)
957
958 return mrcnn_class_logits, mrcnn_probs, mrcnn_bbox

/miniconda/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py in __call__(self, inputs, args, *kwargs)
686
687 if not in_deferred_mode:
--> 688 outputs = self.call(inputs, args, *kwargs)
689 if outputs is None:
690 raise ValueError('A layer\'s call method should return a Tensor '

/miniconda/lib/python3.6/site-packages/tensorflow/python/keras/layers/core.py in call(self, inputs)
438 def call(self, inputs):
439 return array_ops.reshape(inputs,
--> 440 (array_ops.shape(inputs)[0],) + self.target_shape)
441
442 def get_config(self):

/miniconda/lib/python3.6/site-packages/tensorflow/python/ops/gen_array_ops.py in reshape(tensor, shape, name)
6195 if _ctx is None or not _ctx._eager_context.is_eager:
6196 _, _, _op = _op_def_lib._apply_op_helper(
-> 6197 "Reshape", tensor=tensor, shape=shape, name=name)
6198 _result = _op.outputs[:]
6199 _inputs_flat = _op.inputs

/miniconda/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py in _apply_op_helper(self, op_type_name, name, **keywords)
526 raise ValueError(
527 "Tried to convert '%s' to a tensor and failed. Error: %s" %
--> 528 (input_name, err))
529 prefix = ("Input '%s' of '%s' Op has type %s that does not match" %
530 (input_name, op_type_name, observed))

ValueError: Tried to convert 'shape' to a tensor and failed. Error: None values not supported.

Most helpful comment

If you want to use tf.keras or from tensorflow import keras, all you have to do to fix this error is replace the first value (s[1] == None) in the tf.keras.layers.Reshape function with -1:

Replace with the following code:

mrcnn_bbox = layers.Reshape((-1, num_classes, 4), name="mrcnn_bbox")(x)

All 22 comments

Has anybody got this problem before ????

Hi @ShibaPrasad! I'm running into a similar problem, did you managed to find the problem? :)

Hi GianKiMoon,
Yes, I am able to resolve - by installing a few more software (Linus) in your environment. I used all the keras packages and it worked smoothly.

@ShibaPrasad
how to fix this problem?

I had the same problem using the Keras package embbedded in Tensorflow.
Importing Tensorflow and Keras separately solved the problem.

If you want to use tf.keras or from tensorflow import keras, all you have to do to fix this error is replace the first value (s[1] == None) in the tf.keras.layers.Reshape function with -1:

Replace with the following code:

mrcnn_bbox = layers.Reshape((-1, num_classes, 4), name="mrcnn_bbox")(x)

If you want to use tf.keras or from tensorflow import keras, all you have to do to fix this error is replace the first value (s[1] == None) in the tf.keras.layers.Reshape function with -1:

Replace with the following code:

mrcnn_bbox = layers.Reshape((-1, num_classes, 4), name="mrcnn_bbox")(x)

@deluongo
I have the same problem, thanks for your comments.

However, you mean, I have to write like this:

if s[1]==None:
mrcnn_bbox = layers.Reshape((-1, num_classes, 4), name="mrcnn_bbox")(x)
else:
mrcnn_bbox = layers.Reshape((s[1], num_classes, 4), name="mrcnn_bbox")(x)

Am I right?

But the result will be same or any bad effect there on the result after changing?

Thanks

I have the same problem.

\Anaconda3\lib\site-packages\tensorflow_core\python\framework\tensor_util.py:437 make_tensor_proto
raise ValueError("None values not supported.")

ValueError: None values not supported.

Source=mrcnnmodel.py
StackTrace:
File "mrcnnmodel.py", line 2042, in build
[rpn_rois, mrcnn_class, mrcnn_bbox, input_image_meta])
File "mrcnnmodel.py", line 1835, in __init__
self.keras_model = self.build(mode=mode, config=config)
File "Mask_R_CNN_demo.py", line 140, in
rcnn = MaskRCNN(mode='inference', model_dir='./', config=TestConfig())

If you want to use tf.keras or from tensorflow import keras, all you have to do to fix this error is replace the first value (s[1] == None) in the tf.keras.layers.Reshape function with -1:

Replace with the following code:

mrcnn_bbox = layers.Reshape((-1, num_classes, 4), name="mrcnn_bbox")(x)

I did as you wrote, but I got another error :
ValueError: None values not supported.

@deluongo @ibrahimLearning Hi, I am also in the process of converting model.py from Keras to tf.keras. I've attempted the fix proposed by @deluongo above, but I am running into a further error when I implement:

ValueError                                Traceback (most recent call last)
<ipython-input-5-2ba0790b0ffe> in <module>
      2 model = modellib.MaskRCNN(mode="inference", 
      3                           config=inference_config,
----> 4                           model_dir=model_path)
      5 
      6 print("Loading weights from ", model_path)

~/dolphin-recognition/Mask_RCNN-master/mrcnn/model.py in __init__(self, mode, config, model_dir)
   1856         self.model_dir = model_dir
   1857         self.set_log_dir()
-> 1858         self.keras_model = self.build(mode=mode, config=config)
   1859 
   1860     def build(self, mode, config):

~/dolphin-recognition/Mask_RCNN-master/mrcnn/model.py in build(self, mode, config)
   2064             # normalized coordinates
   2065             detections = DetectionLayer(config, name="mrcnn_detection")(
-> 2066                 [rpn_rois, mrcnn_class, mrcnn_bbox, input_image_meta])
   2067 
   2068             # Create masks for detections

~/.virtualenvs/scorecam/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py in __call__(self, inputs, *args, **kwargs)
    632                     outputs = base_layer_utils.mark_as_return(outputs, acd)
    633                 else:
--> 634                   outputs = call_fn(inputs, *args, **kwargs)
    635 
    636             except TypeError as e:

~/.virtualenvs/scorecam/lib/python3.6/site-packages/tensorflow/python/autograph/impl/api.py in wrapper(*args, **kwargs)
    147       except Exception as e:  # pylint:disable=broad-except
    148         if hasattr(e, 'ag_error_metadata'):
--> 149           raise e.ag_error_metadata.to_exception(type(e))
    150         else:
    151           raise

ValueError: in converted code:

    /home/b3020111/dolphin-recognition/Mask_RCNN-master/mrcnn/model.py:826 call *
        detections_batch = utils.batch_slice(
    /home/b3020111/dolphin-recognition/Mask_RCNN-master/mrcnn/utils.py:821 batch_slice *
        output_slice = graph_fn(*inputs_slice)
    /tmp/tmppziso32p.py:15 None *
        detections_batch = ag__.converted_call('batch_slice', utils, ag__.ConversionOptions(recursive=True, force_conversion=False, optional_features=(), internal_convert_user_code=True), ([rois, mrcnn_class, mrcnn_bbox, window], lambda x, y, w, z: ag__.converted_call(refine_detections_graph, None, ag__.ConversionOptions(recursive=True, force_conversion=False, optional_features=(), internal_convert_user_code=True), (x, y, w, z, self.config), None), self.config.IMAGES_PER_GPU), None)
    /home/b3020111/dolphin-recognition/Mask_RCNN-master/mrcnn/model.py:712 refine_detections_graph *
        indices = tf.stack([tf.range(probs.shape[0]), class_ids], axis=1)
    /home/b3020111/.virtualenvs/scorecam/lib/python3.6/site-packages/tensorflow/python/ops/math_ops.py:1305 range
        limit = ops.convert_to_tensor(limit, dtype=dtype, name="limit")
    /home/b3020111/.virtualenvs/scorecam/lib/python3.6/site-packages/tensorflow/python/framework/ops.py:1087 convert_to_tensor
        return convert_to_tensor_v2(value, dtype, preferred_dtype, name)
    /home/b3020111/.virtualenvs/scorecam/lib/python3.6/site-packages/tensorflow/python/framework/ops.py:1145 convert_to_tensor_v2
        as_ref=False)
    /home/b3020111/.virtualenvs/scorecam/lib/python3.6/site-packages/tensorflow/python/framework/ops.py:1224 internal_convert_to_tensor
        ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
    /home/b3020111/.virtualenvs/scorecam/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py:358 _dimension_tensor_conversion_function
        raise ValueError("Cannot convert an unknown Dimension to a Tensor: %s" % d)

    ValueError: Cannot convert an unknown Dimension to a Tensor: ?

Is this something you have ran into and know how to overcome? My model.py file can be viewed here for reference. My tensofrlow version is 1.14, tf.keras version 2.2.4-tf.

Thank you in advance for any help or advice you can give :)

EDIT: After a bit of playing around, I seem to have fixed the issue. This can be achieved by changing line 714 of model.py from:

indices = tf.stack([tf.range(probs.shape[0]), class_ids], axis=1)

to

indices = tf.stack([tf.range(tf.shape(probs)[0]), class_ids], axis = 1)

I have the same problem.

\Anaconda3\lib\site-packages\tensorflow_core\python\framework\tensor_util.py:437 make_tensor_proto
raise ValueError("None values not supported.")

ValueError: None values not supported.

Source=mrcnnmodel.py
StackTrace:
File "mrcnnmodel.py", line 2042, in build
[rpn_rois, mrcnn_class, mrcnn_bbox, input_image_meta])
File "mrcnnmodel.py", line 1835, in init
self.keras_model = self.build(mode=mode, config=config)
File "Mask_R_CNN_demo.py", line 140, in
rcnn = MaskRCNN(mode='inference', model_dir='./', config=TestConfig())

If you want to use tf.keras or from tensorflow import keras, all you have to do to fix this error is replace the first value (s[1] == None) in the tf.keras.layers.Reshape function with -1:
Replace with the following code:
mrcnn_bbox = layers.Reshape((-1, num_classes, 4), name="mrcnn_bbox")(x)

I did as you wrote, but I got another error :
ValueError: None values not supported.

Hi,
i have the same issue please tell how to resolve it.

If you want to use tf.keras or from tensorflow import keras, all you have to do to fix this error is replace the first value (s[1] == None) in the tf.keras.layers.Reshape function with -1:
Replace with the following code:
mrcnn_bbox = layers.Reshape((-1, num_classes, 4), name="mrcnn_bbox")(x)

@deluongo
I have the same problem, thanks for your comments.

However, you mean, I have to write like this:

if s[1]==None:
mrcnn_bbox = layers.Reshape((-1, num_classes, 4), name="mrcnn_bbox")(x)
else:
mrcnn_bbox = layers.Reshape((s[1], num_classes, 4), name="mrcnn_bbox")(x)

Am I right?

But the result will be same or any bad effect there on the result after changing?

Thanks

i have the same issue & i followed as you said but getting error Value Error: None values not supported. . please tell me how to resolve this issue

Given all the open issues due to using deprecated version and that this repo is not maintained it should be marked as deprecated in the readme.md

Hi GianKiMoon,
Yes, I am able to resolve - by installing a few more software (Linus) in your environment. I used all the keras packages and it worked smoothly.

Hello @ShibaPrasad,
I am new to this. May I know which more libraries from keras packages to install ? A little bit confused because we are already importing entire keras package using import keras. I am also using linux system.

Thanking you in advance,
Krupal

The two edits given in the above comments worked for me (TF 2.2.0)

if s[1]==None:
mrcnn_bbox = layers.Reshape((-1, num_classes, 4), name="mrcnn_bbox")(x)
else:
mrcnn_bbox = layers.Reshape((s[1], num_classes, 4), name="mrcnn_bbox")(x)

indices = tf.stack([tf.range(tf.shape(probs)[0]), class_ids], axis = 1)

So thanks!

Hello,
i had the same problem using Colab few days ago, i tried a lot of possibilities
I managed to solve it using the correct version of tensorflow, so if you're using Colab, just make sure to introduce this line :
%tensorflow_version 1.x

It worked for me

Hello,
i had the same problem using Colab few days ago, i tried a lot of possibilities
I managed to solve it using the correct version of tensorflow, so if you're using Colab, just make sure to introduce this line :
%tensorflow_version 1.x

It worked for me

It worked! Just to clarify, you have to add the line before initializing tensorflow. If you are already in a runtime, you have to restart the runtime after adding the line.

There is no problem with TF1.14, however, for TF2.3, I got the problem.
It seems for the TF2.X, the Keras will not call the compute_output_shape.
I tried the most voted solution and still got an error. The following way solved my problem.
At the end of the call function for ProposalLayer class, add the following two lines to change the shape.
Then we will get rid of the None value as we change the
proposals shape from [None, None, 4] to [None, proposal_count, 4].

 proposals = tf.reshape(proposals, [-1, self.proposal_count, 4])
 scores_after_nms = tf.reshape(scores_after_nms, [-1, self.proposal_count])

Hope it helps.

Hello,
i had the same problem using Colab few days ago, i tried a lot of possibilities
I managed to solve it using the correct version of tensorflow, so if you're using Colab, just make sure to introduce this line :
%tensorflow_version 1.x
It worked for me

It worked! Just to clarify, you have to add the line before initializing tensorflow. If you are already in a runtime, you have to restart the runtime after adding the line.

Yes it works great !! Tried everything mentioned on this page above but none worked actually I wanted to use Tensorflow 2.X but even after editting a lot the model.py file but none.Will try to edit some more files so that it works for T 2.X versions if successful will update ans here.
https://docs.github.com/articles/github-community-guidelines

The following steps worked for me:

1. Upgrade the scripts by using the following line on the root folder:

tf_upgrade_v2 --intree Mask_RCNN --inplace --reportfile report.txt

This will automatically update the existing code to TF2. You will also get a list of changes made in report.txt

2. Replace the following line:

mrcnn_bbox = layers.Reshape((-1, num_classes, 4), name="mrcnn_bbox")(x)
with this this if-else code block:

if s[1]==None: mrcnn_bbox = layers.Reshape((-1, num_classes, 4), name="mrcnn_bbox")(x) else: mrcnn_bbox = layers.Reshape((s[1], num_classes, 4), name="mrcnn_bbox")(x)

3. Change the following line:

indices = tf.stack([tf.range(probs.shape[0]), class_ids], axis=1)
with this line:

indices = tf.stack([tf.range(tf.shape(probs)[0]), class_ids], axis = 1)

4. Now, you need to replace:

from keras import saving
with:

from tensorflow.python.keras import saving
then you will also want to replace the lines in both if and else block:

saving.load_weights_from_hdf5_group(f, layers)
and so on with the follwoing lines, inside if and else block respectively:

saving.hdf5_format.load_weights_from_hdf5_group_by_name(f, layers)

saving.hdf5_format.load_weights_from_hdf5_group(f, layers)

Thanks to: @deluongo, @Trotts, @nielsuit227, @ibrahimLearning

Hello,
i had the same problem using Colab few days ago, i tried a lot of possibilities
I managed to solve it using the correct version of tensorflow, so if you're using Colab, just make sure to introduce this line :
%tensorflow_version 1.x

It worked for me

This is the best solution for my pile of errors haha

There is no problem with TF1.14, however, for TF2.3, I got the problem.
It seems for the TF2.X, the Keras will not call the compute_output_shape.
I tried the most voted solution and still got an error. The following way solved my problem.
At the end of the call function for ProposalLayer class, add the following two lines to change the shape.
Then we will get rid of the None value as we change the
proposals shape from [None, None, 4] to [None, proposal_count, 4].

 proposals = tf.reshape(proposals, [-1, self.proposal_count, 4])
 scores_after_nms = tf.reshape(scores_after_nms, [-1, self.proposal_count])

Hope it helps.

Please mention exact locaion where to do this change

Was this page helpful?
0 / 5 - 0 ratings