【发布时间】:2017-01-13 13:28:40
【问题描述】:
我尝试了一段时间让预训练模型在 android 上运行。问题是,我只得到了预训练网络的 ckpt 和元文件。在我看来,我需要 .pb 用于 android 应用程序。所以我尝试将给定的文件转换为 .pb 文件。
因此我尝试了 freeze_graph.py 但没有成功。所以我使用来自https://github.com/openimages/dataset/blob/master/tools/classify.py 的示例代码并对其进行修改以存储一个 pb。加载后的文件
if not os.path.exists(FLAGS.checkpoint):
tf.logging.fatal(
'Checkpoint %s does not exist. Have you download it? See tools/download_data.sh',
FLAGS.checkpoint)
g = tf.Graph()
with g.as_default():
input_image = tf.placeholder(tf.string)
processed_image = PreprocessImage(input_image)
with slim.arg_scope(inception.inception_v3_arg_scope()):
logits, end_points = inception.inception_v3(
processed_image, num_classes=FLAGS.num_classes, is_training=False)
predictions = end_points['multi_predictions'] = tf.nn.sigmoid(
logits, name='multi_predictions')
init_op = control_flow_ops.group(tf.global_variables_initializer(),
tf.global_variables_initializer(),
data_flow_ops.initialize_all_tables())
saver = tf_saver.Saver()
sess = tf.Session()
saver.restore(sess, FLAGS.checkpoint)
outpt_filename = 'output_graph.pb'
#output_graph_def = sess.graph.as_graph_def()
output_graph_def = graph_util.convert_variables_to_constants(sess, sess.graph.as_graph_def(), ["multi_predictions"])
with gfile.FastGFile(outpt_filename, 'wb') as f:
f.write(output_graph_def.SerializeToString())
现在我的问题是我有 .pb 文件,但我没有任何意见输入节点名称是什么,我不确定 multi_predictions 是否是正确的输出名称。在示例 android 应用程序中,我必须同时指定两者。安卓应用崩溃了:
tensorflow_inference_jni.cc:138 Could not create Tensorflow Graph: Invalid argument: No OpKernel was registered to support Op 'DecodeJpeg' with these attrs.
我不知道通过尝试修复 .pb 问题是否还有更多问题。或者,如果有人知道在我的情况下将 ckpt 和元文件移植到 .pd 文件的更好方法,或者知道带有输入和输出名称的最终文件的来源,请给我提示以完成此任务。
谢谢
【问题讨论】:
标签: android tensorflow