matterport / Mask_RCNN

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

Error at - Create model in inference mode (Inside - inspect_nucleus_model.ipynb) #1091

Closed ShibaPrasad closed 6 years ago

ShibaPrasad commented 6 years ago

Hi, I am trying to run the below "Create model in inference mode" and Getting below error message (ValueError ). I am not able find out the exact solution. Please help me

Create model in inference mode

with tf.device(DEVICE): model = modellib.MaskRCNN(mode="inference", model_dir=LOGS_DIR,config=config)

Error message:


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 () 1 # Create model in inference mode 2 with tf.device(DEVICE): ----> 3 model = modellib.MaskRCNN(mode="inference", model_dir=LOGS_DIR, config=config) /project/bioinformatics/Rajaram_lab/s183574/myCopy/Nuclei-Counting-Segmentation/Mask_RCNN-master/mrcnn/model.py in __init__(self, mode, config, model_dir) 1834 self.model_dir = model_dir 1835 self.set_log_dir() -> 1836 self.keras_model = self.build(mode=mode, config=config) 1837 1838 def build(self, mode, config): /project/bioinformatics/Rajaram_lab/s183574/myCopy/Nuclei-Counting-Segmentation/Mask_RCNN-master/mrcnn/model.py in build(self, mode, config) 2035 config.POOL_SIZE, config.NUM_CLASSES, 2036 train_bn=config.TRAIN_BN, -> 2037 fc_layers_size=config.FPN_CLASSIF_FC_LAYERS_SIZE) 2038 2039 # Detections /project/bioinformatics/Rajaram_lab/s183574/myCopy/Nuclei-Counting-Segmentation/Mask_RCNN-master/mrcnn/model.py in fpn_classifier_graph(rois, feature_maps, image_meta, pool_size, num_classes, train_bn, fc_layers_size) 948 # Reshape to [batch, num_rois, NUM_CLASSES, (dy, dx, log(dh), log(dw))] 949 s = K.int_shape(x) --> 950 mrcnn_bbox = KL.Reshape((s[1], num_classes, 4), name="mrcnn_bbox")(x) 951 952 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.
ShibaPrasad commented 6 years ago

After debugging the code i am getting something like below? PLease let me know if that helps.

[<tf.Tensor 'fpn_p2/BiasAdd:0' shape=(?, ?, ?, 256) dtype=float32>, <tf.Tensor 'fpn_p3/BiasAdd:0' shape=(?, ?, ?, 256) dtype=float32>, <tf.Tensor 'fpn_p4/BiasAdd:0' shape=(?, ?, ?, 256) dtype=float32>, <tf.Tensor 'fpn_p5/BiasAdd:0' shape=(?, ?, ?, 256) dtype=float32>]

while executing the code at (model.py)

print("Inside build 6")

Top-down Layers

    # TODO: add assert to varify feature map sizes match what's in config
    P5 = KL.Conv2D(config.TOP_DOWN_PYRAMID_SIZE, (1, 1), name='fpn_c5p5')(C5)
    P4 = KL.Add(name="fpn_p4add")([KL.UpSampling2D(size=(2, 2), name="fpn_p5upsampled")(P5), KL.Conv2D(config.TOP_DOWN_PYRAMID_SIZE, (1, 1), name='fpn_c4p4')(C4)])
    P3 = KL.Add(name="fpn_p3add")([KL.UpSampling2D(size=(2, 2), name="fpn_p4upsampled")(P4), KL.Conv2D(config.TOP_DOWN_PYRAMID_SIZE, (1, 1), name='fpn_c3p3')(C3)])
    P2 = KL.Add(name="fpn_p2add")([KL.UpSampling2D(size=(2, 2), name="fpn_p3upsampled")(P3), KL.Conv2D(config.TOP_DOWN_PYRAMID_SIZE, (1, 1), name='fpn_c2p2')(C2)])

    # Attach 3x3 conv to all P layers to get the final feature maps.
    P2 = KL.Conv2D(config.TOP_DOWN_PYRAMID_SIZE, (3, 3), padding="SAME", name="fpn_p2")(P2)
    P3 = KL.Conv2D(config.TOP_DOWN_PYRAMID_SIZE, (3, 3), padding="SAME", name="fpn_p3")(P3)
    P4 = KL.Conv2D(config.TOP_DOWN_PYRAMID_SIZE, (3, 3), padding="SAME", name="fpn_p4")(P4)
    P5 = KL.Conv2D(config.TOP_DOWN_PYRAMID_SIZE, (3, 3), padding="SAME", name="fpn_p5")(P5)
    # P6 is used for the 5th anchor scale in RPN. Generated by
    # subsampling from P5 with stride of 2.
    P6 = KL.MaxPooling2D(pool_size=(1, 1), strides=2, name="fpn_p6")(P5)

    # Note that P6 is used in RPN, but not in the classifier heads.
    # print (P2)
    rpn_feature_maps = [P2, P3, P4, P5, P6]
    mrcnn_feature_maps = [P2, P3, P4, P5]
    print (mrcnn_feature_maps)
    print("Inside build 7")
keineahnung2345 commented 6 years ago

Could you add print(x) before line 950 in model.py and paste the result here? Thanks.

ShibaPrasad commented 6 years ago

I not getting output value of - x as exception thrown before that.

BBox head

# [batch, num_rois, NUM_CLASSES * (dy, dx, log(dh), log(dw))]
x = KL.TimeDistributed(KL.Dense(num_classes * 4, activation='linear'),
                       name='mrcnn_bbox_fc')(shared)
print("Values of x: in fpn_classifier_graph")
print(x)

just put above 2 line for display and got below output

Output:


ValueError Traceback (most recent call last) ~/.local/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:

~/.local/lib/python3.6/site-packages/tensorflow/python/framework/ops.py in internal_convert_to_tensor(value, dtype, name, as_ref, preferred_dtype, ctx) 1143 if ret is None: -> 1144 ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref) 1145

~/.local/lib/python3.6/site-packages/tensorflow/python/ops/array_ops.py in _autopacking_conversion_function(v, dtype, name, as_ref) 970 v = nest.map_structure(_cast_nested_seqs_to_dtype(dtype), v) --> 971 return _autopacking_helper(v, dtype, name or "packed") 972

~/.local/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)

~/.local/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py in constant(value, dtype, shape, name, verify_shape) 206 tensor_util.make_tensor_proto( --> 207 value, dtype=dtype, shape=shape, verify_shape=verify_shape)) 208 dtype_value = attr_value_pb2.AttrValue(type=tensor_value.tensor.dtype)

~/.local/lib/python3.6/site-packages/tensorflow/python/framework/tensor_util.py in make_tensor_proto(values, dtype, shape, verify_shape) 429 if values is None: --> 430 raise ValueError("None values not supported.") 431 # 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) ~/.local/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:

~/.local/lib/python3.6/site-packages/tensorflow/python/framework/ops.py in internal_convert_to_tensor(value, dtype, name, as_ref, preferred_dtype, ctx) 1143 if ret is None: -> 1144 ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref) 1145

~/.local/lib/python3.6/site-packages/tensorflow/python/ops/array_ops.py in _autopacking_conversion_function(v, dtype, name, as_ref) 970 v = nest.map_structure(_cast_nested_seqs_to_dtype(dtype), v) --> 971 return _autopacking_helper(v, dtype, name or "packed") 972

~/.local/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)

~/.local/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py in constant(value, dtype, shape, name, verify_shape) 206 tensor_util.make_tensor_proto( --> 207 value, dtype=dtype, shape=shape, verify_shape=verify_shape)) 208 dtype_value = attr_value_pb2.AttrValue(type=tensor_value.tensor.dtype)

~/.local/lib/python3.6/site-packages/tensorflow/python/framework/tensor_util.py in make_tensor_proto(values, dtype, shape, verify_shape) 429 if values is None: --> 430 raise ValueError("None values not supported.") 431 # 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 () 1 # Create model in inference mode 2 with tf.device(DEVICE): ----> 3 model = modellib.MaskRCNN(mode="inference", model_dir=LOGS_DIR, config=config) /project/bioinformatics/Rajaram_lab/s183574/myCopy/Nuclei-Counting-Segmentation/Mask_RCNN-master/mrcnn/model.py in __init__(self, mode, config, model_dir) 1820 self.mode = mode 1821 self.config = config -> 1822 self.model_dir = model_dir 1823 self.set_log_dir() 1824 self.keras_model = self.build(mode=mode, config=config) /project/bioinformatics/Rajaram_lab/s183574/myCopy/Nuclei-Counting-Segmentation/Mask_RCNN-master/mrcnn/model.py in build(self, mode, config) 2051 2052 -> 2053 mrcnn_class_logits, mrcnn_class, mrcnn_bbox =\ 2054 fpn_classifier_graph(rpn_rois, mrcnn_feature_maps, input_image_meta, 2055 config.POOL_SIZE, config.NUM_CLASSES, train_bn=config.TRAIN_BN, fc_layers_size=config.FPN_CLASSIF_FC_LAYERS_SIZE) /project/bioinformatics/Rajaram_lab/s183574/myCopy/Nuclei-Counting-Segmentation/Mask_RCNN-master/mrcnn/model.py in fpn_classifier_graph(rois, feature_maps, image_meta, pool_size, num_classes, train_bn, fc_layers_size) 935 print("Values of x: in fpn_classifier_graph") 936 print(x) --> 937 # Reshape to [batch, num_rois, NUM_CLASSES, (dy, dx, log(dh), log(dw))] 938 s = K.int_shape(x) 939 mrcnn_bbox = KL.Reshape((s[1], num_classes, 4), name="mrcnn_bbox")(x) ~/.local/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py in __call__(self, inputs, *args, **kwargs) 767 768 if not in_deferred_mode: --> 769 outputs = self.call(inputs, *args, **kwargs) 770 if outputs is None: 771 raise ValueError('A layer\'s `call` method should return a Tensor ' ~/.local/lib/python3.6/site-packages/tensorflow/python/keras/layers/core.py in call(self, inputs) 441 def call(self, inputs): 442 return array_ops.reshape(inputs, --> 443 (array_ops.shape(inputs)[0],) + self.target_shape) 444 445 def get_config(self): ~/.local/lib/python3.6/site-packages/tensorflow/python/ops/gen_array_ops.py in reshape(tensor, shape, name) 6294 if _ctx is None or not _ctx._eager_context.is_eager: 6295 _, _, _op = _op_def_lib._apply_op_helper( -> 6296 "Reshape", tensor=tensor, shape=shape, name=name) 6297 _result = _op.outputs[:] 6298 _inputs_flat = _op.inputs ~/.local/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.
ShibaPrasad commented 6 years ago

I am able to resolve the issue. Thank You.

keineahnung2345 commented 6 years ago

@ShibaPrasad How do you resolve this problem? Is it something to do with your input?

mzlt commented 5 years ago

Hi, I'm stuck on the same problem, @ShibaPrasad could you elaborate on your solution?

Nakeuh commented 5 years ago

Hi, same problem for me. Someone have the solution ?

shreyydesai commented 4 years ago

has anyone got the solution?