From 14bd31212cda73072db074459b10d3eed3744a7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=97=AD?= <738285867@qq.com> Date: Wed, 20 May 2020 14:46:08 +0800 Subject: [PATCH] add reset_default_graph. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改获取tensor值的代码,添加重置TF 运行图的代码,解决了 预测函数多次运行越来越慢的问题。 --- SpeechModel251.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/SpeechModel251.py b/SpeechModel251.py index a304e62..2595b77 100644 --- a/SpeechModel251.py +++ b/SpeechModel251.py @@ -12,6 +12,7 @@ from general_function.file_dict import * from general_function.gen_func import * # LSTM_CNN +import tensorflow as tf import keras as kr import numpy as np import random @@ -322,19 +323,9 @@ class ModelSpeech(): # 语音模型类 r = K.ctc_decode(base_pred, in_len, greedy = True, beam_width=100, top_paths=1) #print('r', r) - - - r1 = K.get_value(r[0][0]) - #print('r1', r1) - - - #r2 = K.get_value(r[1]) - #print(r2) - - r1=r1[0] - - return r1 - pass + r1 = r[0][0].eval(session=tf.Session()) + tf.reset_default_graph() + return r1[0] def RecognizeSpeech(self, wavsignal, fs): '''