Exemplo n.º 1
0
def get_test_acc(model, image_datasets, dataloaders, use_gpu, max_rank=10):

    gallery_path = image_datasets['gallery'].imgs
    query_path = image_datasets['query'].imgs
    try:
        g_camid, g_pid = get_id(gallery_path)
        q_camid, q_pid = get_id(query_path)
    except:
        g_camid, g_pid = get_id_CUHK(gallery_path)
        q_camid, q_pid = get_id_CUHK(query_path)

    if use_gpu:
        model = model.cuda()
    # Extract feature
    g_feas = extract_feature(model, dataloaders['gallery'])
    # print(g_feas.shape)
    # print("Extracted features for gallery set, obtained {}-by-{} matrix".format(g_feas.size(0), g_feas.size(1)))
    q_feas = extract_feature(model, dataloaders['query'])
    # print("Extracted features for gallery set, obtained {}-by-{} matrix".format(q_feas.size(0), q_feas.size(1)))

    distmat = np.matmul(q_feas.data.numpy(), np.transpose(
        g_feas.data.numpy())) * (-1.0)
    CMC, mAP = eval_market1501_wrap(distmat,
                                    q_pid,
                                    g_pid,
                                    q_camid,
                                    g_camid,
                                    max_rank=10)
    return CMC, mAP
Exemplo n.º 2
0
def evaluate(distmat, q_pids, g_pids, q_camids, g_camids, max_rank=50, use_metric_cuhk03=False, use_cython=True):
    if use_metric_cuhk03:
        return eval_cuhk03(distmat, q_pids, g_pids, q_camids, g_camids, max_rank)
    else:
        if use_cython and CYTHON_EVAL_AVAI:
            return eval_market1501_wrap(distmat, q_pids, g_pids, q_camids, g_camids, max_rank)
        else:
            return eval_market1501(distmat, q_pids, g_pids, q_camids, g_camids, max_rank)
def evaluate(distmat, q_pids, g_pids, q_camids, g_camids, max_rank=50, use_metric_cuhk03=False, use_cython=True):
    if use_metric_cuhk03:
        return eval_cuhk03(distmat, q_pids, g_pids, q_camids, g_camids, max_rank)
    else:
        if use_cython and CYTHON_EVAL_AVAI:
            return eval_market1501_wrap(distmat, q_pids, g_pids, q_camids, g_camids, max_rank)
        else:
            return eval_market1501(distmat, q_pids, g_pids, q_camids, g_camids, max_rank)
Exemplo n.º 4
0
def evaluate(distmat, q_pids, g_pids, q_camids, g_camids, max_rank=50, dataset_type='cuhk03', use_cython=True):
    if dataset_type == 'cuhk03':
        return eval_cuhk03(distmat, q_pids, g_pids, q_camids, g_camids, max_rank)
    elif dataset_type == 'market1501':
        if use_cython and CYTHON_EVAL_AVAI:
            return eval_market1501_wrap(distmat, q_pids, g_pids, q_camids, g_camids, max_rank)
        else:
            return eval_market1501(distmat, q_pids, g_pids, q_camids, g_camids, max_rank)
    else:
        return eval_videotag(distmat, q_pids, g_pids, q_camids, g_camids, max_rank)
Exemplo n.º 5
0
def evaluate(distmat,
             q_pids,
             g_pids,
             q_camids,
             g_camids,
             max_rank=50,
             use_metric_cuhk03=False,
             use_cython=False):
    if use_metric_cuhk03:
        return eval_cuhk03(distmat, q_pids, g_pids, q_camids, g_camids,
                           max_rank)
    else:
        if not use_cython:
            return eval_market1501(distmat, q_pids, g_pids, q_camids, g_camids,
                                   max_rank)
        else:
            return eval_market1501_wrap(distmat, q_pids, g_pids, q_camids,
                                        g_camids, max_rank)
Exemplo n.º 6
0
from eval_metrics import eval_market1501
import numpy as np
import time

num_q = 100
num_g = 1000

distmat = np.random.rand(num_q, num_g) * 20
q_pids = np.random.randint(0, num_q, size=num_q)
g_pids = np.random.randint(0, num_g, size=num_g)
q_camids = np.random.randint(0, 5, size=num_q)
g_camids = np.random.randint(0, 5, size=num_g)

end = time.time()
cmc, mAP = eval_market1501_wrap(distmat, q_pids, g_pids, q_camids, g_camids,
                                10)
elapsed_cython = time.time() - end
print("=> Cython evaluation")
print("consume time {:.5f} \n mAP is {} \n cmc is {}".format(
    elapsed_cython, mAP, cmc))

end = time.time()
cmc, mAP = eval_market1501(distmat, q_pids, g_pids, q_camids, g_camids, 10)
elapsed_python = time.time() - end
print("=> Python evaluation")
print("consume time {:.5f} \n mAP is {} \n cmc is {}".format(
    elapsed_python, mAP, cmc))

xtimes = elapsed_python / elapsed_cython
print("=> Conclusion: cython is {:.2f}x faster than python".format(xtimes))
import numpy as np
import time

num_q = 100
num_g = 1000

distmat = np.random.rand(num_q, num_g) * 20
q_pids = np.random.randint(0, num_q, size=num_q)
g_pids = np.random.randint(0, num_g, size=num_g)
q_camids = np.random.randint(0, 5, size=num_q)
g_camids = np.random.randint(0, 5, size=num_g)

end = time.time()
cmc, mAP = eval_market1501_wrap(distmat,
                                q_pids,
                                g_pids,
                                q_camids,
                                g_camids, 10)
elapsed_cython = time.time() - end
print("=> Cython evaluation")
print("consume time {:.5f} \n mAP is {} \n cmc is {}".format(elapsed_cython, mAP, cmc))

end = time.time()
cmc, mAP = eval_market1501(distmat,
                           q_pids,
                           g_pids,
                           q_camids,
                           g_camids, 10)
elapsed_python = time.time() - end
print("=> Python evaluation")
print("consume time {:.5f} \n mAP is {} \n cmc is {}".format(elapsed_python, mAP, cmc))