Beispiel #1
0
    def evaluate(self, im_data, im_info, gt_objects, gt_relationships, gt_regions, 
        thr=0.5, nms=False, top_Ns = [100], use_gt_boxes=False, use_gt_regions=False, only_predicate=False):
        
        if use_gt_boxes:
            gt_boxes_object = gt_objects[:, :4] * im_info[2]
        else:
            gt_boxes_object = None


        if use_gt_regions:
            gt_boxes_regions = gt_regions[:, :4] * im_info[2]
        else:
            gt_boxes_regions = None
        
        object_result, predicate_result, region_result = \
            self(im_data, im_info, gt_boxes_object, gt_regions=gt_boxes_regions, graph_generation=True)

        cls_prob_object, bbox_object, object_rois = object_result[:3]
        cls_prob_predicate, mat_phrase = predicate_result[:2]

        # interpret the model output
        obj_boxes, obj_scores, obj_inds, subject_inds, object_inds, \
            subject_boxes, object_boxes, predicate_inds = \
                self.interpret_HDN(cls_prob_object, bbox_object, object_rois, 
                            cls_prob_predicate, mat_phrase, im_info, 
                            nms=nms, top_N=max(top_Ns), use_gt_boxes=use_gt_boxes)

        gt_objects[:, :4] /= im_info[0][2]
        rel_cnt, rel_correct_cnt = check_relationship_recall(gt_objects, gt_relationships, 
                                        subject_inds, object_inds, predicate_inds, 
                                        subject_boxes, object_boxes, top_Ns, thres=thr, 
                                        only_predicate=only_predicate)

        return rel_cnt, rel_correct_cnt
Beispiel #2
0
	def evaluate(self, im_data, im_info, gt_objects, gt_relationships,
				 nms=False, nms_thresh=0.4, top_Ns = [100], use_gt_boxes=False, only_predicate=False, thresh=0.5,
				 use_rpn_scores=False):

		if use_gt_boxes:
			gt_boxes_object = gt_objects[:, :4]
		else:
			gt_boxes_object = None

		object_result, predicate_result = \
			self(im_data, im_info, gt_boxes_object, gt_relationships=None)

		cls_prob_object, bbox_object, object_rois, rpn_scores_object = object_result
		cls_prob_predicate, predicate_rois, mat_phrase = predicate_result

		# interpret the model output
		obj_boxes, obj_scores, obj_inds, subject_inds, object_inds, \
			subject_boxes, object_boxes, predicate_inds = \
			self.interpret_HDN(cls_prob_object, bbox_object, object_rois,
			                   cls_prob_predicate, mat_phrase, rpn_scores_object, im_info,
			                   nms=nms, nms_thresh=nms_thresh, top_N=max(top_Ns), use_gt_boxes=use_gt_boxes, use_rpn_scores=use_rpn_scores)


		gt_objects[:, :4] /= im_info[0][2]
		rel_cnt, rel_correct_cnt = check_relationship_recall(gt_objects, gt_relationships,
										subject_inds, object_inds, predicate_inds,
										subject_boxes, object_boxes, top_Ns, thresh=thresh,
										only_predicate=only_predicate)

		# calculate map
		classes_scores, classes_tf, classes_gt_num =\
		self.map_eval(cls_prob_object, bbox_object, object_rois, gt_objects, im_info, nms=False)

		return rel_cnt, rel_correct_cnt, object_rois, classes_scores, classes_tf, classes_gt_num
Beispiel #3
0
    def evaluate(self,
                 im_data,
                 im_info,
                 gt_objects,
                 gt_relationships,
                 gt_regions,
                 thr=0.5,
                 nms=False,
                 top_Ns=[100],
                 use_gt_boxes=False,
                 use_gt_regions=False,
                 only_predicate=False):

        if use_gt_boxes:
            gt_boxes_object = gt_objects[:, :4] * im_info[2]
        else:
            gt_boxes_object = None

        if use_gt_regions:
            gt_boxes_regions = gt_regions[:, :4] * im_info[2]
        else:
            gt_boxes_regions = None

        object_result, predicate_result, region_result, features_result = \
            self(im_data, im_info, gt_boxes_object, gt_regions=gt_boxes_regions, graph_generation=True)  #forward

        cls_prob_object, bbox_object, object_rois = object_result[:3]
        cls_prob_predicate, mat_phrase = predicate_result[:2]
        obj_fea, rel_fea = features_result[:2]
        #64个object
        # pdb.set_trace()
        # interpret the model output
        obj_boxes, obj_scores, obj_inds, subject_inds, object_inds, \
            subject_boxes, object_boxes, predicate_inds, keep, keepSub, keepObj, keepPre = \
                self.interpret_HDN(cls_prob_object, bbox_object, object_rois,
                            cls_prob_predicate, mat_phrase, im_info,
                            nms=nms, top_N=max(top_Ns), use_gt_boxes=use_gt_boxes)

        subFea = obj_fea[keep][keepSub]
        objFea = obj_fea[keep][keepObj]
        preFea = rel_fea[keepPre]
        #50个主语和宾语节点
        # pdb.set_trace()
        gt_objects[:, :4] /= im_info[0][2]
        rel_cnt, rel_correct_cnt, cnt_record = check_relationship_recall(
            gt_objects,
            gt_relationships,
            subject_inds,
            object_inds,
            predicate_inds,
            subject_boxes,
            object_boxes,
            top_Ns,
            thres=thr,
            only_predicate=only_predicate)
        # if cnt_record[0].shape[0]>0:
        #     subFea = subFea[cnt_record[0]]
        #     objFea = objFea[cnt_record[0]]
        #     preFea = preFea[cnt_record[0]]
        #     subject_inds_cnt = subject_inds[cnt_record[0]]
        #     object_inds_cnt = object_inds[cnt_record[0]]
        #     predicate_inds_cnt = predicate_inds[cnt_record[0]]
        # else:
        #     subject_inds_cnt = subject_inds
        #     object_inds_cnt = object_inds
        #     predicate_inds_cnt = predicate_inds
        # pdb.set_trace()
        return rel_cnt, rel_correct_cnt, \
        (subFea, objFea, preFea, subject_inds, object_inds, predicate_inds, subject_boxes, object_boxes, im_info, gt_objects, gt_relationships)