Intel® Distribution of OpenVINO™ Toolkit
Community assistance about the Intel® Distribution of OpenVINO™ toolkit, OpenCV, and all aspects of computer vision-related on Intel® platforms.

Model Optimizer error: ConstSwitchResolver.ConstSwitchEraser


Hi guys,

i trained a SSD textbox detector in tensorflow by following this steps: . It uses their SSD512 network ( to predict bounding boxes around text snippes in an image.

I converted the trained keras model to a tensorflow .pb file and now i am trying to convert this graph with the Model Optimizer with this arguments:

python --input_model model/tf_model.pb --output_dir model/ --input_shape [1,512,512,3] --input "input_1" --output "predictions/concat" --log_level=DEBUG

Here is the trained model tf_model.pb:


Unfortunately, i got the following error:

I0903 12:32:30.234732  3004] Run replacer <class 'extensions.middle.ConstSwitchResolver.ConstSwitchEraser'>
E0903 12:32:30.291608  3004] -------------------------------------------------
E0903 12:32:30.291608  3004] ----------------- INTERNAL ERROR ----------------
E0903 12:32:30.292580  3004] Unexpected exception happened.
E0903 12:32:30.292580  3004] Please contact Model Optimizer developers and forward the following information:
E0903 12:32:30.293576  3004] Exception occurred during running replacer "REPLACEMENT_ID (<class 'extensions.middle.ConstSwitchResolver.ConstSwitchEraser'>)": 0
E0903 12:32:30.295570  3004] Traceback (most recent call last):
  File "C:\Program Files (x86)\IntelSWTools\openvino\deployment_tools\model_optimizer\mo\utils\", line 273, in apply_replacements
    for_graph_and_each_sub_graph_recursively(graph, replacer.find_and_replace_pattern)
  File "C:\Program Files (x86)\IntelSWTools\openvino\deployment_tools\model_optimizer\mo\middle\", line 58, in for_graph_and_each_sub_graph_recursively
  File "C:\Program Files (x86)\IntelSWTools\openvino\deployment_tools\model_optimizer\extensions\middle\", line 39, in find_and_replace_pattern
    remove_op_node_with_data_node(graph, switch_op_node)
  File "C:\Program Files (x86)\IntelSWTools\openvino\deployment_tools\model_optimizer\mo\middle\passes\", line 227, in remove_op_node_with_data_node
    input_data_node = node_to_remove.in_node()
  File "C:\Program Files (x86)\IntelSWTools\openvino\deployment_tools\model_optimizer\mo\graph\", line 174, in in_node
    return self.in_nodes(control_flow=control_flow)[key]
KeyError: 0

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Program Files (x86)\IntelSWTools\openvino\deployment_tools\model_optimizer\mo\", line 302, in main
    return driver(argv)
  File "C:\Program Files (x86)\IntelSWTools\openvino\deployment_tools\model_optimizer\mo\", line 251, in driver
    is_binary=not argv.input_model_is_text)
  File "C:\Program Files (x86)\IntelSWTools\openvino\deployment_tools\model_optimizer\mo\pipeline\", line 134, in tf2nx
    class_registration.apply_replacements(graph, class_registration.ClassType.MIDDLE_REPLACER)
  File "C:\Program Files (x86)\IntelSWTools\openvino\deployment_tools\model_optimizer\mo\utils\", line 299, in apply_replacements
    )) from err
Exception: Exception occurred during running replacer "REPLACEMENT_ID (<class 'extensions.middle.ConstSwitchResolver.ConstSwitchEraser'>)": 0

E0903 12:32:30.296602  3004] ---------------- END OF BUG REPORT --------------
E0903 12:32:30.297564  3004] -------------------------------------------------


There are some Tensorflow Object detection API configs for SSD models, which do not help me because of the different implementation. Can someone help me with this problem ?

Best regards





0 Kudos
2 Replies

Hi Lukas,

I think the model has to frozen before passing to Model Optimizer. Check the solution provided by my colleague in

0 Kudos

Dear G., Lukas,

First kindly make sure that the model is frozen. as Hemanth suggested. Please also post your log with --log_level DEBUG. The main thing I am wondering about, are there any -1 in your shapes preceding the error ? If so, Model Optimizer would be unable to infer shapes. If you see such -1 in the shape values (N,C,H,W)  or rather in Tensorflow's case, (N,H,W,C) then it's a problem - you need to fix that in your model before you move forward.

Let us know,




0 Kudos