예제 #1
0
p_eval, h_eval, y_eval = load_char_data('input/dev.csv', data_size=None)

p_holder = tf.placeholder(dtype=tf.int32,
                          shape=(None, args.seq_length),
                          name='p')
h_holder = tf.placeholder(dtype=tf.int32,
                          shape=(None, args.seq_length),
                          name='h')
y_holder = tf.placeholder(dtype=tf.int32, shape=None, name='y')

dataset = tf.data.Dataset.from_tensor_slices((p_holder, h_holder, y_holder))
dataset = dataset.batch(args.batch_size).repeat(args.epochs)
iterator = dataset.make_initializable_iterator()
next_element = iterator.get_next()

model = Graph()
saver = tf.train.Saver()

config = tf.ConfigProto()
config.gpu_options.allow_growth = True
config.gpu_options.per_process_gpu_memory_fraction = 0.9

with tf.Session(config=config) as sess:
    sess.run(tf.global_variables_initializer())
    sess.run(iterator.initializer,
             feed_dict={
                 p_holder: p,
                 h_holder: h,
                 y_holder: y
             })
    steps = int(len(y) / args.batch_size)
예제 #2
0
    try:
        legacy_init_op = tf.group(tf.tables_initializer(),
                                  name='legacy_init_op')
        builder = saved_model_builder.SavedModelBuilder(export_path)
        builder.add_meta_graph_and_variables(
            session, [tag_constants.SERVING],
            clear_devices=True,
            signature_def_map={
                signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY:
                model_signature,
            },
            legacy_init_op=legacy_init_op)

        builder.save()
    except Exception as e:
        print("Fail to export saved model, exception: {}".format(e))


if __name__ == "__main__":

    graph2 = tf.Graph()
    with graph2.as_default():
        m = Graph()
        saver = tf.train.Saver()
    with tf.Session(graph=graph2) as session:
        saver.restore(session, "model/dssm_9.ckpt")  #加载ckpt模型
        export_model(session, m)

    #load_pb()