Error in compiling keras in relay.frontend.from_keras

I was trying to compile keras model by following tvm tutorial code

shape_dict = {'input_1': (1, 3, 12, 12)}
p_mod, p_params = relay.frontend.from_keras(p_net, shape_dict)

The structure of network that I want to compile like this…

(None, None, None, 3)
(None, None, None, 3)
(None, None, None, 10)
(None, None, None, 10)
(None, None, None, 10)
(None, None, None, 16)

But error comes out…

Traceback (most recent call last):

File "", line 43, in <module>
  p_mod, p_params = relay.frontend.from_keras(p_net, shape_dict)

  File "/home/tvm/python/tvm/relay/frontend/", line 864, in from_keras
    keras_op_to_relay(inexpr, keras_layer, + ':' + str(node_idx), etab)

  File "/home/tvm/python/tvm/relay/frontend/", line 756, in keras_op_to_relay
    outs = _convert_map[op_name](inexpr, keras_layer, etab)

  File "/home/tvm/python/tvm/relay/frontend/", line 400, in _convert_pooling
    pad_l, pad_r = _get_pad_pair(in_w, pool_w, stride_w)

  File "/home/tvm/python/tvm/relay/frontend/", line 42, in _get_pad_pair
    out1d = (input1d + stride1d - 1) // stride1d

TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'

Following that error,

I checked tvm/python/tvm/relay/frontend/ and looked _convert_pooling function.

I found keras_layer.input_shape[1] and keras_layer.input_shape[2] is None, so in_h and in_w is also None.

I guess that’s the reason I cannot compile, but I don’t get any clue of this.

Is there I missing something? Thanks in advance for your help.

The code below is code of _convert_pooling

def _convert_pooling(inexpr, keras_layer, etab):
    pool_type = type(keras_layer).__name__
    # global pool in keras = global pool + flatten in relay
    if pool_type == 'GlobalMaxPooling2D':
        return _convert_flatten(_op.nn.global_max_pool2d(inexpr), keras_layer, etab)
    if pool_type == 'GlobalAveragePooling2D':
        return _convert_flatten(_op.nn.global_avg_pool2d(inexpr), keras_layer, etab)
    pool_h, pool_w = keras_layer.pool_size
    stride_h, stride_w = keras_layer.strides
    params = {'pool_size': [pool_h, pool_w],
              'strides': [stride_h, stride_w],
              'padding': [0, 0]}
    if keras_layer.padding == 'valid':
    elif keras_layer.padding == 'same':
        in_h = keras_layer.input_shape[1]
        in_w = keras_layer.input_shape[2]
        # I guess this trigger error....
        pad_t, pad_b = _get_pad_pair(in_h, pool_h, stride_h)
        pad_l, pad_r = _get_pad_pair(in_w, pool_w, stride_w)
        params['padding'] = [pad_t, pad_l, pad_b, pad_r]