本文整理汇总了Python中cnn_model.TCNNConfig方法的典型用法代码示例。如果您正苦于以下问题:Python cnn_model.TCNNConfig方法的具体用法?Python cnn_model.TCNNConfig怎么用?Python cnn_model.TCNNConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cnn_model
的用法示例。
在下文中一共展示了cnn_model.TCNNConfig方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_model
# 需要导入模块: import cnn_model [as 别名]
# 或者: from cnn_model import TCNNConfig [as 别名]
def load_model(self):
sess = tf.Session()
print('Configuring CNN model...')
config = TCNNConfig()
cnn_model = TextCNN(config)
saver = tf.train.Saver()
params_file = tf.train.latest_checkpoint(self.model_dir)
saver.restore(sess, params_file)
categories, cat_to_id = read_category()
vocab_dir = 'cnews/cnews.vocab.txt'
words, word_to_id = read_vocab(vocab_dir)
self.words = words
self.word_to_id = word_to_id
self.categories = categories
self.cat_to_id = cat_to_id
self.cnn_model = cnn_model
self.sess = sess
print(self.cnn_model)
print(self.sess)
示例2: __init__
# 需要导入模块: import cnn_model [as 别名]
# 或者: from cnn_model import TCNNConfig [as 别名]
def __init__(self):
self.config = TCNNConfig()
self.categories, self.cat_to_id = read_category()
self.words, self.word_to_id = read_vocab(vocab_dir)
self.config.vocab_size = len(self.words)
self.model = TextCNN(self.config)
self.session = tf.Session()
self.session.run(tf.global_variables_initializer())
saver = tf.train.Saver()
saver.restore(sess=self.session, save_path=save_path) # 读取保存的模型
示例3: __init__
# 需要导入模块: import cnn_model [as 别名]
# 或者: from cnn_model import TCNNConfig [as 别名]
def __init__(self):
self.config = TCNNConfig()
self.categories, self.cat_to_id = read_category()
self.word_to_id = read_vocab(vocab_dir)
self.config.vocab_size = len(self.word_to_id)
self.model = TextCNN(self.config)
self.session = tf.Session()
self.session.run(tf.global_variables_initializer())
saver = tf.train.Saver()
saver.restore(sess=self.session, save_path=save_path) # 读取保存的模型
示例4: load_variable_pb
# 需要导入模块: import cnn_model [as 别名]
# 或者: from cnn_model import TCNNConfig [as 别名]
def load_variable_pb():
session = tf.Session(graph=tf.Graph())
model_file_path = "pb/model"
meta_graph = tf.saved_model.loader.load(session, [tf.saved_model.tag_constants.SERVING], model_file_path)
model_graph_signature = list(meta_graph.signature_def.items())[0][1]
output_feed = []
output_op_names = []
output_tensor_dict = {}
output_op_names.append('y_pred_cls')
output_op_names.append('y_pred_prob')
for output_item in model_graph_signature.outputs.items():
output_op_name = output_item[0]
output_tensor_name = output_item[1].name
output_tensor_dict[output_op_name] = output_tensor_name
for name in output_op_names:
output_feed.append(output_tensor_dict[name])
print(output_tensor_dict[name])
print("load model finish!")
config = TCNNConfig()
categories, cat_to_id = read_category()
word_to_id = read_vocab(vocab_dir)
while True:
string = input("请输入测试句子: ").strip()
input_x = [[word_to_id.get(x, word_to_id['<PAD>']) for x in string]]
input_x = tf.keras.preprocessing.sequence.pad_sequences(sequences=input_x, maxlen=config.seq_length)
inputs = {}
inputs['input_x'] = input_x
inputs['keep_prob'] = 1.0
feed_dict = {}
for input_item in model_graph_signature.inputs.items():
input_op_name = input_item[0]
input_tensor_name = input_item[1].name
feed_dict[input_tensor_name] = inputs[input_op_name]
outputs = session.run(output_feed, feed_dict=feed_dict)
print(categories[outputs[0][0]])
print(outputs[1][0])