Resolve shape parameter and returns shape.

def resolve_reshape_params(inputs, function_proto, batch_size):
    '''Resolve shape parameter and returns shape.
    '''
    f = function_proto  # alias

    # There are 2 exceptional cases.
    # A. Negative dimension is batch dimension
    # A-1. Detect multiple negative dimensions (not allowed).
    negative_count = 0
    for d in f.reshape_param.shape.dim:
        if d < 0:
            negative_count += 1
    if negative_count > 1:
        raise ValueError('Reshape: shape has multiple negative number.')

    # A-2. Fill negative dimensions with batch size.
    shape = tuple(
        [d if d >= 0 else batch_size for d in f.reshape_param.shape.dim])

    # B. Console omits batch dimensions (the first dimension) during saving.
    # B-1. Fill with batch size if shapes don't match.
    if numpy.prod(shape) != numpy.prod(inputs[0].shape):
        shape = (batch_size,) + shape
        if numpy.prod(shape) != numpy.prod(inputs[0].shape):
            raise ValueError('Shape after filling batch dimension does not match the input shape. prod({}) != prod({})'.format(
                shape, inputs[0].shape))
    return shape