Example #1
0
def eval(opt):
    model = CycleGANModel(opt)
    dataset = CDFdata.get_loader(opt)
    img_logs,weight_logs = init_logs(opt)
    model.load(weight_logs)

    ave_loss = {}
    for batch_id, data in enumerate(dataset):
        model.set_input(data)
        model.test()

        errors = model.get_current_errors()
        display = '===> Batch({}/{})'.format(batch_id, len(dataset))
        for key, value in errors.items():
            display += '{}:{:.4f}  '.format(key, value)
            try:
                ave_loss[key] = ave_loss[key] + value
            except:
                ave_loss[key] = value
        print(display)

        if (batch_id + 1) % opt.display_gap == 0:
            path = os.path.join(img_logs, 'imgA_{}.jpg'.format(batch_id + 1))
            model.visual(path)
            model.save(weight_logs)

    display ='average loss: '
    for key, value in ave_loss.items():
        display += '{}:{:.4f}  '.format(key, value/len(dataset))
    print(display)
Example #2
0
def eval(opt):
    model = CycleGANModel(opt)
    dataset = CDFdata.get_loader(opt)
    img_logs, weight_logs = init_logs(opt)
    model.load(weight_logs)

    for batch_id, data in enumerate(dataset):
        print('===> Epoch({}/{})'.format(batch_id, len(dataset)))
        model.set_input(data)
        model.test()
        path = os.path.join(img_logs, 'imgA_{}.jpg'.format(batch_id))
        model.visual(path)
Example #3
0
def train(opt):
    model = CycleGANModel(opt)
    # model = CycleActionModel(opt)
    dataset = CDFdata.get_loader(opt)
    img_logs,weight_logs = init_logs(opt)
    # model.load(weight_logs)

    for epoch_id in range(opt.epoch_size):
        for batch_id, data in enumerate(dataset):
            model.set_input(data)
            model.optimize_parameters()

            errors = model.get_current_errors()
            display = '===> Epoch[{}]({}/{})'.format(epoch_id, batch_id, len(dataset))
            for key, value in errors.items():
                display += '{}:{:.4f}  '.format(key, value)
            print(display)

            if (batch_id+1) % opt.display_gap == 0:
                path = os.path.join(img_logs, 'imgA_{}_{}.jpg'.format(epoch_id, batch_id+1))
                model.visual(path)
                model.save(weight_logs)
Example #4
0
# If true, the threads will be executed in background and
# the program will exit.
RUN_AS_DAEMON = False

# If true, the "main" thread will wait all other threads
# to be finished.
WAIT_THREADS = False


def main(pkg_version):
    main_thread = utils.thread_label('main', utils.RED)
    log.info(f'{main_thread} Creating threads...')

    sub_thread = Thread(target=utils.download_file,
                        args=(1, pkg_version, choice(utils.COLORS)),
                        daemon=RUN_AS_DAEMON)
    log.info(f'{main_thread} Ready? Go!')
    sub_thread.start()

    flag = "yes" if WAIT_THREADS else "no"
    log.info(f'{main_thread} Wait for the thread to finish? [{flag}]')
    if WAIT_THREADS:
        sub_thread.join()

    log.info(f'{main_thread} Done!')


if __name__ == '__main__':
    utils.init_logs()
    main('3.0.1')