IndexError:保存keras模型时列出索引超出范围

时间:2018-06-28 10:46:22

标签: python tensorflow keras protocol-buffers tensorflow-android

我正在尝试通过以下代码保存Keras / Tensorflow模型:

qpdf --empty --pages file1.pdf file2.pdf -- merged.pdf

我从Jupyter Notebook中收到以下错误消息:

def export_model(saver, model, input_node_names, output_node_name):
    MODEL_NAME = 'lyme_model'
    tf.train.write_graph(K.get_session().graph_def, 'out', \
    MODEL_NAME + '_graph.pbtxt')

    saver.save(K.get_session(), 'out/' + MODEL_NAME + '.chkp')

    input_graph_path = 'out/'+MODEL_NAME+'.pbtxt'
    checkpoint_path = 'out/'+MODEL_NAME+'.chkp'
    input_saver_def_path = ""
    input_binary = False
    restore_op_name = "save/restore_all"
    filename_tensor_name = "save/Const:0"
    output_frozen_graph_name = 'out/frozen_'+MODEL_NAME+'.pb'
    clear_devices = True


    freeze_graph.freeze_graph(input_graph_path, input_saver_def_path,
                      input_binary, checkpoint_path, output_node_name,
                      restore_op_name, filename_tensor_name,
                      output_frozen_graph_name, clear_devices, "")


    input_graph_def = tf.GraphDef()
    with tf.gfile.Open('out/frozen_' + MODEL_NAME + '.pb', "rb") as f:
         input_graph_def.ParseFromString(f.read())

    output_graph_def = optimize_for_inference_lib.optimize_for_inference(
            input_graph_def, input_node_names, [output_node_name],
            tf.float32.as_datatype_enum)

    with tf.gfile.FastGFile('out/opt_' + MODEL_NAME + '.pb', "wb") as f:
         f.write(output_graph_def.SerializeToString())

    print("graph saved!")

export_model(tf.train.Saver(), model, ["input_1"], "prediction")

是什么引起了这个问题?我什至没有在任何地方看到列表操作,所以我想它们发生在Keras / Tensorflow后端的某个地方。想知道如何解决这个问题。谢谢!

P.S。 export_model()方法取自here

0 个答案:

没有答案