如何将对象检测.h5实施到Google Ai平台中。在转换后的.pb文件的平台上出现错误消息

时间:2019-09-17 13:27:15

标签: python google-cloud-platform

我正在使用tinyyolov3预训练的.h5文件,并将.pb版本上传到Google Cloud AI平台。我按照创建proyect的步骤进行操作,但是保存时得到的提示是:“部署目录gs://-/-/应该包含以下内容之一:[saved_model.pb,saved_model.pbtxt]。”错误信息。

我正在How to export Keras .h5 to tensorflow .pb?中使用Frozen python函数将.h5模型转换为.pb。

def freeze_session(session, keep_var_names=None, output_names=None, clear_devices=True):
    """
    Freezes the state of a session into a pruned computation graph.

    Creates a new computation graph where variable nodes are replaced by
    constants taking their current value in the session. The new graph will be
    pruned so subgraphs that are not necessary to compute the requested
    outputs are removed.
    @param session The TensorFlow session to be frozen.
    @param keep_var_names A list of variable names that should not be frozen,
                          or None to freeze all the variables in the graph.
    @param output_names Names of the relevant graph outputs.
    @param clear_devices Remove the device directives from the graph for better portability.
    @return The frozen graph definition.
    """
    graph = session.graph
    with graph.as_default():
        freeze_var_names = list(set(v.op.name for v in tf.global_variables()).difference(keep_var_names or []))
        output_names = output_names or []
        output_names += [v.op.name for v in tf.global_variables()]
        input_graph_def = graph.as_graph_def()
        if clear_devices:
            for node in input_graph_def.node:
                node.device = ""
        frozen_graph = tf.graph_util.convert_variables_to_constants(
            session, input_graph_def, output_names, freeze_var_names)
        return frozen_graph

我将文件save_model.pb和saved_model.pbtxt上传到Google存储。然后,在Google平台中,我选择了该文件夹并按照说明进行操作,但是当我按下“保存”按钮时,出现了错误消息。我对分类模型使用了相同的过程,但效果很好,但不适用于此模型。

0 个答案:

没有答案