- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have frozen a simple and shortly trained LSTM model:
def gen_model(window_width=16000, LAYER_SIZE=15, HIDDEN_LAYER_COUNT=8): model = keras.Sequential() model.add(keras.layers.LSTM(LAYER_SIZE, input_shape=( window_width, 1), return_sequences=True)) for i in range(HIDDEN_LAYER_COUNT): model.add(keras.layers.LSTM(LAYER_SIZE, return_sequences=True)) model.add(keras.layers.Dense(1)) model.summary() model.compile(loss='mae', optimizer='adam') return model
I am freezing the model with:
from tensorflow.keras.models import load_model from tensorflow.python.framework import graph_io import tensorflow as tf from utils import convert_variables_to_constants # downloaded from https://github.com/intel-analytics/analytics-zoo/blob/master/pyzoo/zoo/util/tf_graph_util.py#L228 # Clear any previous session. tf.keras.backend.clear_session() model_dir = './results/' model_file = 'model_test' save_pb_dir = model_dir + model_file model_fname = model_dir + model_file + '/saved_model.h5' def freeze_graph(graph, session, output, save_pb_dir='.', save_pb_name='frozen_model.pb', save_pb_as_text=False): with graph.as_default(): graphdef_inf = tf.graph_util.remove_training_nodes( graph.as_graph_def()) graphdef_frozen = convert_variables_to_constants( session, graphdef_inf, output) graph_io.write_graph(graphdef_frozen, save_pb_dir, save_pb_name, as_text=save_pb_as_text) return graphdef_frozen # This line must be executed before loading Keras model. tf.keras.backend.set_learning_phase(0) model = load_model(model_fname) session = tf.keras.backend.get_session() INPUT_NODE = [t.op.name for t in model.inputs] OUTPUT_NODE = [t.op.name for t in model.outputs] print(INPUT_NODE, OUTPUT_NODE) frozen_graph = freeze_graph(session.graph, session, [ out.op.name for out in model.outputs], save_pb_dir=save_pb_dir)
Running it with TF1.14, also I already checked the freeze function and it worked for one custom made CNN model and produced the IR normally.
I run it like this:
sudo python3 ~/intel/openvino/deployment_tools/model_optimizer/mo_tf.py --input_model path_to_model/frozen_model.pb -b 1
The issue I get is:
[ ERROR ] Graph contains a cycle. Can not proceed.
Please help me, I am stuck on this and some prior errors for days. And after that I should make it run on a NCS2.
Any help would be appreciated, just say if you need more information.
Also, if there is any model suitable for (audio) anomaly detection (like LSTM's) and it definitely works with the optimizer please tell me.
Or some other way to get the NCS2 to inference my original (or some other) model.
Kind regards,
Marko.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Marko,
Thanks for reaching out. These types of recurrent models from Keras is currently not supported by the OpenVINO Toolkit. It may be possible to implement on TensorFlow, however, you will need to create a custom layers or TensorFlow alternatives if some layers are not supported.
Regards,
Jesus
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page