Example #1
0
def predicts(predictor, start, end):
    global hit, total_hit
    lines = f[start:end]
    imgs = [line.split('\t')[0] for line in lines]
    img_features = np.array([[float(x) for x in line.split('\t')[1:]]
                             for line in lines])
    score = predictor.bulk_predict(img_features, evaluator.all_distinct_texts)

    for i, img in enumerate(imgs):
        indexes = (-score[i]).argsort()

        if FLAGS.print_predict:
            evaluator.print_img(img, i)
            evaluator.print_neareast_texts_with_indexes(score[i], indexes, 20)
            evaluator.print_neareast_texts(rerank_score[i])

        has_hit = False
        for i in range(FLAGS.topn):
            if evaluator.all_distinct_text_strs[indexes[i]] in m[img]:
                total_hit += 1
                has_hit = True
        if has_hit:
            hit += 1
    print('hits:', hit)
    print('total_hits:', total_hit)
def predicts(predictor, start, end):
    lines = f[start:end]
    imgs = [line.split('\t')[0] for line in lines]
    img_features = np.array([[float(x) for x in line.split('\t')[1:]]
                             for line in lines])
    score = bulk_predict(predictor, img_features, all_distinct_texts)
    #print(score)
    for i, img in enumerate(imgs):
        indexes = (-score[i]).argsort()

        if FLAGS.print_predict:
            #print(i, img)
            evaluator.print_img(img, i)
            evaluator.print_neareast_texts_from_sorted(score[i], indexes[:10],
                                                       img)
            #evaluator.print_neareast_texts(score[i], num=20, img = None)

        hits = img2text[img]
        labels = [indexes[j] in hits for j in xrange(num_texts)]

        rank_metrics.add(labels)