當前位置: 首頁>>代碼示例>>Python>>正文


Python cnn_model.TCNNConfig方法代碼示例

本文整理匯總了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) 
開發者ID:ucloud,項目名稱:uai-sdk,代碼行數:25,代碼來源:txt_cnn_rnn_inference.py

示例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)  # 讀取保存的模型 
開發者ID:a414351664,項目名稱:Bert-TextClassification,代碼行數:13,代碼來源:predict.py

示例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)  # 讀取保存的模型 
開發者ID:sliderSun,項目名稱:pynlp,代碼行數:13,代碼來源:predict_cnn.py

示例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]) 
開發者ID:sliderSun,項目名稱:pynlp,代碼行數:52,代碼來源:export_pb_model.py


注:本文中的cnn_model.TCNNConfig方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。