示例#1
0
def eval_ssd(split_id, tid):
    exe = os.path.join(settings.CAFFE_ROOT, '.build_release', 'examples',
                       'ssd', 'ssd_detect.bin')
    deploy = os.path.join(settings.PRODUCTS_ROOT, 'models', 'SSD_512x512',
                          'deploy.prototxt')
    model = last_caffemodel(
        os.path.join(settings.PRODUCTS_ROOT, 'models', 'SSD_512x512'))
    test_list = darknet_tools.append_before_ext(settings.TEST_LIST,
                                                '.{}'.format(split_id))
    args = [exe, deploy, model, test_list]

    stdout_reopen = darknet_tools.append_before_ext(settings.TEST_RESULTS_OUT,
                                                    '.{}'.format(split_id))

    new_env = os.environ.copy()
    if 'CUDA_VISIBLE_DEVICES' in new_env:
        env['CUDA_VISIBLE_DEVICES'] = new_env['CUDA_VISIBLE_DEVICES']
    if 1 != settings.TEST_NUM_GPU:
        env['CUDA_VISIBLE_DEVICES'] = '{}'.format(tid % settings.TEST_NUM_GPU)
    new_env.update(env)

    for k, v in env.items():
        print('{}={}'.format(k, v), end=' ')
    print(*args)
    p = subprocess.Popen(' '.join(args + ['>{}'.format(stdout_reopen)]),
                         env=new_env,
                         shell=True)
    p.wait()
    assert 0 == p.returncode
示例#2
0
文件: eval.py 项目: KarmaGa/CTW
def eval_yolo(split_id, tid):
    exefile = os.path.join(settings.DARKNET_ROOT, 'darknet')
    last_backup = darknet_tools.last_backup(settings.DARKNET_BACKUP_DIR)
    assert last_backup is not None
    darknet_data = darknet_tools.append_before_ext(settings.DARKNET_DATA,
                                                   '.{}'.format(split_id))
    darknet_results_out = darknet_tools.append_before_ext(
        settings.DARKNET_RESULTS_OUT, '.{}'.format(split_id))

    args = [
        exefile, 'detector', 'valid', darknet_data, settings.DARKNET_TEST_CFG,
        last_backup, '-out', darknet_results_out
    ]

    new_env = os.environ.copy()
    if 'CUDA_VISIBLE_DEVICES' in new_env:
        env['CUDA_VISIBLE_DEVICES'] = new_env['CUDA_VISIBLE_DEVICES']
    if 1 != settings.TEST_NUM_GPU:
        env['CUDA_VISIBLE_DEVICES'] = '{}'.format(tid % settings.TEST_NUM_GPU)
    new_env.update(env)

    for k, v in env.items():
        print('{}={}'.format(k, v), end=' ')
    print(*args)
    p = subprocess.Popen(args, env=new_env, shell=False)
    p.wait()
    assert 0 == p.returncode
示例#3
0
 def write_ssd_test_data(split_id):
     test_list = darknet_tools.append_before_ext(settings.TEST_LIST,
                                                 '.{}'.format(split_id))
     with open(test_list, 'w') as f:
         for line in ls[split_id * len(ls) //
                        settings.TEST_SPLIT_NUM:(1 + split_id) * len(ls) //
                        settings.TEST_SPLIT_NUM]:
             f.write(line)
             f.write('\n')
示例#4
0
def write_darknet_test_data(split_id):
    darknet_valid_list = darknet_tools.append_before_ext(settings.DARKNET_VALID_LIST, '.{}'.format(split_id))
    with open(settings.DARKNET_VALID_LIST) as f:
        ls = f.read().splitlines()
    with open(darknet_valid_list, 'w') as f:
        for line in ls[split_id * len(ls) // settings.TEST_SPLIT_NUM:(1 + split_id) * len(ls) // settings.TEST_SPLIT_NUM]:
            f.write(line)
            f.write('\n')

    darknet_data = darknet_tools.append_before_ext(settings.DARKNET_DATA, '.{}'.format(split_id))
    data = {
        'classes': settings.NUM_CHAR_CATES + 1,
        'valid': darknet_valid_list,
        'names': settings.DARKNET_NAMES,
        'results': settings.DARKNET_RESULTS_DIR,
        'eval': 'chinese',
    }
    with open(darknet_data, 'w') as f:
        for k, v in sorted(data.items()):
            f.write('{} = {}\n'.format(k, v))
示例#5
0
def main():
    dn_merge = imp.load_source('dn_merge', '../detection/merge_results.py')

    file_paths = []
    for split_id in range(settings.TEST_SPLIT_NUM):
        result_file_path = darknet_tools.append_before_ext(settings.TEST_RESULTS_OUT, '.{}'.format(split_id))
        file_paths.append(result_file_path)

    print('loading ssd outputs')
    unmerged = read(file_paths)

    print('doing nms sort')
    nms_sorted = dn_merge.do_nms_sort(unmerged, .5)

    print('writing results')
    dn_merge.write(nms_sorted, os.path.join(settings.PRODUCTS_ROOT, 'proposals.jsonl' if proposal_output else 'detections.jsonl'))
示例#6
0
def main():
    file_paths = []
    for split_id in range(settings.TEST_SPLIT_NUM):
        darknet_results_out = darknet_tools.append_before_ext(
            settings.DARKNET_RESULTS_OUT, '.{}'.format(split_id))
        result_file_path = os.path.join(settings.DARKNET_RESULTS_DIR,
                                        '{}.txt'.format(darknet_results_out))
        file_paths.append(result_file_path)

    print('loading darknet outputs')
    unmerged = read(file_paths)

    print('doing nms sort')
    nms_sorted = do_nms_sort(unmerged, .5)

    print('writing results')
    write(
        nms_sorted,
        os.path.join(
            settings.PRODUCTS_ROOT,
            'proposals.jsonl' if proposal_output else 'detections.jsonl'))