Esempio n. 1
0
 def valid_calc(img_model, txt_model, dataset, bit, batch_size, drop_integer=False, return_hash=False, cuda=True):
     """
     get valid data hash code and calculate mAP
     :param img_model: the image model
     :param txt_model: the txt model
     :param dataset: the valid dataset
     :param bit: the length of hash code
     :param batch_size: the batch size of valid
     :param drop_integer: if true, the excrescent data will be drop
     :param return_hash: if true, the hash codes will be returned
     :param cuda: if use cuda
     :return: mAP and hash codes(if return_hash = True)
     """
     # get query img and txt binary code
     dataset.query()
     qB_img, qB_txt = TrainBase.get_codes(img_model, txt_model, dataset, bit, batch_size, cuda=cuda)
     query_label = dataset.get_all_label()
     # get retrieval img and txt binary code
     dataset.retrieval()
     rB_img, rB_txt = TrainBase.get_codes(img_model, txt_model, dataset, bit, batch_size, cuda=cuda)
     retrieval_label = dataset.get_all_label()
     mAPi2t = calc_map_k(qB_img, rB_txt, query_label, retrieval_label)
     mAPt2i = calc_map_k(qB_txt, rB_img, query_label, retrieval_label)
     mAPi2i = calc_map_k(qB_img, rB_img, query_label, retrieval_label)
     mApt2t = calc_map_k(qB_txt, rB_txt, query_label, retrieval_label)
     if return_hash:
         return mAPi2t, mAPt2i, mAPi2i, mApt2t, qB_img.cpu(), qB_txt.cpu(), rB_img.cpu(), rB_txt.cpu()
     return mAPi2t, mAPt2i, mAPi2i, mApt2t
Esempio n. 2
0
 def calc_map(ind):
     qB_img_ind = qB_img[:, ind]
     qB_txt_ind = qB_txt[:, ind]
     rB_img_ind = rB_img[:, ind]
     rB_txt_ind = rB_txt[:, ind]
     mAPi2t = calc_map_k(qB_img_ind, rB_txt_ind, query_label,
                         retrieval_label)
     mAPt2i = calc_map_k(qB_txt_ind, rB_img_ind, query_label,
                         retrieval_label)
     return mAPi2t, mAPt2i
Esempio n. 3
0
 def calc_map(qB_img, qB_txt, rB_img, rB_txt, query_label, retrieval_label):
     mAPi2t = calc_map_k(qB_img, rB_txt, query_label, retrieval_label)
     mAPt2i = calc_map_k(qB_txt, rB_img, query_label, retrieval_label)
     return mAPi2t, mAPt2i