Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Dahan_H_Intel
Employee
69 Views

Model optimizer reports error when converting node ‘ExpandDims’

When I try to use model_optimizer to convert a tf model file xxx.pb to IR, there is always error log in 'ExpandDims':
[ 2018-06-06 21:53:16,206 ] [ DEBUG ] [ infer:70 ]  --------------------
[ 2018-06-06 21:53:16,207 ] [ DEBUG ] [ infer:71 ]  Partial infer for ExpandDims
[ 2018-06-06 21:53:16,207 ] [ DEBUG ] [ infer:72 ]  Op: ExpandDims
[ 2018-06-06 21:53:16,207 ] [ DEBUG ] [ infer:78 ]  Inputs:
[ 2018-06-06 21:53:16,207 ] [ DEBUG ] [ infer:39 ]  input[1]: shape = [], value = 0
[ 2018-06-06 21:53:16,207 ] [ DEBUG ] [ infer:39 ]  input[0]: shape = [480 640   3], value = <UNKNOWN>
[ 2018-06-06 21:53:16,207 ] [ DEBUG ] [ infer:80 ]  Outputs:
[ 2018-06-06 21:53:16,207 ] [ DEBUG ] [ infer:39 ]  output[0]: shape = <UNKNOWN>, value = <UNKNOWN>
[ 2018-06-06 21:53:16,207 ] [ ERROR ] [ infer:86 ]  Shape is not defined for output 0 of "ExpandDims".
[ 2018-06-06 21:53:16,207 ] [ ERROR ] [ infer:112 ]  Cannot infer shapes or values for node "ExpandDims".
[ 2018-06-06 21:53:16,208 ] [ ERROR ] [ infer:113 ]  Not all output shapes were inferred or fully defined for node "ExpandDims". For more information please refer to Model Optimizer FAQ, question #40.
[ 2018-06-06 21:53:16,208 ] [ ERROR ] [ infer:114 ]
[ 2018-06-06 21:53:16,208 ] [ ERROR ] [ infer:115 ]  It can happen due to bug in custom shape infer function <function tf_expand_dims_infer at 0x7f47a22056a8>.
[ 2018-06-06 21:53:16,208 ] [ ERROR ] [ infer:116 ]  Or because the node inputs have incorrect values/shapes.
[ 2018-06-06 21:53:16,208 ] [ ERROR ] [ infer:117 ]  Or because input shapes are incorrect (embedded to the model or passed via --input_shape).
[ 2018-06-06 21:53:16,208 ] [ DEBUG ] [ infer:121 ]  Node "ExpandDims" attributes: {'pb': name: "ExpandDims"
My node of "ExpandDims" description in 'pbtxt' is below:

node {
  name: "ExpandDims"
  op: "ExpandDims"
  input: "sub"
  input: "ExpandDims/dim"
  attr {
    key: "T"
    value {
      type: DT_FLOAT
    }
  }
  attr {
    key: "value"
    value {
      tensor {
        dtype: DT_FLOAT
        tensor_shape {
        }
      }
    }
  }
  attr {
    key: "Tdim"
    value {
      type: DT_INT32
    }
  }
}

Actually I found there are several similar threads on this node, and I have tried to add '--input_shape [1, 480, 640, 3]' and '--input ExpandDims' but no use for my case. Then I started to investigate python code in  model_optimizer/mo/front/common/partial_infer/expand_dims.py below:

import logging as log

import numpy as np


def tf_expand_dims_infer(node):
    input_shape = node.in_nodes()[0]
    axis = node.in_nodes()[1]
    output = node.out_node()

    if input_shape.value is None or axis.value is None:
        return

    if isinstance(axis.value, np.ndarray) and axis.value.size > 1:
        log.error("ExpandDims operation : axis should be scalar")
        return

    if len(input_shape.shape) == 0:
        output.value = input_shape.value.copy()
    else:
        output.value = np.insert(input_shape.value, axis.value[0], 1)
    output.shape = np.array(output.value.shape, dtype=np.int64)

The problem starts from input_shape.value, which is not defined since the value is inherited from the node's first input. So the first 'return' code will be executed. Even though I commented it and let the function runs to the end of the function, the output.value must use input_shape.value too in np.insert(), where the code still gaps into error.

I'm not quite sure if this is the root cause, but I wish to find a workaround to let the MO finish its execution. 

0 Kudos
3 Replies
Monique_J_Intel
Employee
69 Views

Hi Dahan,

Do you mind providing me the frozen .pb file that you are using so that I can reproduce the results?

Kind Regards,

Monique Jones

 

 

Dahan_H_Intel
Employee
69 Views

Hi Jones,

      I've share the compressed model file at https://drive.google.com/open?id=1jrbKtXQkN6A-7Tq0eI_72EH74R0NTqVd

      Could you please help to try mo on it?

Best Regards,

 

Monique_J_Intel
Employee
69 Views

Hi Dahan,

I will reproduce your issue today and see what we can do to resolve it.

Kind Regards,

Monique Jones