Example #1
0
def set_config():
    if opt.config:
        config = parse_config(opt.config)
    else:
        raise_exception('--config must be specified.')

    if isinstance(config.DATA.SCALE, int):
        config.DATA.SCALE = (config.DATA.SCALE, config.DATA.SCALE)  # make tuple

    if not opt.tag:
        opt.tag = utils.get_file_name(opt.config)


    if opt.local_rank is not None:
        opt.gpu_id = opt.local_rank

    opt.device = 'cuda:' + str(opt.gpu_id) if torch.cuda.is_available() and opt.gpu_id != -1 else 'cpu'

    if opt.debug:
        config.MISC.SAVE_FREQ = 1
        config.MISC.VAL_FREQ = 1
        config.MISC.LOG_FREQ = 1

    if opt.tag != 'default':
        pid = f'[PID:{os.getpid()}]'
        with open('run_log.txt', 'a') as f:
            f.writelines(utils.get_time_str(fmt="%Y-%m-%d %H:%M:%S") + ' ' + pid + ' ' + get_command_run() + '\n')

    return config
def parse_runs(tag):
    template_root = os.path.abspath(os.path.join(app.root_path, '..'))
    logroot = os.path.join(template_root, 'logs')
    logpath = os.path.join(logroot, tag, 'meta.json')
    if not os.path.isfile(logpath):
        return []

    with open(logpath, 'r') as f:
        meta = json.load(f)

    runs = []
    for line in meta:
        run = {
            'command':
            line['command'],
            'starttime':
            misc_utils.get_time_str(line['starttime'], fmt='%Y-%m-%d %H:%M:%S')
        }
        if 'finishtime' in line:
            runtime = int(line['finishtime']) - int(line['starttime'])
        else:
            runtime = int(misc_utils.get_time_stamp()) - int(line['starttime'])
        run['runtime'] = misc_utils.format_time(runtime)
        runs.append(run)

    return runs
Example #3
0

def get_command_run():
    args = sys.argv.copy()
    args[0] = args[0].split('/')[-1]

    if 'CUDA_VISIBLE_DEVICES' in os.environ:
        gpu_id = os.environ['CUDA_VISIBLE_DEVICES']
        command = f'CUDA_VISIBLE_DEVICES={gpu_id} '
    else:
        command = ''

    if sys.version[0] == '3':
        command += 'python3'
    else:
        command += 'python'

    for i in args:
        command += ' ' + i
    return command


if opt.tag != 'cache':
    pid = f'[PID:{os.getpid()}]'
    with open('run_log.txt', 'a') as f:
        f.writelines(
            utils.get_time_str(fmt="%Y-%m-%d %H:%M:%S") + ' ' + pid + ' ' +
            get_command_run() + '\n')

# utils.print_args(opt)
Example #4
0
opt = parse_args()

opt.device = 'cuda:' + opt.gpu_ids if torch.cuda.is_available() and opt.gpu_ids != '-1' else 'cpu'

if opt.debug:
    opt.save_freq = 1
    opt.eval_freq = 1
    opt.log_freq = 1


def get_command_run():
    args = sys.argv.copy()
    args[0] = args[0].split('/')[-1]

    if sys.version[0] == '3':
        command = 'python3'
    else:
        command = 'python'

    for i in args:
        command += ' ' + i
    return command


if opt.tag != 'cache':
    with open('run_log.txt', 'a') as f:
        f.writelines(utils.get_time_str(fmt="%Y-%m-%d %H:%M:%S") + ' ' + get_command_run() + '\n')

# utils.print_args(opt)