Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions paddlespeech/cli/asr/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ def _init_from_path(self,
"""
Init model and other resources from a specific path.
"""
logger.info("start to init the model")
logger.debug("start to init the model")
# default max_len: unit:second
self.max_len = 50
if hasattr(self, 'model'):
logger.info('Model had been initialized.')
logger.debug('Model had been initialized.')
return

if cfg_path is None or ckpt_path is None:
Expand All @@ -151,15 +151,15 @@ def _init_from_path(self,
self.ckpt_path = os.path.join(
self.res_path,
self.task_resource.res_dict['ckpt_path'] + ".pdparams")
logger.info(self.res_path)
logger.debug(self.res_path)

else:
self.cfg_path = os.path.abspath(cfg_path)
self.ckpt_path = os.path.abspath(ckpt_path + ".pdparams")
self.res_path = os.path.dirname(
os.path.dirname(os.path.abspath(self.cfg_path)))
logger.info(self.cfg_path)
logger.info(self.ckpt_path)
logger.debug(self.cfg_path)
logger.debug(self.ckpt_path)

#Init body.
self.config = CfgNode(new_allowed=True)
Expand Down Expand Up @@ -216,7 +216,7 @@ def _init_from_path(self,
max_len = self.config.encoder_conf.max_len

self.max_len = frame_shift_ms * max_len * subsample_rate
logger.info(
logger.debug(
f"The asr server limit max duration len: {self.max_len}")

def preprocess(self, model_type: str, input: Union[str, os.PathLike]):
Expand All @@ -227,15 +227,15 @@ def preprocess(self, model_type: str, input: Union[str, os.PathLike]):

audio_file = input
if isinstance(audio_file, (str, os.PathLike)):
logger.info("Preprocess audio_file:" + audio_file)
logger.debug("Preprocess audio_file:" + audio_file)

# Get the object for feature extraction
if "deepspeech2" in model_type or "conformer" in model_type or "transformer" in model_type:
logger.info("get the preprocess conf")
logger.debug("get the preprocess conf")
preprocess_conf = self.config.preprocess_config
preprocess_args = {"train": False}
preprocessing = Transformation(preprocess_conf)
logger.info("read the audio file")
logger.debug("read the audio file")
audio, audio_sample_rate = soundfile.read(
audio_file, dtype="int16", always_2d=True)
if self.change_format:
Expand All @@ -255,7 +255,7 @@ def preprocess(self, model_type: str, input: Union[str, os.PathLike]):
else:
audio = audio[:, 0]

logger.info(f"audio shape: {audio.shape}")
logger.debug(f"audio shape: {audio.shape}")
# fbank
audio = preprocessing(audio, **preprocess_args)

Expand All @@ -264,19 +264,19 @@ def preprocess(self, model_type: str, input: Union[str, os.PathLike]):

self._inputs["audio"] = audio
self._inputs["audio_len"] = audio_len
logger.info(f"audio feat shape: {audio.shape}")
logger.debug(f"audio feat shape: {audio.shape}")

else:
raise Exception("wrong type")

logger.info("audio feat process success")
logger.debug("audio feat process success")

@paddle.no_grad()
def infer(self, model_type: str):
"""
Model inference and result stored in self.output.
"""
logger.info("start to infer the model to get the output")
logger.debug("start to infer the model to get the output")
cfg = self.config.decode
audio = self._inputs["audio"]
audio_len = self._inputs["audio_len"]
Expand All @@ -293,7 +293,7 @@ def infer(self, model_type: str):
self._outputs["result"] = result_transcripts[0]

elif "conformer" in model_type or "transformer" in model_type:
logger.info(
logger.debug(
f"we will use the transformer like model : {model_type}")
try:
result_transcripts = self.model.decode(
Expand Down Expand Up @@ -352,7 +352,7 @@ def _check(self, audio_file: str, sample_rate: int, force_yes: bool):
logger.error("Please input the right audio file path")
return False

logger.info("checking the audio file format......")
logger.debug("checking the audio file format......")
try:
audio, audio_sample_rate = soundfile.read(
audio_file, dtype="int16", always_2d=True)
Expand All @@ -374,7 +374,7 @@ def _check(self, audio_file: str, sample_rate: int, force_yes: bool):
sox input_audio.xx --rate 8k --bits 16 --channels 1 output_audio.wav \n \
")
return False
logger.info("The sample rate is %d" % audio_sample_rate)
logger.debug("The sample rate is %d" % audio_sample_rate)
if audio_sample_rate != self.sample_rate:
logger.warning("The sample rate of the input file is not {}.\n \
The program will resample the wav file to {}.\n \
Expand All @@ -383,28 +383,28 @@ def _check(self, audio_file: str, sample_rate: int, force_yes: bool):
".format(self.sample_rate, self.sample_rate))
if force_yes is False:
while (True):
logger.info(
logger.debug(
"Whether to change the sample rate and the channel. Y: change the sample. N: exit the prgream."
)
content = input("Input(Y/N):")
if content.strip() == "Y" or content.strip(
) == "y" or content.strip() == "yes" or content.strip(
) == "Yes":
logger.info(
logger.debug(
"change the sampele rate, channel to 16k and 1 channel"
)
break
elif content.strip() == "N" or content.strip(
) == "n" or content.strip() == "no" or content.strip(
) == "No":
logger.info("Exit the program")
logger.debug("Exit the program")
return False
else:
logger.warning("Not regular input, please input again")

self.change_format = True
else:
logger.info("The audio file format is right")
logger.debug("The audio file format is right")
self.change_format = False

return True
Expand Down
6 changes: 3 additions & 3 deletions paddlespeech/cli/cls/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def _init_from_path(self,
Init model and other resources from a specific path.
"""
if hasattr(self, 'model'):
logger.info('Model had been initialized.')
logger.debug('Model had been initialized.')
return

if label_file is None or ckpt_path is None:
Expand Down Expand Up @@ -135,14 +135,14 @@ def preprocess(self, audio_file: Union[str, os.PathLike]):
Input content can be a text(tts), a file(asr, cls) or a streaming(not supported yet).
"""
feat_conf = self._conf['feature']
logger.info(feat_conf)
logger.debug(feat_conf)
waveform, _ = load(
file=audio_file,
sr=feat_conf['sample_rate'],
mono=True,
dtype='float32')
if isinstance(audio_file, (str, os.PathLike)):
logger.info("Preprocessing audio_file:" + audio_file)
logger.debug("Preprocessing audio_file:" + audio_file)

# Feature extraction
feature_extractor = LogMelSpectrogram(
Expand Down
16 changes: 8 additions & 8 deletions paddlespeech/cli/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _get_unique_endpoints(trainer_endpoints):
continue
ips.add(ip)
unique_endpoints.add(endpoint)
logger.info("unique_endpoints {}".format(unique_endpoints))
logger.debug("unique_endpoints {}".format(unique_endpoints))
return unique_endpoints


Expand Down Expand Up @@ -96,7 +96,7 @@ def get_path_from_url(url,
# data, and the same ip will only download data once.
unique_endpoints = _get_unique_endpoints(ParallelEnv().trainer_endpoints[:])
if osp.exists(fullpath) and check_exist and _md5check(fullpath, md5sum):
logger.info("Found {}".format(fullpath))
logger.debug("Found {}".format(fullpath))
else:
if ParallelEnv().current_endpoint in unique_endpoints:
fullpath = _download(url, root_dir, md5sum, method=method)
Expand All @@ -118,7 +118,7 @@ def _get_download(url, fullname):
try:
req = requests.get(url, stream=True)
except Exception as e: # requests.exceptions.ConnectionError
logger.info("Downloading {} from {} failed with exception {}".format(
logger.debug("Downloading {} from {} failed with exception {}".format(
fname, url, str(e)))
return False

Expand Down Expand Up @@ -190,7 +190,7 @@ def _download(url, path, md5sum=None, method='get'):
fullname = osp.join(path, fname)
retry_cnt = 0

logger.info("Downloading {} from {}".format(fname, url))
logger.debug("Downloading {} from {}".format(fname, url))
while not (osp.exists(fullname) and _md5check(fullname, md5sum)):
if retry_cnt < DOWNLOAD_RETRY_LIMIT:
retry_cnt += 1
Expand All @@ -209,16 +209,16 @@ def _md5check(fullname, md5sum=None):
if md5sum is None:
return True

logger.info("File {} md5 checking...".format(fullname))
logger.debug("File {} md5 checking...".format(fullname))
md5 = hashlib.md5()
with open(fullname, 'rb') as f:
for chunk in iter(lambda: f.read(4096), b""):
md5.update(chunk)
calc_md5sum = md5.hexdigest()

if calc_md5sum != md5sum:
logger.info("File {} md5 check failed, {}(calc) != "
"{}(base)".format(fullname, calc_md5sum, md5sum))
logger.debug("File {} md5 check failed, {}(calc) != "
"{}(base)".format(fullname, calc_md5sum, md5sum))
return False
return True

Expand All @@ -227,7 +227,7 @@ def _decompress(fname):
"""
Decompress for zip and tar file
"""
logger.info("Decompressing {}...".format(fname))
logger.debug("Decompressing {}...".format(fname))

# For protecting decompressing interupted,
# decompress to fpath_tmp directory firstly, if decompress
Expand Down
4 changes: 2 additions & 2 deletions paddlespeech/cli/kws/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def _init_from_path(self,
Init model and other resources from a specific path.
"""
if hasattr(self, 'model'):
logger.info('Model had been initialized.')
logger.debug('Model had been initialized.')
return

if ckpt_path is None:
Expand Down Expand Up @@ -141,7 +141,7 @@ def preprocess(self, audio_file: Union[str, os.PathLike]):
assert os.path.isfile(audio_file)
waveform, _ = load(audio_file)
if isinstance(audio_file, (str, os.PathLike)):
logger.info("Preprocessing audio_file:" + audio_file)
logger.debug("Preprocessing audio_file:" + audio_file)

# Feature extraction
waveform = paddle.to_tensor(waveform).unsqueeze(0)
Expand Down
2 changes: 1 addition & 1 deletion paddlespeech/cli/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(self, name: str=None):
self.handler.setFormatter(self.format)

self.logger.addHandler(self.handler)
self.logger.setLevel(logging.DEBUG)
self.logger.setLevel(logging.INFO)
self.logger.propagate = False

def __call__(self, log_level: str, msg: str):
Expand Down
10 changes: 5 additions & 5 deletions paddlespeech/cli/st/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def _set_kaldi_bins(self) -> os.PathLike:
"""
decompressed_path = download_and_decompress(self.kaldi_bins, MODEL_HOME)
decompressed_path = os.path.abspath(decompressed_path)
logger.info("Kaldi_bins stored in: {}".format(decompressed_path))
logger.debug("Kaldi_bins stored in: {}".format(decompressed_path))
if "LD_LIBRARY_PATH" in os.environ:
os.environ["LD_LIBRARY_PATH"] += f":{decompressed_path}"
else:
Expand All @@ -128,7 +128,7 @@ def _init_from_path(self,
Init model and other resources from a specific path.
"""
if hasattr(self, 'model'):
logger.info('Model had been initialized.')
logger.debug('Model had been initialized.')
return

if cfg_path is None or ckpt_path is None:
Expand All @@ -140,8 +140,8 @@ def _init_from_path(self,
self.ckpt_path = os.path.join(
self.task_resource.res_dir,
self.task_resource.res_dict['ckpt_path'])
logger.info(self.cfg_path)
logger.info(self.ckpt_path)
logger.debug(self.cfg_path)
logger.debug(self.ckpt_path)
res_path = self.task_resource.res_dir
else:
self.cfg_path = os.path.abspath(cfg_path)
Expand Down Expand Up @@ -192,7 +192,7 @@ def preprocess(self, wav_file: Union[str, os.PathLike], model_type: str):
Input content can be a file(wav).
"""
audio_file = os.path.abspath(wav_file)
logger.info("Preprocess audio_file:" + audio_file)
logger.debug("Preprocess audio_file:" + audio_file)

if "fat_st" in model_type:
cmvn = self.config.cmvn_path
Expand Down
2 changes: 1 addition & 1 deletion paddlespeech/cli/text/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def _init_from_path(self,
Init model and other resources from a specific path.
"""
if hasattr(self, 'model'):
logger.info('Model had been initialized.')
logger.debug('Model had been initialized.')
return

self.task = task
Expand Down
14 changes: 7 additions & 7 deletions paddlespeech/cli/tts/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def _init_from_path(
Init model and other resources from a specific path.
"""
if hasattr(self, 'am_inference') and hasattr(self, 'voc_inference'):
logger.info('Models had been initialized.')
logger.debug('Models had been initialized.')
return

# am
Expand All @@ -200,9 +200,9 @@ def _init_from_path(
# must have phones_dict in acoustic
self.phones_dict = os.path.join(
self.am_res_path, self.task_resource.res_dict['phones_dict'])
logger.info(self.am_res_path)
logger.info(self.am_config)
logger.info(self.am_ckpt)
logger.debug(self.am_res_path)
logger.debug(self.am_config)
logger.debug(self.am_ckpt)
else:
self.am_config = os.path.abspath(am_config)
self.am_ckpt = os.path.abspath(am_ckpt)
Expand Down Expand Up @@ -248,9 +248,9 @@ def _init_from_path(
self.voc_stat = os.path.join(
self.voc_res_path,
self.task_resource.voc_res_dict['speech_stats'])
logger.info(self.voc_res_path)
logger.info(self.voc_config)
logger.info(self.voc_ckpt)
logger.debug(self.voc_res_path)
logger.debug(self.voc_config)
logger.debug(self.voc_ckpt)
else:
self.voc_config = os.path.abspath(voc_config)
self.voc_ckpt = os.path.abspath(voc_ckpt)
Expand Down
Loading