ASRT_SpeechRecognition/train_mspeech.py

50 lines
1.3 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@author: nl8590687
用于训练语音识别系统语音模型的程序
"""
import platform as plat
import os
import tensorflow as tf
from keras.backend.tensorflow_backend import set_session
2018-07-27 14:31:48 +08:00
from SpeechModel251 import ModelSpeech
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
2018-07-15 14:21:10 +08:00
#进行配置使用95%的GPU
config = tf.ConfigProto()
2018-07-15 14:21:10 +08:00
config.gpu_options.per_process_gpu_memory_fraction = 0.95
#config.gpu_options.allow_growth=True #不全部占满显存, 按需分配
set_session(tf.Session(config=config))
datapath = ''
modelpath = 'model_speech'
if(not os.path.exists(modelpath)): # 判断保存模型的目录是否存在
os.makedirs(modelpath) # 如果不存在,就新建一个,避免之后保存模型的时候炸掉
system_type = plat.system() # 由于不同的系统的文件路径表示不一样,需要进行判断
if(system_type == 'Windows'):
datapath = 'E:\\语音数据集'
modelpath = modelpath + '\\'
elif(system_type == 'Linux'):
datapath = 'dataset'
modelpath = modelpath + '/'
else:
print('*[Message] Unknown System\n')
datapath = 'dataset'
modelpath = modelpath + '/'
ms = ModelSpeech(datapath)
2018-07-27 14:31:48 +08:00
#ms.LoadModel(modelpath + 'speech_model251_e_0_step_327500.model')
2018-07-15 14:21:10 +08:00
ms.TrainModel(datapath, epoch = 50, batch_size = 16, save_step = 500)