''' Created on 2019年1月15日 @author: User ''' import tensorflow as tf from tensorflow.contrib.crf import crf_log_likelihood path = "D://Anaconda3.4//envs//dl_nlp//fool//pos.pb" def loss_layer(project_logits,y_target,trans,max_steps): with tf.variable_scope("crf_loss1"): log_likelihood, trans = crf_log_likelihood(inputs=project_logits, tag_indices=y_target, transition_params=trans, sequence_lengths=max_steps) return tf.reduce_mean(-log_likelihood) def load_graph(path): with tf.gfile.GFile(path, mode='rb') as f: graph_def = tf.GraphDef() graph_def.ParseFromString(f.read()) for i,n in enumerate(graph_def.node): print("Name of the node - %s" % n.name) with tf.Graph().as_default() as graph: tf.import_graph_def(graph_def, name="prefix") return graph ''' with tf.gfile.GFile(path, mode='rb') as f: graph_def = tf.GraphDef() graph_def.ParseFromString(f.read()) for i,n in enumerate(graph_def.node): print("Name of the node - %s" % n.name) with tf.Graph().as_default() as graph: tf.import_graph_def(graph_def) trans = graph.get_tensor_by_name("prefix/crf_loss/transitions:0") logits = graph.get_tensor_by_name("prefix/project/logits:0") y_target = tf.placeholder() loss = loss_layer(logits, y_target, trans, 100) summaryWriter = tf.summary.FileWriter('log/', graph) #tf.Graph().get_operations() ''' def buildModel(): graph = load_graph(path) with graph.as_default(): trans = graph.get_tensor_by_name("prefix/crf_loss/transitions:0") lengths = graph.get_tensor_by_name("prefix/lengths:0") logits = graph.get_tensor_by_name("prefix/project/logits:0") print(logits) print(trans) y_target = tf.placeholder(dtype=tf.int32, shape=[None, None], name='y_target') #loss = loss_layer(logits, y_target, trans, lengths) summaryWriter = tf.summary.FileWriter('log/', graph) if __name__=="__main__": # import fool # a = fool.LEXICAL_ANALYSER # a._load_ner_model() # _dict = a.ner_model.id_to_tag # for _key in _dict.keys(): # print(_key,_dict[_key]) # load_graph(path) a = [1,2,3,44] print(a[-100:])