提交 676ebcdf 编写于 作者: H Hui Zhang

fix logger

上级 e61a6134
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import logging
from typing import Union from typing import Union
from typing import List from typing import List
from typing import Tuple from typing import Tuple
...@@ -23,30 +22,11 @@ from paddle.nn import functional as F ...@@ -23,30 +22,11 @@ from paddle.nn import functional as F
#TODO(Hui Zhang): remove fluid import #TODO(Hui Zhang): remove fluid import
from paddle.fluid import core from paddle.fluid import core
root = logging.getLogger() from deepspeech.utils.log import Log
root.setLevel(logging.DEBUG) logger = Log(__name__).getlog()
format = '[%(levelname)s %(asctime)s %(filename)s:%(lineno)d] %(message)s'
formatter = logging.Formatter(fmt=format, datefmt='%Y/%m/%d %H:%M:%S')
stream_handler = logging.StreamHandler()
stream_handler.setLevel(logging.INFO)
stream_handler.setFormatter(formatter)
root.addHandler(stream_handler)
save_path = 'global.log'
file_handler = logging.FileHandler(save_path)
file_handler.setLevel(logging.DEBUG)
file_handler.setFormatter(formatter)
root.addHandler(file_handler)
# stop propagate for propagating may print
# log multiple times
root.propagate = False
logger = logging.getLogger(__name__)
########### hcak logging ############# ########### hcak logging #############
logger.warn = logging.warning logger.warn = logger.warning
########### hcak paddle ############# ########### hcak paddle #############
paddle.bool = 'bool' paddle.bool = 'bool'
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
"""Contains DeepSpeech2 model.""" """Contains DeepSpeech2 model."""
import time import time
import logging from deepspeech.utils.log import Log
import numpy as np import numpy as np
from collections import defaultdict from collections import defaultdict
from pathlib import Path from pathlib import Path
...@@ -38,7 +38,7 @@ from deepspeech.io.dataset import ManifestDataset ...@@ -38,7 +38,7 @@ from deepspeech.io.dataset import ManifestDataset
from deepspeech.models.deepspeech2 import DeepSpeech2Model from deepspeech.models.deepspeech2 import DeepSpeech2Model
from deepspeech.models.deepspeech2 import DeepSpeech2InferModel from deepspeech.models.deepspeech2 import DeepSpeech2InferModel
logger = logging.getLogger(__name__) logger = Log(__name__).getlog()
class DeepSpeech2Trainer(Trainer): class DeepSpeech2Trainer(Trainer):
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
import sys import sys
import time import time
import logging from deepspeech.utils.log import Log
import numpy as np import numpy as np
from collections import defaultdict from collections import defaultdict
from pathlib import Path from pathlib import Path
...@@ -41,7 +41,7 @@ from deepspeech.io.dataset import ManifestDataset ...@@ -41,7 +41,7 @@ from deepspeech.io.dataset import ManifestDataset
from deepspeech.models.u2 import U2Model from deepspeech.models.u2 import U2Model
logger = logging.getLogger(__name__) logger = Log(__name__).getlog()
class U2Trainer(Trainer): class U2Trainer(Trainer):
......
...@@ -12,12 +12,12 @@ ...@@ -12,12 +12,12 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
"""Contains the volume perturb augmentation model.""" """Contains the volume perturb augmentation model."""
import logging from deepspeech.utils.log import Log
import numpy as np import numpy as np
from deepspeech.frontend.augmentor.base import AugmentorBase from deepspeech.frontend.augmentor.base import AugmentorBase
logger = logging.getLogger(__name__) logger = Log(__name__).getlog()
class SpecAugmentor(AugmentorBase): class SpecAugmentor(AugmentorBase):
......
...@@ -16,9 +16,9 @@ import numpy as np ...@@ -16,9 +16,9 @@ import numpy as np
import math import math
import json import json
import codecs import codecs
import logging from deepspeech.utils.log import Log
logger = logging.getLogger(__name__) logger = Log(__name__).getlog()
__all__ = [ __all__ = [
"load_cmvn", "read_manifest", "rms_to_db", "rms_to_dbfs", "max_dbfs", "load_cmvn", "read_manifest", "rms_to_db", "rms_to_dbfs", "max_dbfs",
......
...@@ -12,16 +12,16 @@ ...@@ -12,16 +12,16 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import logging from deepspeech.utils.log import Log
import numpy as np import numpy as np
from deepspeech.io.utility import pad_sequence from deepspeech.io.utility import pad_sequence
from deepspeech.frontend.utility import IGNORE_ID from deepspeech.frontend.utility import IGNORE_ID
logger = logging.getLogger(__name__)
__all__ = ["SpeechCollator"] __all__ = ["SpeechCollator"]
logger = Log(__name__).getlog()
class SpeechCollator(): class SpeechCollator():
def __init__(self, keep_transcription_text=True): def __init__(self, keep_transcription_text=True):
......
...@@ -16,7 +16,7 @@ import time ...@@ -16,7 +16,7 @@ import time
import io import io
import random import random
import tarfile import tarfile
import logging from deepspeech.utils.log import Log
from typing import Optional from typing import Optional
from yacs.config import CfgNode from yacs.config import CfgNode
from collections import namedtuple from collections import namedtuple
...@@ -29,12 +29,12 @@ from deepspeech.frontend.featurizer.speech_featurizer import SpeechFeaturizer ...@@ -29,12 +29,12 @@ from deepspeech.frontend.featurizer.speech_featurizer import SpeechFeaturizer
from deepspeech.frontend.speech import SpeechSegment from deepspeech.frontend.speech import SpeechSegment
from deepspeech.frontend.normalizer import FeatureNormalizer from deepspeech.frontend.normalizer import FeatureNormalizer
logger = logging.getLogger(__name__)
__all__ = [ __all__ = [
"ManifestDataset", "ManifestDataset",
] ]
logger = Log(__name__).getlog()
class ManifestDataset(Dataset): class ManifestDataset(Dataset):
@classmethod @classmethod
......
...@@ -13,20 +13,20 @@ ...@@ -13,20 +13,20 @@
# limitations under the License. # limitations under the License.
import math import math
import logging from deepspeech.utils.log import Log
import numpy as np import numpy as np
from paddle.io import BatchSampler from paddle.io import BatchSampler
from paddle.io import DistributedBatchSampler from paddle.io import DistributedBatchSampler
from paddle import distributed as dist from paddle import distributed as dist
logger = logging.getLogger(__name__)
__all__ = [ __all__ = [
"SortagradDistributedBatchSampler", "SortagradDistributedBatchSampler",
"SortagradBatchSampler", "SortagradBatchSampler",
] ]
logger = Log(__name__).getlog()
def _batch_shuffle(indices, batch_size, epoch, clipped=False): def _batch_shuffle(indices, batch_size, epoch, clipped=False):
"""Put similarly-sized instances into minibatches for better efficiency """Put similarly-sized instances into minibatches for better efficiency
......
...@@ -12,14 +12,14 @@ ...@@ -12,14 +12,14 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import logging from deepspeech.utils.log import Log
import numpy as np import numpy as np
from typing import List from typing import List
logger = logging.getLogger(__name__)
__all__ = ["pad_sequence"] __all__ = ["pad_sequence"]
logger = Log(__name__).getlog()
def pad_sequence(sequences: List[np.ndarray], def pad_sequence(sequences: List[np.ndarray],
batch_first: bool=True, batch_first: bool=True,
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
"""Deepspeech2 ASR Model""" """Deepspeech2 ASR Model"""
import logging from deepspeech.utils.log import Log
from typing import Optional from typing import Optional
from yacs.config import CfgNode from yacs.config import CfgNode
...@@ -26,7 +26,7 @@ from deepspeech.modules.ctc import CTCDecoder ...@@ -26,7 +26,7 @@ from deepspeech.modules.ctc import CTCDecoder
from deepspeech.utils import checkpoint from deepspeech.utils import checkpoint
from deepspeech.utils import layer_tools from deepspeech.utils import layer_tools
logger = logging.getLogger(__name__) logger = Log(__name__).getlog()
__all__ = ['DeepSpeech2Model'] __all__ = ['DeepSpeech2Model']
......
...@@ -19,7 +19,7 @@ Unified Streaming and Non-streaming Two-pass End-to-end Model for Speech Recogni ...@@ -19,7 +19,7 @@ Unified Streaming and Non-streaming Two-pass End-to-end Model for Speech Recogni
import time import time
import sys import sys
from collections import defaultdict from collections import defaultdict
import logging from deepspeech.utils.log import Log
from yacs.config import CfgNode from yacs.config import CfgNode
from typing import List, Optional, Tuple, Dict from typing import List, Optional, Tuple, Dict
...@@ -50,7 +50,7 @@ from deepspeech.utils.tensor_utils import th_accuracy ...@@ -50,7 +50,7 @@ from deepspeech.utils.tensor_utils import th_accuracy
from deepspeech.utils.tensor_utils import pad_sequence from deepspeech.utils.tensor_utils import pad_sequence
from deepspeech.utils.ctc_utils import remove_duplicates_and_blank from deepspeech.utils.ctc_utils import remove_duplicates_and_blank
logger = logging.getLogger(__name__) logger = Log(__name__).getlog()
__all__ = ["U2Model", "U2InferModel"] __all__ = ["U2Model", "U2InferModel"]
......
...@@ -12,13 +12,13 @@ ...@@ -12,13 +12,13 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import logging from deepspeech.utils.log import Log
from collections import OrderedDict from collections import OrderedDict
import paddle import paddle
from paddle import nn from paddle import nn
logger = logging.getLogger(__name__) logger = Log(__name__).getlog()
__all__ = ["get_activation", "brelu", "LinearGLUBlock", "ConvGLUBlock"] __all__ = ["get_activation", "brelu", "LinearGLUBlock", "ConvGLUBlock"]
......
...@@ -13,14 +13,14 @@ ...@@ -13,14 +13,14 @@
# limitations under the License. # limitations under the License.
"""Multi-Head Attention layer definition.""" """Multi-Head Attention layer definition."""
import math import math
import logging from deepspeech.utils.log import Log
from typing import Optional, Tuple from typing import Optional, Tuple
import paddle import paddle
from paddle import nn from paddle import nn
from paddle.nn import initializer as I from paddle.nn import initializer as I
logger = logging.getLogger(__name__) logger = Log(__name__).getlog()
__all__ = ["MultiHeadedAttention", "RelPositionMultiHeadedAttention"] __all__ = ["MultiHeadedAttention", "RelPositionMultiHeadedAttention"]
......
...@@ -12,12 +12,12 @@ ...@@ -12,12 +12,12 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import logging from deepspeech.utils.log import Log
import paddle import paddle
from paddle import nn from paddle import nn
logger = logging.getLogger(__name__) logger = Log(__name__).getlog()
__all__ = ['GlobalCMVN'] __all__ = ['GlobalCMVN']
......
...@@ -15,12 +15,12 @@ ...@@ -15,12 +15,12 @@
from typing import Optional, Tuple from typing import Optional, Tuple
from typeguard import check_argument_types from typeguard import check_argument_types
import logging from deepspeech.utils.log import Log
import paddle import paddle
from paddle import nn from paddle import nn
logger = logging.getLogger(__name__) logger = Log(__name__).getlog()
__all__ = ['ConvolutionModule'] __all__ = ['ConvolutionModule']
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import logging from deepspeech.utils.log import Log
from paddle import nn from paddle import nn
from paddle.nn import functional as F from paddle.nn import functional as F
...@@ -20,7 +20,7 @@ from paddle.nn import functional as F ...@@ -20,7 +20,7 @@ from paddle.nn import functional as F
from deepspeech.modules.mask import sequence_mask from deepspeech.modules.mask import sequence_mask
from deepspeech.modules.activation import brelu from deepspeech.modules.activation import brelu
logger = logging.getLogger(__name__) logger = Log(__name__).getlog()
__all__ = ['ConvStack', "conv_output_size"] __all__ = ['ConvStack', "conv_output_size"]
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import logging from deepspeech.utils.log import Log
from typeguard import check_argument_types from typeguard import check_argument_types
import paddle import paddle
...@@ -26,7 +26,7 @@ from deepspeech.decoders.swig_wrapper import Scorer ...@@ -26,7 +26,7 @@ from deepspeech.decoders.swig_wrapper import Scorer
from deepspeech.decoders.swig_wrapper import ctc_greedy_decoder from deepspeech.decoders.swig_wrapper import ctc_greedy_decoder
from deepspeech.decoders.swig_wrapper import ctc_beam_search_decoder_batch from deepspeech.decoders.swig_wrapper import ctc_beam_search_decoder_batch
logger = logging.getLogger(__name__) logger = Log(__name__).getlog()
__all__ = ['CTCDecoder'] __all__ = ['CTCDecoder']
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
"""Decoder definition.""" """Decoder definition."""
from typing import Tuple, List, Optional from typing import Tuple, List, Optional
from typeguard import check_argument_types from typeguard import check_argument_types
import logging from deepspeech.utils.log import Log
import paddle import paddle
from paddle import nn from paddle import nn
...@@ -26,7 +26,7 @@ from deepspeech.modules.positionwise_feed_forward import PositionwiseFeedForward ...@@ -26,7 +26,7 @@ from deepspeech.modules.positionwise_feed_forward import PositionwiseFeedForward
from deepspeech.modules.mask import subsequent_mask from deepspeech.modules.mask import subsequent_mask
from deepspeech.modules.mask import make_non_pad_mask from deepspeech.modules.mask import make_non_pad_mask
logger = logging.getLogger(__name__) logger = Log(__name__).getlog()
__all__ = ["TransformerDecoder"] __all__ = ["TransformerDecoder"]
......
...@@ -13,12 +13,12 @@ ...@@ -13,12 +13,12 @@
# limitations under the License. # limitations under the License.
"""Decoder self-attention layer definition.""" """Decoder self-attention layer definition."""
from typing import Optional, Tuple from typing import Optional, Tuple
import logging from deepspeech.utils.log import Log
import paddle import paddle
from paddle import nn from paddle import nn
logger = logging.getLogger(__name__) logger = Log(__name__).getlog()
__all__ = ["DecoderLayer"] __all__ = ["DecoderLayer"]
......
...@@ -14,13 +14,13 @@ ...@@ -14,13 +14,13 @@
"""Positonal Encoding Module.""" """Positonal Encoding Module."""
import math import math
import logging from deepspeech.utils.log import Log
from typing import Tuple from typing import Tuple
import paddle import paddle
from paddle import nn from paddle import nn
logger = logging.getLogger(__name__) logger = Log(__name__).getlog()
__all__ = ["PositionalEncoding", "RelPositionalEncoding"] __all__ = ["PositionalEncoding", "RelPositionalEncoding"]
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
"""Encoder definition.""" """Encoder definition."""
import logging from deepspeech.utils.log import Log
from typing import Tuple, List, Optional from typing import Tuple, List, Optional
from typeguard import check_argument_types from typeguard import check_argument_types
...@@ -35,7 +35,7 @@ from deepspeech.modules.mask import make_non_pad_mask ...@@ -35,7 +35,7 @@ from deepspeech.modules.mask import make_non_pad_mask
from deepspeech.modules.mask import add_optional_chunk_mask from deepspeech.modules.mask import add_optional_chunk_mask
from deepspeech.modules.activation import get_activation from deepspeech.modules.activation import get_activation
logger = logging.getLogger(__name__) logger = Log(__name__).getlog()
__all__ = ["BaseEncoder", 'TransformerEncoder', "ConformerEncoder"] __all__ = ["BaseEncoder", 'TransformerEncoder', "ConformerEncoder"]
......
...@@ -13,12 +13,12 @@ ...@@ -13,12 +13,12 @@
# limitations under the License. # limitations under the License.
"""Encoder self-attention layer definition.""" """Encoder self-attention layer definition."""
from typing import Optional, Tuple from typing import Optional, Tuple
import logging from deepspeech.utils.log import Log
import paddle import paddle
from paddle import nn from paddle import nn
logger = logging.getLogger(__name__) logger = Log(__name__).getlog()
__all__ = ["TransformerEncoderLayer", "ConformerEncoderLayer"] __all__ = ["TransformerEncoderLayer", "ConformerEncoderLayer"]
......
...@@ -12,13 +12,13 @@ ...@@ -12,13 +12,13 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import logging from deepspeech.utils.log import Log
import paddle import paddle
from paddle import nn from paddle import nn
from paddle.nn import functional as F from paddle.nn import functional as F
logger = logging.getLogger(__name__) logger = Log(__name__).getlog()
__all__ = ['CTCLoss', "LabelSmoothingLoss"] __all__ = ['CTCLoss', "LabelSmoothingLoss"]
......
...@@ -12,11 +12,11 @@ ...@@ -12,11 +12,11 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import logging from deepspeech.utils.log import Log
import paddle import paddle
logger = logging.getLogger(__name__) logger = Log(__name__).getlog()
__all__ = [ __all__ = [
'sequence_mask', "make_pad_mask", "make_non_pad_mask", "subsequent_mask", 'sequence_mask', "make_pad_mask", "make_non_pad_mask", "subsequent_mask",
......
...@@ -12,12 +12,12 @@ ...@@ -12,12 +12,12 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
"""Positionwise feed forward layer definition.""" """Positionwise feed forward layer definition."""
import logging from deepspeech.utils.log import Log
import paddle import paddle
from paddle import nn from paddle import nn
logger = logging.getLogger(__name__) logger = Log(__name__).getlog()
__all__ = ["PositionwiseFeedForward"] __all__ = ["PositionwiseFeedForward"]
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
# limitations under the License. # limitations under the License.
import math import math
import logging from deepspeech.utils.log import Log
import paddle import paddle
from paddle import nn from paddle import nn
...@@ -23,7 +23,7 @@ from paddle.nn import initializer as I ...@@ -23,7 +23,7 @@ from paddle.nn import initializer as I
from deepspeech.modules.mask import sequence_mask from deepspeech.modules.mask import sequence_mask
from deepspeech.modules.activation import brelu from deepspeech.modules.activation import brelu
logger = logging.getLogger(__name__) logger = Log(__name__).getlog()
__all__ = ['RNNStack'] __all__ = ['RNNStack']
......
...@@ -14,14 +14,14 @@ ...@@ -14,14 +14,14 @@
"""Subsampling layer definition.""" """Subsampling layer definition."""
from typing import Tuple from typing import Tuple
import logging from deepspeech.utils.log import Log
import paddle import paddle
from paddle import nn from paddle import nn
from deepspeech.modules.embedding import PositionalEncoding from deepspeech.modules.embedding import PositionalEncoding
logger = logging.getLogger(__name__) logger = Log(__name__).getlog()
__all__ = [ __all__ = [
"LinearNoSubsampling", "Conv2dSubsampling4", "Conv2dSubsampling6", "LinearNoSubsampling", "Conv2dSubsampling4", "Conv2dSubsampling6",
......
...@@ -12,17 +12,17 @@ ...@@ -12,17 +12,17 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import logging from deepspeech.utils.log import Log
import paddle import paddle
from paddle.fluid.dygraph import base as imperative_base from paddle.fluid.dygraph import base as imperative_base
from paddle.fluid import layers from paddle.fluid import layers
from paddle.fluid import core from paddle.fluid import core
logger = logging.getLogger(__name__)
__all__ = ["ClipGradByGlobalNormWithLog"] __all__ = ["ClipGradByGlobalNormWithLog"]
logger = Log(__name__).getlog()
class ClipGradByGlobalNormWithLog(paddle.nn.ClipGradByGlobalNorm): class ClipGradByGlobalNormWithLog(paddle.nn.ClipGradByGlobalNorm):
def __init__(self, clip_norm): def __init__(self, clip_norm):
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import logging from deepspeech.utils.log import Log
from typing import Union from typing import Union
from typeguard import check_argument_types from typeguard import check_argument_types
...@@ -20,7 +20,7 @@ from paddle.optimizer.lr import LRScheduler ...@@ -20,7 +20,7 @@ from paddle.optimizer.lr import LRScheduler
__all__ = ["WarmupLR"] __all__ = ["WarmupLR"]
logger = logging.getLogger(__name__) logger = Log(__name__).getlog()
class WarmupLR(LRScheduler): class WarmupLR(LRScheduler):
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
# limitations under the License. # limitations under the License.
import time import time
import logging from deepspeech.utils.log import Log
from pathlib import Path from pathlib import Path
import paddle import paddle
...@@ -25,7 +25,7 @@ from deepspeech.utils import mp_tools ...@@ -25,7 +25,7 @@ from deepspeech.utils import mp_tools
__all__ = ["Trainer"] __all__ = ["Trainer"]
logger = logging.getLogger(__name__) logger = Log(__name__).getlog()
class Trainer(): class Trainer():
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
# limitations under the License. # limitations under the License.
import os import os
import logging from deepspeech.utils.log import Log
import re import re
import json import json
from typing import Union from typing import Union
...@@ -24,7 +24,7 @@ from paddle.optimizer import Optimizer ...@@ -24,7 +24,7 @@ from paddle.optimizer import Optimizer
from deepspeech.utils import mp_tools from deepspeech.utils import mp_tools
logger = logging.getLogger(__name__) logger = Log(__name__).getlog()
__all__ = ["load_parameters", "save_parameters"] __all__ = ["load_parameters", "save_parameters"]
......
...@@ -12,13 +12,13 @@ ...@@ -12,13 +12,13 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import logging from deepspeech.utils.log import Log
import numpy as np import numpy as np
from typing import List from typing import List
import paddle import paddle
logger = logging.getLogger(__name__) logger = Log(__name__).getlog()
__all__ = ["forced_align", "remove_duplicates_and_blank", "insert_blank"] __all__ = ["forced_align", "remove_duplicates_and_blank", "insert_blank"]
......
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
import os
class Log():
def __init__(self, logger=None, log_cate='global'):
self.logger = logging.getLogger(logger)
self.logger.setLevel(logging.DEBUG)
file_dir = os.getcwd() + '/log'
if not os.path.exists(file_dir):
os.mkdir(file_dir)
self.log_path = file_dir
self.log_name = self.log_path + "/" + log_cate + '.log'
fh = logging.FileHandler(self.log_name)
fh.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.INFO)
format = '[%(levelname)s %(asctime)s %(filename)s:%(lineno)d] %(message)s'
formatter = logging.Formatter(fmt=format, datefmt='%Y/%m/%d %H:%M:%S')
fh.setFormatter(formatter)
ch.setFormatter(formatter)
self.logger.addHandler(fh)
self.logger.addHandler(ch)
# stop propagate for propagating may print
# log multiple times
# self.logger.propagate = False
fh.close()
ch.close()
def getlog(self):
return self.logger
...@@ -12,15 +12,15 @@ ...@@ -12,15 +12,15 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
"""Unility functions for Transformer.""" """Unility functions for Transformer."""
import logging from deepspeech.utils.log import Log
from typing import Tuple, List from typing import Tuple, List
import paddle import paddle
logger = logging.getLogger(__name__)
__all__ = ["pad_sequence", "add_sos_eos", "th_accuracy"] __all__ = ["pad_sequence", "add_sos_eos", "th_accuracy"]
logger = Log(__name__).getlog()
def pad_sequence(sequences: List[paddle.Tensor], def pad_sequence(sequences: List[paddle.Tensor],
batch_first: bool=False, batch_first: bool=False,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册