2018-05-11 18:42:58 +08:00
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
# -*- coding: utf-8 -*-
|
2021-05-16 19:44:05 +08:00
|
|
|
|
#
|
|
|
|
|
# Copyright 2016-2099 Ailemon.net
|
|
|
|
|
#
|
|
|
|
|
# This file is part of ASRT Speech Recognition Tool.
|
|
|
|
|
#
|
|
|
|
|
# ASRT is free software: you can redistribute it and/or modify
|
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
# ASRT is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
|
# along with ASRT. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
# ============================================================================
|
|
|
|
|
|
2018-05-11 18:42:58 +08:00
|
|
|
|
"""
|
|
|
|
|
@author: nl8590687
|
|
|
|
|
用于训练语音识别系统语音模型的程序
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
import platform as plat
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
import tensorflow as tf
|
2021-05-16 20:28:20 +08:00
|
|
|
|
#from keras.backend.tensorflow_backend import set_session
|
2018-05-11 18:42:58 +08:00
|
|
|
|
|
|
|
|
|
|
2020-08-10 16:35:40 +08:00
|
|
|
|
from SpeechModel251 import ModelSpeech, ModelName
|
2018-05-11 18:42:58 +08:00
|
|
|
|
|
|
|
|
|
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
|
2018-07-15 14:21:10 +08:00
|
|
|
|
#进行配置,使用95%的GPU
|
2021-11-03 17:58:45 +08:00
|
|
|
|
#config = tf.compat.v1.ConfigProto()
|
|
|
|
|
#config.gpu_options.per_process_gpu_memory_fraction = 0.95
|
2018-05-11 18:42:58 +08:00
|
|
|
|
#config.gpu_options.allow_growth=True #不全部占满显存, 按需分配
|
2021-11-03 17:58:45 +08:00
|
|
|
|
#sess = tf.compat.v1.Session(config=config)
|
|
|
|
|
#tf.compat.v1.keras.backend.set_session(sess)
|
2018-05-11 18:42:58 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
datapath = ''
|
|
|
|
|
modelpath = 'model_speech'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(not os.path.exists(modelpath)): # 判断保存模型的目录是否存在
|
|
|
|
|
os.makedirs(modelpath) # 如果不存在,就新建一个,避免之后保存模型的时候炸掉
|
2020-08-10 16:35:40 +08:00
|
|
|
|
os.makedirs(modelpath + '/m' + ModelName)
|
2018-05-11 18:42:58 +08:00
|
|
|
|
|
|
|
|
|
system_type = plat.system() # 由于不同的系统的文件路径表示不一样,需要进行判断
|
|
|
|
|
if(system_type == 'Windows'):
|
2020-10-22 20:10:57 +08:00
|
|
|
|
datapath = 'D:\\SpeechData'
|
2018-05-11 18:42:58 +08:00
|
|
|
|
modelpath = modelpath + '\\'
|
|
|
|
|
elif(system_type == 'Linux'):
|
|
|
|
|
datapath = 'dataset'
|
|
|
|
|
modelpath = modelpath + '/'
|
|
|
|
|
else:
|
|
|
|
|
print('*[Message] Unknown System\n')
|
|
|
|
|
datapath = 'dataset'
|
|
|
|
|
modelpath = modelpath + '/'
|
|
|
|
|
|
|
|
|
|
ms = ModelSpeech(datapath)
|
|
|
|
|
|
2021-05-16 21:14:52 +08:00
|
|
|
|
#ms.LoadModel(modelpath + 'speech_model251_e_0_step_327500.h5')
|
2021-08-10 17:14:34 +08:00
|
|
|
|
ms.TrainModel(datapath, epoch = 50, batch_size = 16, save_step = 5000)
|
2018-05-11 18:42:58 +08:00
|
|
|
|
|
|
|
|
|
|