本文整理匯總了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])