Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
107 Views

Support for TensorFlow Where operation

Hi.

While converting the model, I encountered the error in tf.where operation with one condition parameter, which should return the indexes to be passed on to tf.gather, tf.gather_nd functions.

Usage example

ix = tf.where(tf.equal (roi_level, level))
level_boxes = tf.gather_nd(boxes, ix)


Model Optimizer output ():

...

[ WARNING ] Instructions/layers that do not have attribute extractors:
[ WARNING ] Where (12)
[ WARNING ] roi_align_classifier/Where
[ WARNING ] roi_align_classifier/Where_1
[ WARNING ] roi_align_classifier/Where_2
[ WARNING ] roi_align_classifier/Where_3

...

[ 2020-06-29 11:40:52,725 ] [ DEBUG ] [ infer:128 ] --------------------
[ 2020-06-29 11:40:52,725 ] [ DEBUG ] [ infer:129 ] Partial infer for roi_align_classifier/Where_3
[ 2020-06-29 11:40:52,725 ] [ DEBUG ] [ infer:130 ] Op: Where
[ 2020-06-29 11:40:52,725 ] [ DEBUG ] [ infer:131 ] Inputs:
[ 2020-06-29 11:40:52,725 ] [ DEBUG ] [ infer:31 ] input[0]: shape = [ 1 1000], value = <UNKNOWN>
[ INFO ] Called "tf_native_tf_node_infer" for node "roi_align_classifier/Where_3"
[ 2020-06-29 11:40:52,726 ] [ DEBUG ] [ tf:226 ] Added placeholder with name 'roi_align_classifier/Equal_3_port_0_ie_placeholder'
[ 2020-06-29 11:40:52,726 ] [ DEBUG ] [ tf:239 ] update_input_in_pbs: replace input 'roi_align_classifier/Equal_3' with input 'roi_align_classifier/Equal_3_port_0_ie_placeholder'
[ 2020-06-29 11:40:52,726 ] [ DEBUG ] [ tf:247 ] Replacing input '0' of the node 'roi_align_classifier/Where_3' with placeholder 'roi_align_classifier/Equal_3_port_0_ie_placeholder'
[ ERROR ] Cannot infer shapes or values for node "roi_align_classifier/Where_3".
[ ERROR ] Input 0 of node roi_align_classifier/Where_3 was passed int32 from roi_align_classifier/Equal_3_port_0_ie_placeholder:0 incompatible with expected bool.
[ ERROR ]
[ ERROR ] It can happen due to bug in custom shape infer function <function tf_native_tf_node_infer at 0x7f6aadf82f28>.
[ ERROR ] Or because the node inputs have incorrect values/shapes.
[ ERROR ] Or because input shapes are incorrect (embedded to the model or passed via --input_shape).
[ 2020-06-29 11:40:52,733 ] [ DEBUG ] [ infer:196 ] Node "roi_align_classifier/Where_3" attributes: {'pb': name: "roi_align_classifier/Where_3"
op: "Where"
input: "roi_align_classifier/Equal_3_port_0_ie_placeholder"
attr {
key: "T"
value {
type: DT_BOOL
}
}
, '_in_ports': {0: {'control_flow': False}}, '_out_ports': {0: {'control_flow': False}}, 'kind': 'op', 'name': 'roi_align_classifier/Where_3', 'op': 'Where', 'infer': <function tf_native_tf_node_infer at 0x7f6aadf82f28>, 'is_output_reachable': True, 'is_undead': False, 'is_const_producer': False, 'is_partial_inferred': False}
[ ERROR ] Exception occurred during running replacer "REPLACEMENT_ID" (<class 'extensions.middle.PartialInfer.PartialInfer'>): Stopped shape/value propagation at "roi_align_classifier/Where_3" node.
For more information please refer to Model Optimizer FAQ (https://docs.openvinotoolkit.org/latest/_docs_MO_DG_prepare_model_Model_Optimizer_FAQ.html), question #38.
[ 2020-06-29 11:40:52,734 ] [ DEBUG ] [ main:325 ] Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/importer.py", line 501, in _import_graph_def_internal
graph._c_graph, serialized, options) # pylint: disable=protected-access
tensorflow.python.framework.errors_impl.InvalidArgumentError: Input 0 of node roi_align_classifier/Where_3 was passed int32 from roi_align_classifier/Equal_3_port_0_ie_placeholder:0 incompatible with expected bool.

Although support for tf.gather is declared at https://docs.openvinotoolkit.org/latest/_docs_MO_DG_prepare_model_convert_model_Convert_Model_From_T..., I could not find any operation that could somehow replace tf.where - get indices by some condition. I know that the Select (similar to tf.where with 3 arguments), and ROIPooling operations is implemented, but it does not fit in our model.

Please inform me if there is a method for implementing the functionality of the Where(condition) operation?

0 Kudos
1 Reply
Highlighted
Moderator
94 Views

Hi @Evgenii 

Indeed, tf.Where is not mentioned as one of supported TensorFlow operations. You can find the list of all supported TF operations here https://docs.openvinotoolkit.org/latest/_docs_MO_DG_prepare_model_Supported_Frameworks_Layers.html#t...

As a workaround, you could either use different operation for your model or implement Where operation as a custom layer. Please see more details on how to do this in https://docs.openvinotoolkit.org/latest/_docs_MO_DG_prepare_model_customize_model_optimizer_Customiz...

Hope this helps.

Best regards, Max.

0 Kudos