Mask_rcnn: ValueError: The channel dimension of the inputs should be defined. Found `None`. in demo.ipynb

Created on 6 Nov 2017  路  4Comments  路  Source: matterport/Mask_RCNN

Hey @waleedka

Great work. Now I have man-crush on you.

A little PSA. If anyone is getting this error:

ValueError: The channel dimension of the inputs should be defined. Found None.

you're most likely having backend issue ( in ~/.keras/keras.json), as it might be set to Theano instead of TF. And even if it it,s for some reason jupyter notebook is not reading it correctly.

Solution. You can do either

1) Before this cell is executed:

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)

you can add:

import keras.backend

K = keras.backend.backend()
if K=='tensorflow':
    keras.backend.set_image_dim_ordering('tf')

2) Stick it in ipython notebook startup file (~/.ipython/profile_default/startup/ ) like this guy

Most helpful comment

Hey guys,

I finally passed this error by this command below.

if K.backend()=='tensorflow':
    keras.backend.set_image_data_format("channels_last")

Add it before

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

My keras version is 2.3.1.

In version 2.3.1, there is no image_dim_ordering and set_image_dim_ordering.
So it should be replaced by set_image_data_format.

All 4 comments

Thx for sharing,This really helped!

Guys, which keras version was that?

Hey guys,

I finally passed this error by this command below.

if K.backend()=='tensorflow':
    keras.backend.set_image_data_format("channels_last")

Add it before

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

My keras version is 2.3.1.

In version 2.3.1, there is no image_dim_ordering and set_image_dim_ordering.
So it should be replaced by set_image_data_format.

I ran with the same error when trying to use the Mask_RCNN demo program. Keras backbone is set to tensorflow. I tried different version of Keras and Tensorflow but no luck. I got exact same error at the same location. Hope some of you have some solution.
import tensorflow as tf
import keras

print ("tensorflow_version ", tf.__version__," Keras_version: ", keras.__version__ )
import keras.backend as K
print ("keras backend: ", K.backend())
print ("K.image_data_format():", K.image_data_format())
print ("---------------------------------------------------------------------------")
model = modellib.MaskRCNN(mode="inference", model_dir=MODEL_DIR, config=config)
model.load_weights(COCO_MODEL_PATH, by_name=True)

tensorflow_version 1.14.0 Keras_version: 2.3.1
keras backend: tensorflow

K.image_data_format(): channels_last

WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/keras/backend/tensorflow_backend.py:4070: The name tf.nn.max_pool is deprecated. Please use tf.nn.max_pool2d instead.


ValueError Traceback (most recent call last)
in
9 print ("---------------------------------------------------------------------------")
10
---> 11 model = modellib.MaskRCNN(mode="inference", model_dir=MODEL_DIR, config=config)
12
13 # Load weights trained on MS-COCO

~/deep_vision/Mask_RCNN/mrcnn/model.py in __init__(self, mode, config, model_dir)
1848 self.model_dir = model_dir
1849 self.set_log_dir()
-> 1850 self.keras_model = self.build(mode=mode, config=config)
1851
1852 def build(self, mode, config):

~/deep_vision/Mask_RCNN/mrcnn/model.py in build(self, mode, config)
1951 # RPN Model
1952 rpn = build_rpn_model(config.RPN_ANCHOR_STRIDE,
-> 1953 len(config.RPN_ANCHOR_RATIOS), config.TOP_DOWN_PYRAMID_SIZE)
1954 # Loop through pyramid layers
1955 layer_outputs = [] # list of lists

~/deep_vision/Mask_RCNN/mrcnn/model.py in build_rpn_model(anchor_stride, anchors_per_location, depth)
903 input_feature_map = KL.Input(shape=[depth, None, None],
904 name="input_rpn_feature_map")
--> 905 outputs = rpn_graph(input_feature_map, anchors_per_location, anchor_stride)
906 return KM.Model([input_feature_map], outputs, name="rpn_model")
907

~/deep_vision/Mask_RCNN/mrcnn/model.py in rpn_graph(feature_map, anchors_per_location, anchor_stride)
859 shared = KL.Conv2D(512, (3, 3), padding='same', activation='relu',
860 strides=anchor_stride,
--> 861 name='rpn_conv_shared')(feature_map)
862
863 # Anchor Score. [batch, height, width, anchors per location * 2].

/usr/local/lib/python3.7/dist-packages/keras/engine/base_layer.py in __call__(self, inputs, **kwargs)
461 'You can build it manually via: '
462 'layer.build(batch_input_shape)')
--> 463 self.build(unpack_singleton(input_shapes))
464 self.built = True
465

/usr/local/lib/python3.7/dist-packages/keras/layers/convolutional.py in build(self, input_shape)
130 channel_axis = -1
131 if input_shape[channel_axis] is None:
--> 132 raise ValueError('The channel dimension of the inputs '
133 'should be defined. Found None.')
134 input_dim = input_shape[channel_axis]

ValueError: The channel dimension of the inputs should be defined. Found None.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

apptech-evan-huang picture apptech-evan-huang  路  3Comments

LifeBeyondExpectations picture LifeBeyondExpectations  路  4Comments

PaulChongPeng picture PaulChongPeng  路  4Comments

wjdhuster2018 picture wjdhuster2018  路  3Comments

Jargon4072 picture Jargon4072  路  3Comments