diff --git a/deepspeech/__init__.py b/deepspeech/__init__.py index a1617c78a54d6b1d7083f095aedb015e9d7434a6..8be0e93f4961781ba4d9a8bf195f98b5e097de86 100644 --- a/deepspeech/__init__.py +++ b/deepspeech/__init__.py @@ -11,7 +11,6 @@ # 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 from typing import Union from typing import List from typing import Tuple @@ -23,30 +22,11 @@ from paddle.nn import functional as F #TODO(Hui Zhang): remove fluid import from paddle.fluid import core -root = logging.getLogger() -root.setLevel(logging.DEBUG) - -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__) +from deepspeech.utils.log import Log +logger = Log(__name__).getlog() ########### hcak logging ############# -logger.warn = logging.warning +logger.warn = logger.warning ########### hcak paddle ############# paddle.bool = 'bool' diff --git a/deepspeech/exps/deepspeech2/model.py b/deepspeech/exps/deepspeech2/model.py index fcc303a3af3079846da1df98a72bdec3cf7dc12f..ffe7d717ceb7529abf386bc5ef1e7e7ae8f92663 100644 --- a/deepspeech/exps/deepspeech2/model.py +++ b/deepspeech/exps/deepspeech2/model.py @@ -14,7 +14,7 @@ """Contains DeepSpeech2 model.""" import time -import logging +from deepspeech.utils.log import Log import numpy as np from collections import defaultdict from pathlib import Path @@ -38,7 +38,7 @@ from deepspeech.io.dataset import ManifestDataset from deepspeech.models.deepspeech2 import DeepSpeech2Model from deepspeech.models.deepspeech2 import DeepSpeech2InferModel -logger = logging.getLogger(__name__) +logger = Log(__name__).getlog() class DeepSpeech2Trainer(Trainer): diff --git a/deepspeech/exps/u2/model.py b/deepspeech/exps/u2/model.py index d02818c202ae0a9c4c21a443a8d0c291ef1b7b8d..646b672592e39f07e482d1edcdb682aacdaeea0b 100644 --- a/deepspeech/exps/u2/model.py +++ b/deepspeech/exps/u2/model.py @@ -15,7 +15,7 @@ import sys import time -import logging +from deepspeech.utils.log import Log import numpy as np from collections import defaultdict from pathlib import Path @@ -41,7 +41,7 @@ from deepspeech.io.dataset import ManifestDataset from deepspeech.models.u2 import U2Model -logger = logging.getLogger(__name__) +logger = Log(__name__).getlog() class U2Trainer(Trainer): diff --git a/deepspeech/frontend/augmentor/spec_augment.py b/deepspeech/frontend/augmentor/spec_augment.py index 2b648daba99b217fc86357792f18a6f518216cf7..59240be5a1f5504c479ce5ebefe3a22e49963cff 100644 --- a/deepspeech/frontend/augmentor/spec_augment.py +++ b/deepspeech/frontend/augmentor/spec_augment.py @@ -12,12 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. """Contains the volume perturb augmentation model.""" -import logging +from deepspeech.utils.log import Log import numpy as np from deepspeech.frontend.augmentor.base import AugmentorBase -logger = logging.getLogger(__name__) +logger = Log(__name__).getlog() class SpecAugmentor(AugmentorBase): diff --git a/deepspeech/frontend/utility.py b/deepspeech/frontend/utility.py index 8c5581eb09716ce9a749a15b06f988dea611f287..657a71a9f5f569e87129c72f64f7496a27b65f28 100644 --- a/deepspeech/frontend/utility.py +++ b/deepspeech/frontend/utility.py @@ -16,9 +16,9 @@ import numpy as np import math import json import codecs -import logging +from deepspeech.utils.log import Log -logger = logging.getLogger(__name__) +logger = Log(__name__).getlog() __all__ = [ "load_cmvn", "read_manifest", "rms_to_db", "rms_to_dbfs", "max_dbfs", diff --git a/deepspeech/io/collator.py b/deepspeech/io/collator.py index 4edb4ca99eb4c581c9c03e062d2df15e340fcd66..310333d04ed7d315956e5dd251b28146e33b61ee 100644 --- a/deepspeech/io/collator.py +++ b/deepspeech/io/collator.py @@ -12,16 +12,16 @@ # See the License for the specific language governing permissions and # limitations under the License. -import logging +from deepspeech.utils.log import Log import numpy as np from deepspeech.io.utility import pad_sequence from deepspeech.frontend.utility import IGNORE_ID -logger = logging.getLogger(__name__) - __all__ = ["SpeechCollator"] +logger = Log(__name__).getlog() + class SpeechCollator(): def __init__(self, keep_transcription_text=True): diff --git a/deepspeech/io/dataset.py b/deepspeech/io/dataset.py index a660ae49411f3aa5f5653a09029b2f353d6ea443..a33724947d105696005f7a39c6ecaa59a5dededc 100644 --- a/deepspeech/io/dataset.py +++ b/deepspeech/io/dataset.py @@ -16,7 +16,7 @@ import time import io import random import tarfile -import logging +from deepspeech.utils.log import Log from typing import Optional from yacs.config import CfgNode from collections import namedtuple @@ -29,12 +29,12 @@ from deepspeech.frontend.featurizer.speech_featurizer import SpeechFeaturizer from deepspeech.frontend.speech import SpeechSegment from deepspeech.frontend.normalizer import FeatureNormalizer -logger = logging.getLogger(__name__) - __all__ = [ "ManifestDataset", ] +logger = Log(__name__).getlog() + class ManifestDataset(Dataset): @classmethod diff --git a/deepspeech/io/sampler.py b/deepspeech/io/sampler.py index 7acb88cf24c79ce741f5b507137cec1224e00d7a..910169af67e4e86fc3b99e2d4145d927721d5a2e 100644 --- a/deepspeech/io/sampler.py +++ b/deepspeech/io/sampler.py @@ -13,20 +13,20 @@ # limitations under the License. import math -import logging +from deepspeech.utils.log import Log import numpy as np from paddle.io import BatchSampler from paddle.io import DistributedBatchSampler from paddle import distributed as dist -logger = logging.getLogger(__name__) - __all__ = [ "SortagradDistributedBatchSampler", "SortagradBatchSampler", ] +logger = Log(__name__).getlog() + def _batch_shuffle(indices, batch_size, epoch, clipped=False): """Put similarly-sized instances into minibatches for better efficiency diff --git a/deepspeech/io/utility.py b/deepspeech/io/utility.py index 4c2ff76bd353b6e539d0b9f75180b8f3b870987e..de0e5234907105e21c8f518dd7256c91b2c80528 100644 --- a/deepspeech/io/utility.py +++ b/deepspeech/io/utility.py @@ -12,14 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. -import logging +from deepspeech.utils.log import Log import numpy as np from typing import List -logger = logging.getLogger(__name__) - __all__ = ["pad_sequence"] +logger = Log(__name__).getlog() + def pad_sequence(sequences: List[np.ndarray], batch_first: bool=True, diff --git a/deepspeech/models/deepspeech2.py b/deepspeech/models/deepspeech2.py index 884fa4b1f1428a9285eb70336020e5337f5f1000..a3ad9fed44f475c1bf7220c719df5f97ad3fda53 100644 --- a/deepspeech/models/deepspeech2.py +++ b/deepspeech/models/deepspeech2.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. """Deepspeech2 ASR Model""" -import logging +from deepspeech.utils.log import Log from typing import Optional from yacs.config import CfgNode @@ -26,7 +26,7 @@ from deepspeech.modules.ctc import CTCDecoder from deepspeech.utils import checkpoint from deepspeech.utils import layer_tools -logger = logging.getLogger(__name__) +logger = Log(__name__).getlog() __all__ = ['DeepSpeech2Model'] diff --git a/deepspeech/models/u2.py b/deepspeech/models/u2.py index af7a11e1c8789f23253a3ec8b3a3c9dd1a193310..04a57c1ee0d677b3e263bf3dc2c44a002951b2ae 100644 --- a/deepspeech/models/u2.py +++ b/deepspeech/models/u2.py @@ -19,7 +19,7 @@ Unified Streaming and Non-streaming Two-pass End-to-end Model for Speech Recogni import time import sys from collections import defaultdict -import logging +from deepspeech.utils.log import Log from yacs.config import CfgNode from typing import List, Optional, Tuple, Dict @@ -50,7 +50,7 @@ from deepspeech.utils.tensor_utils import th_accuracy from deepspeech.utils.tensor_utils import pad_sequence from deepspeech.utils.ctc_utils import remove_duplicates_and_blank -logger = logging.getLogger(__name__) +logger = Log(__name__).getlog() __all__ = ["U2Model", "U2InferModel"] diff --git a/deepspeech/modules/activation.py b/deepspeech/modules/activation.py index 6fd2fa51c3bceead9c6c72929649715f7c6ca880..eb0297dd382e6ecb3872b8cf60f314452fe181bf 100644 --- a/deepspeech/modules/activation.py +++ b/deepspeech/modules/activation.py @@ -12,13 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import logging +from deepspeech.utils.log import Log from collections import OrderedDict import paddle from paddle import nn -logger = logging.getLogger(__name__) +logger = Log(__name__).getlog() __all__ = ["get_activation", "brelu", "LinearGLUBlock", "ConvGLUBlock"] diff --git a/deepspeech/modules/attention.py b/deepspeech/modules/attention.py index f2eb77e4709fc1cc9f7243c82fa50c887f8ce0ec..19c3381777a4b1fb3b7d7111ffa6e560bdb919f0 100644 --- a/deepspeech/modules/attention.py +++ b/deepspeech/modules/attention.py @@ -13,14 +13,14 @@ # limitations under the License. """Multi-Head Attention layer definition.""" import math -import logging +from deepspeech.utils.log import Log from typing import Optional, Tuple import paddle from paddle import nn from paddle.nn import initializer as I -logger = logging.getLogger(__name__) +logger = Log(__name__).getlog() __all__ = ["MultiHeadedAttention", "RelPositionMultiHeadedAttention"] diff --git a/deepspeech/modules/cmvn.py b/deepspeech/modules/cmvn.py index 562efd4170ab7942237b9f1935326d41f8ff0d62..0d65242bcc2231441d55018e21cc09d85f4ea464 100644 --- a/deepspeech/modules/cmvn.py +++ b/deepspeech/modules/cmvn.py @@ -12,12 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -import logging +from deepspeech.utils.log import Log import paddle from paddle import nn -logger = logging.getLogger(__name__) +logger = Log(__name__).getlog() __all__ = ['GlobalCMVN'] diff --git a/deepspeech/modules/conformer_convolution.py b/deepspeech/modules/conformer_convolution.py index 1a9c59f42c5bb90de5409f793562c3736c6a8081..2e6d40bb1f159d568f3d8e32de63c0ad28e70e8c 100644 --- a/deepspeech/modules/conformer_convolution.py +++ b/deepspeech/modules/conformer_convolution.py @@ -15,12 +15,12 @@ from typing import Optional, Tuple from typeguard import check_argument_types -import logging +from deepspeech.utils.log import Log import paddle from paddle import nn -logger = logging.getLogger(__name__) +logger = Log(__name__).getlog() __all__ = ['ConvolutionModule'] diff --git a/deepspeech/modules/conv.py b/deepspeech/modules/conv.py index 4c3374286ac8b61a45d340e28aeb29810b03cd10..c86b36f472e5f0cb35faa82f8c727e80e499c544 100644 --- a/deepspeech/modules/conv.py +++ b/deepspeech/modules/conv.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import logging +from deepspeech.utils.log import Log from paddle import nn 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.activation import brelu -logger = logging.getLogger(__name__) +logger = Log(__name__).getlog() __all__ = ['ConvStack', "conv_output_size"] diff --git a/deepspeech/modules/ctc.py b/deepspeech/modules/ctc.py index 1cd7a3c850a12989ac70acade0d4c91c69ebbb67..fc0fc8f3839ed9d953354156198653a58ab51602 100644 --- a/deepspeech/modules/ctc.py +++ b/deepspeech/modules/ctc.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import logging +from deepspeech.utils.log import Log from typeguard import check_argument_types import paddle @@ -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_beam_search_decoder_batch -logger = logging.getLogger(__name__) +logger = Log(__name__).getlog() __all__ = ['CTCDecoder'] diff --git a/deepspeech/modules/decoder.py b/deepspeech/modules/decoder.py index 11f18f7bfcee16023189cdbeaecc9bea2fe51f00..6d6e0944aa299a341a3c777dcdca4354488eeb21 100644 --- a/deepspeech/modules/decoder.py +++ b/deepspeech/modules/decoder.py @@ -14,7 +14,7 @@ """Decoder definition.""" from typing import Tuple, List, Optional from typeguard import check_argument_types -import logging +from deepspeech.utils.log import Log import paddle from paddle import nn @@ -26,7 +26,7 @@ from deepspeech.modules.positionwise_feed_forward import PositionwiseFeedForward from deepspeech.modules.mask import subsequent_mask from deepspeech.modules.mask import make_non_pad_mask -logger = logging.getLogger(__name__) +logger = Log(__name__).getlog() __all__ = ["TransformerDecoder"] diff --git a/deepspeech/modules/decoder_layer.py b/deepspeech/modules/decoder_layer.py index a781ea5d5b4f0ddad2b16dd48d21c5ea6a596cdd..84490290e96c9a446dbdf0e70fa81723aa18864d 100644 --- a/deepspeech/modules/decoder_layer.py +++ b/deepspeech/modules/decoder_layer.py @@ -13,12 +13,12 @@ # limitations under the License. """Decoder self-attention layer definition.""" from typing import Optional, Tuple -import logging +from deepspeech.utils.log import Log import paddle from paddle import nn -logger = logging.getLogger(__name__) +logger = Log(__name__).getlog() __all__ = ["DecoderLayer"] diff --git a/deepspeech/modules/embedding.py b/deepspeech/modules/embedding.py index df8e346a7d45cec75fdab9b940ca59eb5f5a8f4c..8d7a842e10e9aa80de6ec883606713d93ea2c598 100644 --- a/deepspeech/modules/embedding.py +++ b/deepspeech/modules/embedding.py @@ -14,13 +14,13 @@ """Positonal Encoding Module.""" import math -import logging +from deepspeech.utils.log import Log from typing import Tuple import paddle from paddle import nn -logger = logging.getLogger(__name__) +logger = Log(__name__).getlog() __all__ = ["PositionalEncoding", "RelPositionalEncoding"] diff --git a/deepspeech/modules/encoder.py b/deepspeech/modules/encoder.py index e2ea57d3917e0a1ccd7d4ae17a9c4e92185c62f5..70b01eb4aaadec7b83bb629626766744119b35b8 100644 --- a/deepspeech/modules/encoder.py +++ b/deepspeech/modules/encoder.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. """Encoder definition.""" -import logging +from deepspeech.utils.log import Log from typing import Tuple, List, Optional from typeguard import check_argument_types @@ -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.activation import get_activation -logger = logging.getLogger(__name__) +logger = Log(__name__).getlog() __all__ = ["BaseEncoder", 'TransformerEncoder', "ConformerEncoder"] diff --git a/deepspeech/modules/encoder_layer.py b/deepspeech/modules/encoder_layer.py index 6ae69852e7ef6ae539f865eddcd597f6aefea39a..5dec456526d2f96869252061db74b8c129b3dd47 100644 --- a/deepspeech/modules/encoder_layer.py +++ b/deepspeech/modules/encoder_layer.py @@ -13,12 +13,12 @@ # limitations under the License. """Encoder self-attention layer definition.""" from typing import Optional, Tuple -import logging +from deepspeech.utils.log import Log import paddle from paddle import nn -logger = logging.getLogger(__name__) +logger = Log(__name__).getlog() __all__ = ["TransformerEncoderLayer", "ConformerEncoderLayer"] diff --git a/deepspeech/modules/loss.py b/deepspeech/modules/loss.py index 95ca644ad5f4ae4ced28b7b4cc499a250fcf63bc..d78f689d02d26c0e1a7167f9f63613db3fb4f948 100644 --- a/deepspeech/modules/loss.py +++ b/deepspeech/modules/loss.py @@ -12,13 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import logging +from deepspeech.utils.log import Log import paddle from paddle import nn from paddle.nn import functional as F -logger = logging.getLogger(__name__) +logger = Log(__name__).getlog() __all__ = ['CTCLoss', "LabelSmoothingLoss"] diff --git a/deepspeech/modules/mask.py b/deepspeech/modules/mask.py index beb67db7db9c88d3ad2a61da4542006d289fcf7b..2877b063ea74697f5865eb0477b114759a0c297d 100644 --- a/deepspeech/modules/mask.py +++ b/deepspeech/modules/mask.py @@ -12,11 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -import logging +from deepspeech.utils.log import Log import paddle -logger = logging.getLogger(__name__) +logger = Log(__name__).getlog() __all__ = [ 'sequence_mask', "make_pad_mask", "make_non_pad_mask", "subsequent_mask", diff --git a/deepspeech/modules/positionwise_feed_forward.py b/deepspeech/modules/positionwise_feed_forward.py index 4c4c3a66a74e1780996449393900e90b60078ef2..3242dd6f1b9af5fd41856636d1bbc98eaa418abe 100644 --- a/deepspeech/modules/positionwise_feed_forward.py +++ b/deepspeech/modules/positionwise_feed_forward.py @@ -12,12 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. """Positionwise feed forward layer definition.""" -import logging +from deepspeech.utils.log import Log import paddle from paddle import nn -logger = logging.getLogger(__name__) +logger = Log(__name__).getlog() __all__ = ["PositionwiseFeedForward"] diff --git a/deepspeech/modules/rnn.py b/deepspeech/modules/rnn.py index 22dd13a44bdeacca6b6930fbd47058c5c68d535b..6d26fb4f886275feb42ade580b434c260e488a1b 100644 --- a/deepspeech/modules/rnn.py +++ b/deepspeech/modules/rnn.py @@ -13,7 +13,7 @@ # limitations under the License. import math -import logging +from deepspeech.utils.log import Log import paddle from paddle import nn @@ -23,7 +23,7 @@ from paddle.nn import initializer as I from deepspeech.modules.mask import sequence_mask from deepspeech.modules.activation import brelu -logger = logging.getLogger(__name__) +logger = Log(__name__).getlog() __all__ = ['RNNStack'] diff --git a/deepspeech/modules/subsampling.py b/deepspeech/modules/subsampling.py index b337089620285bcd354fda1df8ed73ed5cb558dc..8ffb20cfbedfc67047ab755c65966a382e899aef 100644 --- a/deepspeech/modules/subsampling.py +++ b/deepspeech/modules/subsampling.py @@ -14,14 +14,14 @@ """Subsampling layer definition.""" from typing import Tuple -import logging +from deepspeech.utils.log import Log import paddle from paddle import nn from deepspeech.modules.embedding import PositionalEncoding -logger = logging.getLogger(__name__) +logger = Log(__name__).getlog() __all__ = [ "LinearNoSubsampling", "Conv2dSubsampling4", "Conv2dSubsampling6", diff --git a/deepspeech/training/gradclip.py b/deepspeech/training/gradclip.py index b52bb981df8e48562714ad3a3f9f4e54ca051d1a..8f62383d4121c6f2ab8f9aaad21e1d5b252615ca 100644 --- a/deepspeech/training/gradclip.py +++ b/deepspeech/training/gradclip.py @@ -12,17 +12,17 @@ # See the License for the specific language governing permissions and # limitations under the License. -import logging +from deepspeech.utils.log import Log import paddle from paddle.fluid.dygraph import base as imperative_base from paddle.fluid import layers from paddle.fluid import core -logger = logging.getLogger(__name__) - __all__ = ["ClipGradByGlobalNormWithLog"] +logger = Log(__name__).getlog() + class ClipGradByGlobalNormWithLog(paddle.nn.ClipGradByGlobalNorm): def __init__(self, clip_norm): diff --git a/deepspeech/training/scheduler.py b/deepspeech/training/scheduler.py index 5144ca5aef469c9df19f9dd7e8b7653be927a3e7..b2400a73a04a812579f42a38e14cbb20cb384fdf 100644 --- a/deepspeech/training/scheduler.py +++ b/deepspeech/training/scheduler.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import logging +from deepspeech.utils.log import Log from typing import Union from typeguard import check_argument_types @@ -20,7 +20,7 @@ from paddle.optimizer.lr import LRScheduler __all__ = ["WarmupLR"] -logger = logging.getLogger(__name__) +logger = Log(__name__).getlog() class WarmupLR(LRScheduler): diff --git a/deepspeech/training/trainer.py b/deepspeech/training/trainer.py index 7a9748cf6bfb9fa9258f50805f36f78a812f34d1..d172d02dda2932e486a962211646946e7df537b0 100644 --- a/deepspeech/training/trainer.py +++ b/deepspeech/training/trainer.py @@ -13,7 +13,7 @@ # limitations under the License. import time -import logging +from deepspeech.utils.log import Log from pathlib import Path import paddle @@ -25,7 +25,7 @@ from deepspeech.utils import mp_tools __all__ = ["Trainer"] -logger = logging.getLogger(__name__) +logger = Log(__name__).getlog() class Trainer(): diff --git a/deepspeech/utils/checkpoint.py b/deepspeech/utils/checkpoint.py index c674b11179905c3ff5244e2d343a0c7d5293d4bc..1174d8559fb7da04581a7e4b84d0ea9acfbf6f1d 100644 --- a/deepspeech/utils/checkpoint.py +++ b/deepspeech/utils/checkpoint.py @@ -13,7 +13,7 @@ # limitations under the License. import os -import logging +from deepspeech.utils.log import Log import re import json from typing import Union @@ -24,7 +24,7 @@ from paddle.optimizer import Optimizer from deepspeech.utils import mp_tools -logger = logging.getLogger(__name__) +logger = Log(__name__).getlog() __all__ = ["load_parameters", "save_parameters"] diff --git a/deepspeech/utils/ctc_utils.py b/deepspeech/utils/ctc_utils.py index 9517b8d647c69a8f730a8c80bde266e75ff1c4f7..fe646450259034ef8ea2703f5bfec24f5d88f65f 100644 --- a/deepspeech/utils/ctc_utils.py +++ b/deepspeech/utils/ctc_utils.py @@ -12,13 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import logging +from deepspeech.utils.log import Log import numpy as np from typing import List import paddle -logger = logging.getLogger(__name__) +logger = Log(__name__).getlog() __all__ = ["forced_align", "remove_duplicates_and_blank", "insert_blank"] diff --git a/deepspeech/utils/log.py b/deepspeech/utils/log.py new file mode 100644 index 0000000000000000000000000000000000000000..b5168342dd32f52cb2ea9f82b7169a9b34d98a7a --- /dev/null +++ b/deepspeech/utils/log.py @@ -0,0 +1,52 @@ +# 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 diff --git a/deepspeech/utils/tensor_utils.py b/deepspeech/utils/tensor_utils.py index 66d40e673f641e70f5e7eb184a4aaef0d0771ece..0a78125f83d4dbfe688a860e85b9551ab123c427 100644 --- a/deepspeech/utils/tensor_utils.py +++ b/deepspeech/utils/tensor_utils.py @@ -12,15 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. """Unility functions for Transformer.""" -import logging +from deepspeech.utils.log import Log from typing import Tuple, List import paddle -logger = logging.getLogger(__name__) - __all__ = ["pad_sequence", "add_sos_eos", "th_accuracy"] +logger = Log(__name__).getlog() + def pad_sequence(sequences: List[paddle.Tensor], batch_first: bool=False,