bascobasculino commited on
Commit
51908c1
·
1 Parent(s): b40b29b
Files changed (1) hide show
  1. my_metricv2.py +32 -22
my_metricv2.py CHANGED
@@ -35,6 +35,7 @@ This new module is designed to solve this great ML task and is crafted with a lo
35
 
36
  # TODO: Add description of the arguments of the module here
37
  _KWARGS_DESCRIPTION = """
 
38
  Calculates how good are predictions given some references, using certain scores
39
  Args:
40
  predictions: list of predictions to score. Each predictions
@@ -45,13 +46,26 @@ Returns:
45
  accuracy: description of the first score,
46
  another_score: description of the second score,
47
  Examples:
48
- Examples should be written in doctest format, and should illustrate how
49
- to use the function.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
- >>> my_new_module = evaluate.load("my_new_module")
52
- >>> results = my_new_module.compute(references=[0, 1], predictions=[0, 1])
53
- >>> print(results)
54
- {'accuracy': 1.0}
55
  """
56
 
57
  # TODO: Define external resources urls if needed
@@ -96,27 +110,23 @@ class MyMetricv2(evaluate.Metric):
96
  # TODO: Compute the different scores of the module
97
 
98
  # <frame number>, <object id>, <bb_left>, <bb_top>, <bb_width>, <bb_height>, <confidence>, <x>, <y>, <z>
99
- # predictions array de formato []
100
 
101
- # accuracy = sum(i == j for i, j in zip(predictions, references)) / len(predictions)
102
 
 
 
 
 
 
 
 
 
 
 
103
 
104
- return {
105
 
106
  "predictions": predictions,
107
  "references": references
108
 
109
  }
110
-
111
- def add(self, predictions, references):
112
- """Returns the scores"""
113
- print("add")
114
- print(predictions)
115
- print(references)
116
-
117
- return {
118
-
119
- "predictions": predictions,
120
- "references": references
121
-
122
- }
 
35
 
36
  # TODO: Add description of the arguments of the module here
37
  _KWARGS_DESCRIPTION = """
38
+
39
  Calculates how good are predictions given some references, using certain scores
40
  Args:
41
  predictions: list of predictions to score. Each predictions
 
46
  accuracy: description of the first score,
47
  another_score: description of the second score,
48
  Examples:
49
+ >>> import numpy as np
50
+ >>> mean_iou = evaluate.load("mean_iou")
51
+
52
+ >>> # suppose one has 3 different segmentation maps predicted
53
+ >>> predicted_1 = np.array([[1, 2], [3, 4], [5, 255]])
54
+ >>> actual_1 = np.array([[0, 3], [5, 4], [6, 255]])
55
+
56
+ >>> predicted_2 = np.array([[2, 7], [9, 2], [3, 6]])
57
+ >>> actual_2 = np.array([[1, 7], [9, 2], [3, 6]])
58
+
59
+ >>> predicted_3 = np.array([[2, 2, 3], [8, 2, 4], [3, 255, 2]])
60
+ >>> actual_3 = np.array([[1, 2, 2], [8, 2, 1], [3, 255, 1]])
61
+
62
+ >>> predicted = [predicted_1, predicted_2, predicted_3]
63
+ >>> ground_truth = [actual_1, actual_2, actual_3]
64
+
65
+ >>> results = mean_iou.compute(predictions=predicted, references=ground_truth, num_labels=10, ignore_index=255, reduce_labels=False)
66
+ >>> print(results) # doctest: +NORMALIZE_WHITESPACE
67
+ {'mean_iou': 0.47750000000000004, 'mean_accuracy': 0.5916666666666666, 'overall_accuracy': 0.5263157894736842, 'per_category_iou': array([0. , 0. , 0.375, 0.4 , 0.5 , 0. , 0.5 , 1. , 1. , 1. ]), 'per_category_accuracy': array([0. , 0. , 0.75 , 0.66666667, 1. , 0. , 0.5 , 1. , 1. , 1. ])}
68
 
 
 
 
 
69
  """
70
 
71
  # TODO: Define external resources urls if needed
 
110
  # TODO: Compute the different scores of the module
111
 
112
  # <frame number>, <object id>, <bb_left>, <bb_top>, <bb_width>, <bb_height>, <confidence>, <x>, <y>, <z>
 
113
 
114
+ return calculate(predictions, references)
115
 
116
+ def calculate(predictions, references):
117
+ """Returns the scores"""
118
+ try:
119
+ np_predictions = np.array(predictions)
120
+ np_references = np.array(references)
121
+ except:
122
+ raise ValueError("The predictions and references should be lists of floats in the correct format [frame number, object id, bb_left, bb_top, bb_width, bb_height, confidence]")
123
+
124
+ print(predictions)
125
+ print(references)
126
 
127
+ return {
128
 
129
  "predictions": predictions,
130
  "references": references
131
 
132
  }