|
|
@ -9,43 +9,45 @@ from data_utils.normalizer import FeatureNormalizer
|
|
|
|
from data_utils.augmentor.augmentation import AugmentationPipeline
|
|
|
|
from data_utils.augmentor.augmentation import AugmentationPipeline
|
|
|
|
from data_utils.featurizer.audio_featurizer import AudioFeaturizer
|
|
|
|
from data_utils.featurizer.audio_featurizer import AudioFeaturizer
|
|
|
|
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
|
|
|
|
description='Computing mean and stddev for feature normalizer.')
|
|
|
|
def add_arg(argname, type, default, help, **kwargs):
|
|
|
|
parser.add_argument(
|
|
|
|
type = distutils.util.strtobool if type == bool else type
|
|
|
|
"--specgram_type",
|
|
|
|
parser.add_argument(
|
|
|
|
default='linear',
|
|
|
|
"--" + argname,
|
|
|
|
type=str,
|
|
|
|
default=default,
|
|
|
|
help="Feature type of audio data: 'linear' (power spectrum)"
|
|
|
|
type=type,
|
|
|
|
" or 'mfcc'. (default: %(default)s)")
|
|
|
|
help=help + ' Default: %(default)s.',
|
|
|
|
parser.add_argument(
|
|
|
|
**kwargs)
|
|
|
|
"--manifest_path",
|
|
|
|
|
|
|
|
default='datasets/manifest.train',
|
|
|
|
|
|
|
|
type=str,
|
|
|
|
# yapf: disable
|
|
|
|
help="Manifest path for computing normalizer's mean and stddev."
|
|
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
|
|
"(default: %(default)s)")
|
|
|
|
add_arg('num_samples', int, 2000, "# of samples to for statistics.")
|
|
|
|
parser.add_argument(
|
|
|
|
add_arg('specgram_type', str,
|
|
|
|
"--num_samples",
|
|
|
|
'linear',
|
|
|
|
default=2000,
|
|
|
|
"Audio feature type. Options: linear, mfcc.",
|
|
|
|
type=int,
|
|
|
|
choices=['linear', 'mfcc'])
|
|
|
|
help="Number of samples for computing mean and stddev. "
|
|
|
|
add_arg('manifest_path', str,
|
|
|
|
"(default: %(default)s)")
|
|
|
|
'datasets/manifest.train',
|
|
|
|
parser.add_argument(
|
|
|
|
"Filepath of manifest to compute normalizer's mean and stddev.")
|
|
|
|
"--augmentation_config",
|
|
|
|
add_arg('output_path', str,
|
|
|
|
default='{}',
|
|
|
|
'mean_std.npz',
|
|
|
|
type=str,
|
|
|
|
"Filepath of write mean and stddev to (.npz).")
|
|
|
|
help="Augmentation configuration in json-format. "
|
|
|
|
|
|
|
|
"(default: %(default)s)")
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
|
|
|
"--output_file",
|
|
|
|
|
|
|
|
default='mean_std.npz',
|
|
|
|
|
|
|
|
type=str,
|
|
|
|
|
|
|
|
help="Filepath to write mean and std to (.npz)."
|
|
|
|
|
|
|
|
"(default: %(default)s)")
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
# yapf: disable
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def print_arguments(args):
|
|
|
|
|
|
|
|
print("----------- Configuration Arguments -----------")
|
|
|
|
|
|
|
|
for arg, value in sorted(vars(args).iteritems()):
|
|
|
|
|
|
|
|
print("%s: %s" % (arg, value))
|
|
|
|
|
|
|
|
print("------------------------------------------------")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
def main():
|
|
|
|
augmentation_pipeline = AugmentationPipeline(args.augmentation_config)
|
|
|
|
print_arguments(args)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
augmentation_pipeline = AugmentationPipeline('{}')
|
|
|
|
audio_featurizer = AudioFeaturizer(specgram_type=args.specgram_type)
|
|
|
|
audio_featurizer = AudioFeaturizer(specgram_type=args.specgram_type)
|
|
|
|
|
|
|
|
|
|
|
|
def augment_and_featurize(audio_segment):
|
|
|
|
def augment_and_featurize(audio_segment):
|
|
|
@ -57,7 +59,7 @@ def main():
|
|
|
|
manifest_path=args.manifest_path,
|
|
|
|
manifest_path=args.manifest_path,
|
|
|
|
featurize_func=augment_and_featurize,
|
|
|
|
featurize_func=augment_and_featurize,
|
|
|
|
num_samples=args.num_samples)
|
|
|
|
num_samples=args.num_samples)
|
|
|
|
normalizer.write_to_file(args.output_file)
|
|
|
|
normalizer.write_to_file(args.output_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if __name__ == '__main__':
|
|
|
|