コード例 #1
0
def debug_recall(debug_dir, i, qvec, cvec, img, rois, num_rois=100):
    # debug
    if not os.path.exists(debug_dir):
        os.makedirs(debug_dir)
    qdic_dir = osp.join(cfg.DATA_DIR, cfg.IMDB_NAME, 'query_dict')

    qdic = Dictionary(qdic_dir)
    qdic.load()
    cont = np.transpose(cvec)[0]
    query = np.transpose(qvec)[0]
    q_str = []
    for idx in query:
        if int(idx) != 0:
            q_str.append(qdic.get_token(idx))
    q_str = ' '.join(q_str)
    # if right_flag:
    #     save_dir = 'debug/%s/right/'%str(iid)+str(i)
    # else:
    #     save_dir = 'debug/%s/wrong/'%str(iid)+str(i)
    save_dir = os.path.join(debug_dir, '%s' % str(i))
    if not os.path.exists(save_dir):
        os.makedirs(save_dir)
    # json.dump(list(cont.astype(np.int)), open(save_dir+'/%s'%q_str, 'w'))
    # json.dump(list(query.astype(np.int)), open(save_dir+'/query.json', 'w'))
    with open(save_dir + '/query.txt', 'w') as f:
        f.write(q_str)
    pred = img.copy()
    rois = rois[:num_rois]
    for box in rois:
        cv2.rectangle(pred, (box[0], box[1]), (box[2], box[3]), (0, 255, 0))
    cv2.imwrite(save_dir + '/rois.jpg', pred)
コード例 #2
0
def debug_pred(debug_dir, count, qvec, cvec, img, gt_bbox, roi, bbox_pred, iou):
    # debug
    if not os.path.exists(debug_dir):
        os.makedirs(debug_dir)
    qdic_dir = osp.join(cfg.DATA_DIR, cfg.IMDB_NAME, 'query_dict')

    qdic = Dictionary(qdic_dir)
    qdic.load()
    q_str = []
    for idx in qvec:
        if int(idx) != 0:
            q_str.append(qdic.get_token(idx))
    q_str = ' '.join(q_str)
    if iou >= 0.5:
        save_dir = os.path.join(debug_dir, 'right/' + str(count))
    else:
        save_dir = os.path.join(debug_dir, 'wrong/' + str(count))
    if not os.path.exists(save_dir):
        os.makedirs(save_dir)
    with open(save_dir + '/%.3f' % iou, 'w') as f:
        f.write(' ')
    # json.dump(list(cont.astype(np.int)), open(save_dir+'/%s'%q_str, 'w'))
    # json.dump(list(query.astype(np.int)), open(save_dir+'/query.json', 'w'))
    with open(save_dir + '/query.txt', 'w') as f:
        f.write(q_str)
    pred = img.copy()
    box = gt_bbox.astype(np.int)
    cv2.rectangle(pred, (box[0], box[1]), (box[2], box[3]), (0, 255, 0), 2)
    box = roi.astype(np.int)
    cv2.rectangle(pred, (box[0], box[1]), (box[2], box[3]), (0, 255, 255), 2)
    box = bbox_pred.astype(np.int)
    cv2.rectangle(pred, (box[0], box[1]), (box[2], box[3]), (0, 0, 255), 2)
    cv2.imwrite(save_dir + '/pred.jpg', pred)