コード例 #1
0
def test(test_loader, target_net):
    box_num = np.array([0, 0])
    correct_cnt, total_cnt = np.array([0, 0]), np.array([0, 0])
    print '========== Testing ======='
    results_obj = []
    results_region = []

    batch_time = network.AverageMeter()
    end = time.time()
    im_counter = 0
    for i, sample in enumerate(test_loader):
        correct_cnt_t, total_cnt_t = np.array([0, 0]), np.array([0, 0])
        # Forward pass

        # measure the data loading time
        im_data = Variable(sample['visual'].cuda(), volatile=True)
        im_counter += im_data.size(0)
        im_info = sample['image_info']
        gt_objects = sample['objects']
        gt_regions = sample['regions']
        object_rois, region_rois = target_net(im_data, im_info)[1:]
        results_obj.append(object_rois.cpu().data.numpy())
        results_region.append(region_rois.cpu().data.numpy())
        box_num[0] += object_rois.size(0)
        box_num[1] += region_rois.size(0)
        correct_cnt_t[0], total_cnt_t[0] = check_recall(
            object_rois, gt_objects, 50)
        correct_cnt_t[1], total_cnt_t[1] = check_recall(
            region_rois, gt_regions, 50)
        correct_cnt += correct_cnt_t
        total_cnt += total_cnt_t
        batch_time.update(time.time() - end)
        end = time.time()
        if (i + 1) % 100 == 0 and i > 0:
            print(
                '[{0}/{10}]  Time: {1:2.3f}s/img).'
                '\t[object] Avg: {2:2.2f} Boxes/im, Top-50 recall: {3:2.3f} ({4:d}/{5:d})'
                '\t[region] Avg: {6:2.2f} Boxes/im, Top-50 recall: {7:2.3f} ({8:d}/{9:d})'
                .format(i + 1, batch_time.avg, box_num[0] / float(im_counter),
                        correct_cnt[0] / float(total_cnt[0]) * 100,
                        correct_cnt[0], total_cnt[0],
                        box_num[1] / float(im_counter),
                        correct_cnt[1] / float(total_cnt[1]) * 100,
                        correct_cnt[1], total_cnt[1], len(test_loader)))

    recall = correct_cnt / total_cnt.astype(np.float)
    print '====== Done Testing ===='
    return recall, results_obj, results_region
コード例 #2
0
def test(test_loader, target_net):
    box_num = 0
    correct_cnt, total_cnt = 0., 0.
    print '========== Testing ======='

    results = []

    batch_time = network.AverageMeter()
    end = time.time()
    im_counter = 0
    for i, sample in enumerate(test_loader):
        correct_cnt_t, total_cnt_t = 0., 0.
        # Forward pass
        im_data = Variable(sample['visual'].cuda(), volatile=True)
        im_counter += im_data.size(0)
        im_info = sample['image_info']
        gt_objects = sample['objects']
        object_rois = target_net(im_data, im_info)[1]
        results.append(object_rois.cpu().data.numpy())
        box_num += object_rois.size(0)
        correct_cnt_t, total_cnt_t = check_recall(object_rois, gt_objects, 200)
        correct_cnt += correct_cnt_t
        total_cnt += total_cnt_t
        batch_time.update(time.time() - end)
        end = time.time()
        if (i + 1) % 100 == 0 and i > 0:
            print('[{0}/{6}]  Time: {1:2.3f}s/img).'
                  '\t[object] Avg: {2:2.2f} Boxes/im, Top-200 recall: {3:2.3f} ({4:.0f}/{5:.0f})'.format(
                    i + 1, batch_time.avg,
                    box_num / float(im_counter), correct_cnt / float(total_cnt)* 100, correct_cnt, total_cnt,
                    len(test_loader)))

    recall = correct_cnt / float(total_cnt)
    print '====== Done Testing ===='
    return recall, results