【问题标题】:Get Pretrained Inception v3 model from Open Images dataset working on Android从在 Android 上运行的 Open Images 数据集获取 Pretrained Inception v3 模型
【发布时间】: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


    【解决方案1】:

    您需要使用 optimize_for_inference.py 脚本来去除图中未使用的节点。 Android 不支持“decodeJpeg”——应该直接输入像素值。 ClassifierActivity.java 包含有关用于 inception v3 的特定节点的更多详细信息。

    【讨论】:

    • 抱歉,有点忙。您对使用 optimize_for_inference.py 的提示绝对正确,我可以使用“Mul”作为输入节点。非常感谢
    • 嗨@lampep 你是如何预处理你的图像的?我正在尝试在 ios 上运行它并且重复相同的预测。我遵循了您的代码,生成了优化的图表,但预测无法正常工作。谢谢!
    猜你喜欢
    • 2017-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-31
    • 1970-01-01
    • 2020-09-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多