Exemplo n.º 1
0
def main():
    # Reading option
    parser = argparse.ArgumentParser()
    parser.add_argument('-opt', type=str, help='Path to option YAML file.')
    args = parser.parse_args()

    opt = parse(args.opt, is_tain=True)
    logger = get_logger(__name__)

    logger.info('Building the model of Conv-TasNet')
    net = ConvTasNet(**opt['net_conf'])

    logger.info('Building the trainer of Conv-TasNet')
    gpuid = tuple(opt['gpu_ids'])
    trainer = Trainer(net,
                      **opt['train'],
                      resume=opt['resume'],
                      gpuid=gpuid,
                      optimizer_kwargs=opt['optimizer_kwargs'])

    logger.info('Making the train and test data loader')
    train_loader = make_dataloader(is_train=True,
                                   data_kwargs=opt['datasets']['train'],
                                   num_workers=opt['datasets']['num_workers'],
                                   chunk_size=opt['datasets']['chunk_size'],
                                   batch_size=opt['datasets']['batch_size'])
    val_loader = make_dataloader(is_train=True,
                                 data_kwargs=opt['datasets']['val'],
                                 num_workers=opt['datasets']['num_workers'],
                                 chunk_size=opt['datasets']['chunk_size'],
                                 batch_size=opt['datasets']['batch_size'])

    trainer.run(train_loader, val_loader)
Exemplo n.º 2
0
 def __init__(self, mix_path, yaml_path, model, gpuid):
     super(Separation, self).__init__()
     self.mix = AudioReader(mix_path, sample_rate=8000)
     opt = parse(yaml_path, is_tain=False)
     net = ConvTasNet(**opt['net_conf'])
     dicts = torch.load(model, map_location='cpu')
     net.load_state_dict(dicts["model_state_dict"])
     self.logger = get_logger(__name__)
     self.logger.info('Load checkpoint from {}, epoch {: d}'.format(
         model, dicts["epoch"]))
     self.net = net.cuda()
     self.device = torch.device(
         'cuda:{}'.format(gpuid[0]) if len(gpuid) > 0 else 'cpu')
     self.gpuid = tuple(gpuid)
Exemplo n.º 3
0
    else:
        gpus = None
    # logger

    # default logger used by trainer
    logger = TensorBoardLogger(save_dir='./logger',
                               version=1,
                               name='lightning_logs')
    # Trainer
    trainer = pl.Trainer(
        max_epochs=opt['train']['epochs'],
        checkpoint_callback=checkpoint,
        early_stop_callback=early_stopping,
        default_root_dir=checkpoint_path,
        gpus=gpus,
        distributed_backend=opt['train']['distributed_backend'],
        train_percent_check=1.0,  # Useful for fast experiment
        gradient_clip_val=5.,
        logger=logger)

    trainer.fit(light)


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument('--opt', type=str, help='Path to option YAML file.')
    args = parser.parse_args()

    opt = parse(args.opt, is_train=True)
    Train(opt)
Exemplo n.º 4
0
    special_case = [
        u"上季度底"
    ]

    for case in special_case:
        print(case)
        times = time_parse(sentence=case, splits=None, pos=0, endpos=len(case), args=args)
        for t in times: print(t)
        print("")



def test(args):
    import autotest
    autotest.test(args)



if __name__ == '__main__':
    # parse args
    args = option.parse()

    if args.command == 'demo':
        demo(args)
    elif args.command == 'test':
        test(args)
    else:
        print("invalid command")


Exemplo n.º 5
0
import option
import wsgi_httpserver
from coordinator import Coordinator


def create_logger(level=logging.INFO):
    logging.basicConfig(level=logging.INFO,
                        stream=sys.stderr,
                        format='%(asctime)s %(levelname)s %(message)s')
    return logging.getLogger()


if __name__ == '__main__':

    opt = option.parse(__doc__, ['port=', 'interface='], ['port'],
                       {'interface': ''})
    log = create_logger()

    log.info('hello')

    # TODO
    # pre-fork hub
    # http://groups.google.com/group/gevent/browse_thread/thread/44b756976698503b

    env = {'rain.log': log, 'rain.coordinator': Coordinator(log)}
    server = wsgi_httpserver.create(opt['interface'], opt['port'], log, env)
    try:
        server.serve_forever()
    except KeyboardInterrupt:
        print
        log.info('recd KeyboardInterrupt; shutting down')
Exemplo n.º 6
0
    start = time.time ()
    params = socket_recv.all (socket)
    povray.render_to_socket (params, socket)
    socket.close ()
    print ('%s: %0.2f ms' % (params, (time.time () - start)*1000))

def register (master_url, my_addr):
    urlopen ('%s/worker/register?ip=%s&port=%d' % ((master_url,) + my_addr))
def unregister (master_url, my_addr):
    urlopen ('%s/worker/unregister?ip=%s&port=%d' % ((master_url,) + my_addr))


if __name__ == '__main__':

    opt = option.parse (__doc__, 
            ['port=', 'interface=', 'master-url='], 
            ['port', 'master-url'], {'interface': ''})
    addr = (opt['interface'], int (opt['port']))
    master = opt['master-url']

    print 'starting worker on %s:%s' % addr
    server = gevent.server.StreamServer (addr, handler)
    server.pre_start ()

    register (master, addr)

    try:
        server.serve_forever ()
    except KeyboardInterrupt:
        print
    except: