def main(model_path, epoch):

    # Load config file
    with open(os.path.join(model_path, 'config.yml'), "r") as f:
        config = yaml.load(f)
        param = config['param']

    # Except for a blank label
    if param['label_type_sub'] == 'phone61':
        param['num_classes_sub'] = 61
    elif param['label_type_sub'] == 'phone48':
        param['num_classes_sub'] = 48
    elif param['label_type_sub'] == 'phone39':
        param['num_classes_sub'] = 39

    # Model setting
    CTCModel = load(model_type=config['model_name'])
    network = CTCModel(batch_size=1,
                       input_size=param['input_size'] * param['num_stack'],
                       num_unit=param['num_unit'],
                       num_layer_main=param['num_layer_main'],
                       num_layer_sub=param['num_layer_sub'],
                       num_classes_main=30,
                       num_classes_sub=param['num_classes_sub'],
                       main_task_weight=param['main_task_weight'],
                       clip_grad=param['clip_grad'],
                       clip_activation=param['clip_activation'],
                       dropout_ratio_input=param['dropout_input'],
                       dropout_ratio_hidden=param['dropout_hidden'],
                       num_proj=param['num_proj'],
                       weight_decay=param['weight_decay'])

    network.model_dir = model_path
    print(network.model_dir)
    do_plot(network=network, param=param, epoch=epoch)
def main(model_path):

    epoch = None  # if None, restore the final epoch

    # Load config file
    with open(os.path.join(model_path, 'config.yml'), "r") as f:
        config = yaml.load(f)
        corpus = config['corpus']
        feature = config['feature']
        param = config['param']

    if corpus['label_type_second'] == 'phone61':
        output_size_second = 61
    elif corpus['label_type_second'] == 'phone48':
        output_size_second = 48
    elif corpus['label_type_second'] == 'phone39':
        output_size_second = 39

    # Model setting
    CTCModel = load(model_type=config['model_name'])
    network = CTCModel(batch_size=1,
                       input_size=feature['input_size'] * feature['num_stack'],
                       num_unit=param['num_unit'],
                       num_layer_main=param['num_layer_main'],
                       num_layer_second=param['num_layer_second'],
                       output_size_main=30,
                       output_size_second=output_size_second,
                       main_task_weight=param['main_task_weight'],
                       parameter_init=param['weight_init'],
                       clip_grad=param['clip_grad'],
                       clip_activation=param['clip_activation'],
                       dropout_ratio_input=param['dropout_input'],
                       dropout_ratio_hidden=param['dropout_hidden'],
                       num_proj=param['num_proj'],
                       weight_decay=param['weight_decay'])

    network.model_dir = model_path
    print(network.model_dir)
    do_eval(network=network,
            label_type_second=corpus['label_type_second'],
            num_stack=feature['num_stack'],
            num_skip=feature['num_skip'],
            epoch=epoch)
def main(config_path):

    # Load a config file (.yml)
    with open(config_path, "r") as f:
        config = yaml.load(f)
        param = config['param']

    if param['label_type_sub'] == 'phone61':
        param['num_classes_sub'] = 61
    elif param['label_type_sub'] == 'phone48':
        param['num_classes_sub'] = 48
    elif param['label_type_sub'] == 'phone39':
        param['num_classes_sub'] = 39

    # Model setting
    CTCModel = load(model_type=param['model'])
    network = CTCModel(batch_size=param['batch_size'],
                       input_size=param['input_size'] * param['num_stack'],
                       num_unit=param['num_unit'],
                       num_layer_main=param['num_layer_main'],
                       num_layer_sub=param['num_layer_sub'],
                       num_classes_main=33,
                       num_classes_sub=param['num_classes_sub'],
                       main_task_weight=param['main_task_weight'],
                       parameter_init=param['weight_init'],
                       clip_grad=param['clip_grad'],
                       clip_activation=param['clip_activation'],
                       dropout_ratio_input=param['dropout_input'],
                       dropout_ratio_hidden=param['dropout_hidden'],
                       num_proj=param['num_proj'],
                       weight_decay=param['weight_decay'])

    network.model_name = param['model']
    network.model_name += '_' + str(param['num_unit'])
    network.model_name += '_main' + str(param['num_layer_main'])
    network.model_name += '_sub' + str(param['num_layer_sub'])
    network.model_name += '_' + param['optimizer']
    network.model_name += '_lr' + str(param['learning_rate'])
    if param['num_proj'] != 0:
        network.model_name += '_proj' + str(param['num_proj'])
    if param['dropout_input'] != 1:
        network.model_name += '_dropi' + str(param['dropout_input'])
    if param['dropout_hidden'] != 1:
        network.model_name += '_droph' + str(param['dropout_hidden'])
    if param['num_stack'] != 1:
        network.model_name += '_stack' + str(param['num_stack'])
    if param['weight_decay'] != 0:
        network.model_name += '_weightdecay' + str(param['weight_decay'])
    network.model_name += '_taskweight' + str(param['main_task_weight'])
    if param['decay_rate'] != 1:
        network.model_name += '_lrdecay' + \
            str(param['decay_steps'] + param['decay_rate'])

    # Set save path
    network.model_dir = mkdir('/n/sd8/inaguma/result/timit/')
    network.model_dir = mkdir_join(network.model_dir, 'ctc')
    network.model_dir = mkdir_join(network.model_dir,
                                   'char_' + param['label_type_sub'])
    network.model_dir = mkdir_join(network.model_dir, network.model_name)

    # Reset model directory
    if not isfile(join(network.model_dir, 'complete.txt')):
        tf.gfile.DeleteRecursively(network.model_dir)
        tf.gfile.MakeDirs(network.model_dir)
    else:
        raise ValueError('File exists.')

    # Set process name
    setproctitle('timit_multictc')

    # Save config file
    shutil.copyfile(config_path, join(network.model_dir, 'config.yml'))

    sys.stdout = open(join(network.model_dir, 'train.log'), 'w')
    print(network.model_name)
    do_train(network=network, param=param)
def main(config_path):

    # Load a config file (.yml)
    with open(config_path, "r") as f:
        config = yaml.load(f)
        corpus = config['corpus']
        feature = config['feature']
        param = config['param']

    if corpus['label_type_second'] == 'phone61':
        output_size_second = 61
    elif corpus['label_type_second'] == 'phone48':
        output_size_second = 48
    elif corpus['label_type_second'] == 'phone39':
        output_size_second = 39

    # Model setting
    CTCModel = load(model_type=config['model_name'])
    network = CTCModel(batch_size=param['batch_size'],
                       input_size=feature['input_size'] * feature['num_stack'],
                       num_unit=param['num_unit'],
                       num_layer_main=param['num_layer_main'],
                       num_layer_second=param['num_layer_second'],
                       #    bottleneck_dim=param['bottleneck_dim'],
                       output_size_main=30,
                       output_size_second=output_size_second,
                       main_task_weight=param['main_task_weight'],
                       parameter_init=param['weight_init'],
                       clip_grad=param['clip_grad'],
                       clip_activation=param['clip_activation'],
                       dropout_ratio_input=param['dropout_input'],
                       dropout_ratio_hidden=param['dropout_hidden'],
                       num_proj=param['num_proj'],
                       weight_decay=param['weight_decay'])

    network.model_name = config['model_name'].upper()
    network.model_name += '_' + str(param['num_unit'])
    network.model_name += '_main' + str(param['num_layer_main'])
    network.model_name += '_second' + str(param['num_layer_second'])
    network.model_name += '_' + param['optimizer']
    network.model_name += '_lr' + str(param['learning_rate'])
    if param['num_proj'] != 0:
        network.model_name += '_proj' + str(param['num_proj'])
    if feature['num_stack'] != 1:
        network.model_name += '_stack' + str(feature['num_stack'])
    if param['weight_decay'] != 0:
        network.model_name += '_weightdecay' + str(param['weight_decay'])
    network.model_name += '_taskweight' + str(param['main_task_weight'])

    # Set save path
    network.model_dir = mkdir('/n/sd8/inaguma/result/timit/')
    network.model_dir = mkdir_join(network.model_dir, 'ctc')
    network.model_dir = mkdir_join(
        network.model_dir, 'char_' + corpus['label_type_second'])
    network.model_dir = mkdir_join(network.model_dir, network.model_name)

    # Reset model directory
    if not isfile(join(network.model_dir, 'complete.txt')):
        tf.gfile.DeleteRecursively(network.model_dir)
        tf.gfile.MakeDirs(network.model_dir)
    else:
        raise ValueError('File exists.')

    # Set process name
    setproctitle('multitaskctc_timit')

    # Save config file
    shutil.copyfile(config_path, join(network.model_dir, 'config.yml'))

    sys.stdout = open(join(network.model_dir, 'train.log'), 'w')
    print(network.model_name)
    do_train(network=network,
             optimizer=param['optimizer'],
             learning_rate=param['learning_rate'],
             batch_size=param['batch_size'],
             epoch_num=param['num_epoch'],
             label_type_second=corpus['label_type_second'],
             num_stack=feature['num_stack'],
             num_skip=feature['num_skip'])
    sys.stdout = sys.__stdout__
Ejemplo n.º 5
0
def main(config_path):

    # Read a config file (.yml)
    with open(config_path, "r") as f:
        config = yaml.load(f)
        param = config['param']

    # Except for a blank label
    if param['label_type_main'] == 'kanji':
        param['num_classes_main'] = 3386
    elif param['label_type_main'] == 'kana':
        param['num_classes_main'] = 147

    if param['label_type_sub'] == 'kana':
        param['num_classes_sub'] = 147
    elif param['label_type_sub'] == 'phone':
        param['num_classes_sub'] = 38

    # Model setting
    CTCModel = load(model_type=param['model'])
    network = CTCModel(
        batch_size=param['batch_size'],
        input_size=param['input_size'] * param['num_stack'],
        num_unit=param['num_unit'],
        num_layer_main=param['num_layer_main'],
        num_layer_sub=param['num_layer_sub'],
        #    bottleneck_dim=param['bottleneck_dim'],
        num_classes_main=param['num_classes_main'],
        num_classes_sub=param['num_classes_sub'],
        main_task_weight=param['main_task_weight'],
        parameter_init=param['weight_init'],
        clip_grad=param['clip_grad'],
        clip_activation=param['clip_activation'],
        dropout_ratio_input=param['dropout_input'],
        dropout_ratio_hidden=param['dropout_hidden'],
        num_proj=param['num_proj'],
        weight_decay=param['weight_decay'])

    network.model_name = param['model']
    network.model_name += '_' + str(param['num_unit'])
    network.model_name += '_main' + str(param['num_layer_main'])
    network.model_name += '_sub' + str(param['num_layer_sub'])
    network.model_name += '_' + param['optimizer']
    network.model_name += '_lr' + str(param['learning_rate'])
    if param['bottleneck_dim'] != 0:
        network.model_name += '_bottoleneck' + str(param['bottleneck_dim'])
    if param['num_proj'] != 0:
        network.model_name += '_proj' + str(param['num_proj'])
    if param['num_stack'] != 1:
        network.model_name += '_stack' + str(param['num_stack'])
    if param['weight_decay'] != 0:
        network.model_name += '_weightdecay' + str(param['weight_decay'])
    network.model_name += '_taskweight' + str(param['main_task_weight'])
    if param['train_data_size'] == 'large':
        network.model_name += '_large'

    # Set save path
    network.model_dir = mkdir('/n/sd8/inaguma/result/csj/')
    network.model_dir = mkdir_join(network.model_dir, 'ctc')
    network.model_dir = mkdir_join(
        network.model_dir,
        param['label_type_main'] + '_' + param['label_type_sub'])
    network.model_dir = mkdir_join(network.model_dir, network.model_name)

    # Reset model directory
    if not isfile(join(network.model_dir, 'complete.txt')):
        tf.gfile.DeleteRecursively(network.model_dir)
        tf.gfile.MakeDirs(network.model_dir)
    else:
        raise ValueError('File exists.')

    # Set process name
    setproctitle('csj_multictc_' + param['label_type_main'] + '_' +
                 param['label_type_sub'] + '_' + param['train_data_size'])

    # Save config file
    shutil.copyfile(config_path, join(network.model_dir, 'config.yml'))

    sys.stdout = open(join(network.model_dir, 'train.log'), 'w')
    print(network.model_name)
    do_train(network=network, param=param)
    sys.stdout = sys.__stdout__