franzi2505 commited on
Commit
098fa32
·
1 Parent(s): c41036a

make wandb functionality also usable for class specific setting

Browse files
Files changed (1) hide show
  1. det-metrics.py +21 -8
det-metrics.py CHANGED
@@ -29,10 +29,10 @@ LABEL_MAPPING = {
29
  'FISHING_SHIP': 0,
30
  'CONTAINER_SHIP': 0,
31
  'CRUISE_SHIP': 0,
 
32
  'BOAT_WITHOUT_SAILS': 1,
33
  'MOTORBOAT': 1,
34
  'MARITIME_VEHICLE': 1,
35
- 'BOAT': 1,
36
  'SAILING_BOAT': 2,
37
  'SAILING_BOAT_WITH_CLOSED_SAILS': 2,
38
  'SAILING_BOAT_WITH_OPEN_SAILS': 2,
@@ -288,7 +288,6 @@ class DetectionMetric(evaluate.Metric):
288
  # add payload if available (otherwise predictions and references must be added with add function)
289
  if self.payload:
290
  self._add_payload(self.payload, model_name)
291
-
292
  results[model_name] = self.coco_metric.compute()
293
 
294
  # reset coco_metrics for next model
@@ -299,6 +298,7 @@ class DetectionMetric(evaluate.Metric):
299
  class_agnostic=self.class_agnostic,
300
  iou_type=self.iou_type,
301
  box_format=self.bbox_format,
 
302
  )
303
  return results
304
 
@@ -428,11 +428,6 @@ class DetectionMetric(evaluate.Metric):
428
  wandb: To interact with the Weights and Biases platform.
429
  datetime: To generate a timestamp for run names.
430
  """
431
- if not self.class_agnostic:
432
- raise ValueError(
433
- "This method is not yet implemented for `self.class_agnostic=False`."
434
- )
435
-
436
  import os
437
  import wandb
438
  import datetime
@@ -449,7 +444,25 @@ class DetectionMetric(evaluate.Metric):
449
  run = wandb.init(project=wandb_project, name=f"{k}-{formatted_datetime}")
450
  else:
451
  run = wandb_runs[i]
452
- run.log({f"{wandb_section}/{m}" : v for m, v in results[k]['metrics'].items()} if wandb_section is not None else results[k]['metrics'])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
453
  if wandb_runs is None:
454
  run.finish()
455
 
 
29
  'FISHING_SHIP': 0,
30
  'CONTAINER_SHIP': 0,
31
  'CRUISE_SHIP': 0,
32
+ 'BOAT': 1,
33
  'BOAT_WITHOUT_SAILS': 1,
34
  'MOTORBOAT': 1,
35
  'MARITIME_VEHICLE': 1,
 
36
  'SAILING_BOAT': 2,
37
  'SAILING_BOAT_WITH_CLOSED_SAILS': 2,
38
  'SAILING_BOAT_WITH_OPEN_SAILS': 2,
 
288
  # add payload if available (otherwise predictions and references must be added with add function)
289
  if self.payload:
290
  self._add_payload(self.payload, model_name)
 
291
  results[model_name] = self.coco_metric.compute()
292
 
293
  # reset coco_metrics for next model
 
298
  class_agnostic=self.class_agnostic,
299
  iou_type=self.iou_type,
300
  box_format=self.bbox_format,
301
+ labels=sorted(list(set(list(self.label_mapping.values())))) if self.label_mapping else None
302
  )
303
  return results
304
 
 
428
  wandb: To interact with the Weights and Biases platform.
429
  datetime: To generate a timestamp for run names.
430
  """
 
 
 
 
 
431
  import os
432
  import wandb
433
  import datetime
 
444
  run = wandb.init(project=wandb_project, name=f"{k}-{formatted_datetime}")
445
  else:
446
  run = wandb_runs[i]
447
+ if self.class_agnostic:
448
+ run.log({f"{wandb_section}/{m}" : v for m, v in results[k]['metrics'].items()} if wandb_section is not None else results[k]['metrics'])
449
+ else:
450
+ for area_range, area_v in results[k]['metrics'].items():
451
+ for m, v in area_v.items():
452
+ if m in ["precision", "recall", "f1", "duplicates", "support"]:
453
+ for cls_idx in list(set(list(self.label_mapping.values()))):
454
+ cls_name = list(self.label_mapping.keys())[list(self.label_mapping.values()).index(cls_idx)]
455
+ run.log(
456
+ {
457
+ (f"{(wandb_section + '/') if wandb_section else ''}{cls_name}/{area_range + '.' + m}") : v[cls_idx]
458
+ }
459
+ )
460
+ else:
461
+ run.log(
462
+ {
463
+ f"{(wandb_section + '/') if wandb_section is not None else ''}{m}" : v
464
+ }
465
+ )
466
  if wandb_runs is None:
467
  run.finish()
468