HFswapnil commited on
Commit
0793f25
·
verified ·
1 Parent(s): 3e54650

Update src/localization_eval.py

Browse files
Files changed (1) hide show
  1. src/localization_eval.py +3 -25
src/localization_eval.py CHANGED
@@ -9,16 +9,6 @@ from pycocotools.coco import COCO
9
  from pycocotools.cocoeval import COCOeval
10
 
11
 
12
- import logging
13
-
14
- logging.basicConfig(level=logging.INFO) # Configure the root logger
15
-
16
- logging.basicConfig(
17
- format='%(asctime)s - %(levelname)s - %(message)s',
18
- level=logging.INFO
19
- )
20
-
21
-
22
  class Localization:
23
  """
24
  Original Localization class from EvalAI
@@ -41,11 +31,8 @@ class Localization:
41
  """
42
  print("In compute_coco_metrics")
43
  # Load ground truth and submission annotations
44
- logging.info(f"gt_annotations : {gt_annotations}\tsub_annotations : {sub_annotations}")
45
  coco_gt = COCO(gt_annotations)
46
  coco_sub = coco_gt.loadRes(sub_annotations)
47
-
48
- logging.info(f"COCO GT : {coco_gt}\tCOCO SUB : {coco_sub}")
49
 
50
  bbox_mAP = 0.0
51
  bbox_AP50 = 0.0
@@ -62,8 +49,6 @@ class Localization:
62
  # CORRECTED: stats[0] is mAP, stats[1] is AP50
63
  bbox_mAP = coco_eval_bbox.stats[0]
64
  bbox_AP50 = coco_eval_bbox.stats[1]
65
-
66
- logging.info(f"In [IF self.eval_bbox] condition : Calculated bbox_mAP : {bbox_mAP} and bbox_AP50 : {bbox_AP50}")
67
 
68
  if self.eval_segm:
69
  # Instance Segmentation Evaluation
@@ -75,8 +60,6 @@ class Localization:
75
  segm_mAP = coco_eval_mask.stats[0]
76
  segm_AP50 = coco_eval_mask.stats[1]
77
 
78
- logging.info(f"In [IF self.eval_segm] condition : Calculated bbox_mAP : {bbox_mAP} and bbox_AP50 : {bbox_AP50}")
79
-
80
  return bbox_mAP, bbox_AP50, segm_mAP, segm_AP50
81
 
82
 
@@ -97,7 +80,6 @@ def evaluate_submission(ground_truth_path, predictions_path):
97
  predictions = json.load(f)
98
 
99
  print("Loaded Predictions file")
100
- logging.info(f" [localization_eval.py] Loaded Predictions File")
101
 
102
  if not isinstance(predictions, list) or len(predictions) == 0:
103
  return None
@@ -105,26 +87,22 @@ def evaluate_submission(ground_truth_path, predictions_path):
105
  # Check required fields
106
  required_fields = ['image_id', 'category_id', 'bbox', 'score']
107
  if not all(field in predictions[0] for field in required_fields):
108
- logging.info(f"Required Fields not found")
109
  return None
110
  print(f"Required Fields Checked")
111
 
112
  # Run evaluation
113
- logging.info("Initiating Localization Instance....")
114
  evaluator = Localization(eval_bbox=True, eval_segm=False)
115
- logging.info("Evaluation Object Instantiated\nStatring COCO metrics computation")
116
  bbox_mAP, bbox_AP50, segm_mAP, segm_AP50 = evaluator.compute_coco_metrics(
117
  ground_truth_path,
118
  predictions_path
119
  )
120
- logging.info("COCO Metrics computation completed")
121
- logging.info(f"bbox_mAP, bbox_AP50, segm_mAP, segm_AP50 : {bbox_mAP, bbox_AP50, segm_mAP, segm_AP50}")
122
  print(f"bbox score calculated : {bbox_mAP}")
123
  # Convert mAP to percentage (0-100 scale)
124
  score = round(bbox_mAP * 100, 2)
125
  print("Returning Result")
126
- return score
127
 
128
  except Exception as e:
129
- logging.info(f"Evaluation error: {e}")
130
  return None
 
9
  from pycocotools.cocoeval import COCOeval
10
 
11
 
 
 
 
 
 
 
 
 
 
 
12
  class Localization:
13
  """
14
  Original Localization class from EvalAI
 
31
  """
32
  print("In compute_coco_metrics")
33
  # Load ground truth and submission annotations
 
34
  coco_gt = COCO(gt_annotations)
35
  coco_sub = coco_gt.loadRes(sub_annotations)
 
 
36
 
37
  bbox_mAP = 0.0
38
  bbox_AP50 = 0.0
 
49
  # CORRECTED: stats[0] is mAP, stats[1] is AP50
50
  bbox_mAP = coco_eval_bbox.stats[0]
51
  bbox_AP50 = coco_eval_bbox.stats[1]
 
 
52
 
53
  if self.eval_segm:
54
  # Instance Segmentation Evaluation
 
60
  segm_mAP = coco_eval_mask.stats[0]
61
  segm_AP50 = coco_eval_mask.stats[1]
62
 
 
 
63
  return bbox_mAP, bbox_AP50, segm_mAP, segm_AP50
64
 
65
 
 
80
  predictions = json.load(f)
81
 
82
  print("Loaded Predictions file")
 
83
 
84
  if not isinstance(predictions, list) or len(predictions) == 0:
85
  return None
 
87
  # Check required fields
88
  required_fields = ['image_id', 'category_id', 'bbox', 'score']
89
  if not all(field in predictions[0] for field in required_fields):
 
90
  return None
91
  print(f"Required Fields Checked")
92
 
93
  # Run evaluation
 
94
  evaluator = Localization(eval_bbox=True, eval_segm=False)
95
+ print("Evaluation Object Instantiated")
96
  bbox_mAP, bbox_AP50, segm_mAP, segm_AP50 = evaluator.compute_coco_metrics(
97
  ground_truth_path,
98
  predictions_path
99
  )
 
 
100
  print(f"bbox score calculated : {bbox_mAP}")
101
  # Convert mAP to percentage (0-100 scale)
102
  score = round(bbox_mAP * 100, 2)
103
  print("Returning Result")
104
+ return float(bbox_mAP), float(bbox_AP50), segm_mAP, segm_AP50
105
 
106
  except Exception as e:
107
+ print(f"Evaluation error: {e}")
108
  return None