0

I've fine-tuned a model (using TF 1.9) from Object Detection Zoo Model and right now I am trying to freeze the graph for TensorFlowSharp using TF 1.9.

import tensorflow as tf
import os
from tensorflow.python.tools import freeze_graph
from tensorflow.core.protobuf import saver_pb2

#print("current tensorflow version: ", tf.version)
sess=tf.Session()

model_path = 'latest_cp/'
saver = tf.train.import_meta_graph('model.ckpt.meta')
saver.restore(sess,tf.train.latest_checkpoint('.')) #current dir of the checkpoint file
tf.train.write_graph(sess.graph_def, '.', 'test.pbtxt') #output in pbtxt format

freeze_graph.freeze_graph(input_graph = 'test.pbtxt',
    input_binary = False,
    input_checkpoint = model_path + 'model.ckpt',
    output_node_names =     "num_detections,detection_boxes,detection_scores,detection_classes",
    output_graph = 'test.bytes' ,
    clear_devices = True, initializer_nodes = "",input_saver = "",
    restore_op_name = "save/restore_all", filename_tensor_name = "save/Const:0")

It worked but then after I imported it to Unity it returned the following error:

TFException: Op type not registered 'NonMaxSuppressionV3' in binary running on AK38713. Make sure the Op and Kernel are registered in the binary running in this process.

I find out that TensorFlowSharp works with TensorFlow 1.4 and when I tried to freeze graph with 1.4 it returns the same NonMaxSuppressionV3 error. Do you know any way to solve this issue? Thank you so much for the support.

o.O
  • 491
  • 1
  • 10
  • 26
  • "when I tried to freeze graph with 1.4" you mean you installed TF 1.4 in Python and tried to export it? That should work, but you need to create the model with TF 1.4, not just restore it and export it. You don't necessarily have to retrain, though, you could run the original code to create the graph in 1.4, restore only the variables (not the whole metagraph) and export it. – jdehesa Nov 19 '18 at 17:13
  • 1
    If that is absolutely not an option (e.g. no code available), technically it could be possible to replace `NonMaxSuppressionV3` ops with a former version. Seems `NonMaxSuppressionV2` has been there since [1.3.0](https://github.com/tensorflow/tensorflow/commit/53cb26d05a5c2080d8022124178b1cc43a30ffe5), and looks like it has the same interface. However it's a bit of a messy path and there could still be other incompatible ops in the graph. – jdehesa Nov 19 '18 at 17:13

0 Answers0