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
ValueError: Tried to convert 'shape' to a tensor and failed. Error: None values not supported. #1070
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, |
@ShibaPrasad |
I had the same problem using the Keras package embbedded in Tensorflow. |
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 However, you mean, I have to write like this:
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
Source=mrcnn\model.py |
I did as you wrote, but I got another error : |
@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:
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:
to
|
Hi, |
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 |
Hello @ShibaPrasad, Thanking you in advance, |
The two edits given in the above comments worked for me (TF 2.2.0)
So thanks! |
Hello, 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.
Hope it helps. |
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. |
The following steps worked for me: 1. Upgrade the scripts by using the following line on the root folder:
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:
3. Change the following line:
4. Now, you need to replace:
Thanks to: @deluongo, @Trotts, @nielsuit227, @IbrahimLearning |
This is the best solution for my pile of errors haha |
Please mention exact locaion where to do this change |
Hello I'm having the same issue! I don't have these line in my model.py, instead I have a similar one, which is the one that seems to be causing trouble: I'm a bit of a noob and I am a bit lost, please HELP. |
it is not working for me. |
It's in Feature Pyramid Network Heads section, line 951 if you are using the original scripts from matterport. @mayurmahurkar 's work around worked for me. |
matterport#1070 and matterport#1070 (comment) tensorflow/tensorflow#43982 and tensorflow/tensorflow#43982 (comment) matterport#2252 and matterport#2252 (comment) See the diff to see where everything was updated for 2021 using python 3 and latest versions of tensorflow and keras. As of this commit, the demo.ipynb runs and displays images as expected.
A bit late but if anyone else stumbles in here and have the same problem; if your layers are named "KL" - just replace
|
code change 1. import keras.engine as KE -> import keras.engine.topology as KE 2. from keras import saving -> from tensorflow.python.keras.saving import hdf5_format 3. saving.load_weights_from_hdf5_group(f, layers) -> hdf5_format.load_weights_from_hdf5_group(f, layers) 4. import tensorflow as tf -> import tensorflow.compat.v1 as tf 5. indices = tf.stack([tf.range(probs.shape[0]), class_ids], axis=1) -> indices = tf.stack([tf.range(tf.shape(probs)[0]), class_ids], axis = 1) 6. mrcnn_bbox = layers.Reshape((-1, num_classes, 4), name="mrcnn_bbox")(x) -> if s[1]==None: mrcnn_bbox = layers.Reshape((-1, num_classes, 4), name="mrcnn_bbox")(x) else: mrcnn_bbox = KL.Reshape((s[1], num_classes, 4), name="mrcnn_bbox")(x) 7. indices = tf.stack([tf.range(probs.shape[0]), class_ids], axis=1) -> indices = tf.stack([tf.range(tf.shape(probs)[0]), class_ids], axis = 1) 8. from keras import saving -> from tensorflow.python.keras import saving https://stackoverflow.com/questions/67905185/module-keras-engine-has-no-attribute-layer matterport#2252 (comment) matterport#1797 (comment) matterport#1070 (comment) matterport#1070 (comment)
The following steps worked for me:
if s[1]==None: Hello I'm having the same issue! I don't have these line in my model.py, instead I have a similar one, which is the one that seems to be causing trouble: I'm a bit of a noob and I am a bit lost, please HELP. A bit late but if anyone else stumbles in here and have the same problem; if your layers are named "KL" - just replace layers. in his solution with KL. So: if s[1]==None: i did all the changes but still getting an error as nameerror s is not defined plzz help |
Thank you everyone! Here, How it worked for me in all steps:
I did almost everything same, but there were some differences: In 4th one, I replaced the lines: replace the lines from: Thank youu!! |
Thanks a lot!! I was finally able to run demo.ipynb after grueling hours or looking at red text, which is big on its own 😵. I personally did all these in a virtual environment created in the Mask_RCNN directory, simply running pip install -r requirements.txt works fine if you follow the above steps and make those edits |
I read a few months back that Keras had been rolled back and is a part of TensorFlow now. Tried these changes and it worked amazingly. Thank you. |
Upgrade TensorFlow to 2.4.0 and Keras to 2.4.3. For further information about upgrading TensorFlow to 2.x you can check the following links: 1. matterport#1070 (comment) 2. https://stackoverflow.com/a/69806683
Just wondering, as there are clear fixes, why don't we just have another branch with tf version 2 support? |
There is another repo you can clone, with files updated to run for tf v2: |
@yashsandansing @ivarmak @BhavyaKohli Hi folks. Looks like you all were able to run Mask_RCNN on TF2, and inference worked fine for you so Im wondering what I'm missing. Are coco weights supposed to work out of the box in demo.ipynb or I have to train the model first? |
It has been a while since I have worked on this, but here is what I remember:
The coco weights are supposed to work without the need for training the model, unless you want inference on a custom dataset. I hope this helps, good luck! |
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.
The text was updated successfully, but these errors were encountered: