Adam Kunรกk
commited on
๐ [Fix] validation_step (#134)
Browse files* ๐ [Fix] validation_step
Changed the self.metric() call to self.metric.update().
Removed the logging of per batch metric values.
Filtered out the dummy boxes from the per image "target" tensors before appending them to the metrics accumulator.
fixes #133
* ๐ [Fix] target filtering
Changed dummy target filtering to be based on class IDs being -1 and moved it inside the to_metrics_format function.
- yolo/tools/solver.py +2 -11
- yolo/utils/bounding_box_utils.py +1 -0
yolo/tools/solver.py
CHANGED
@@ -48,17 +48,8 @@ class ValidateModel(BaseModel):
|
|
48 |
batch_size, images, targets, rev_tensor, img_paths = batch
|
49 |
H, W = images.shape[2:]
|
50 |
predicts = self.post_process(self.ema(images), image_size=[W, H])
|
51 |
-
|
52 |
-
|
53 |
-
)
|
54 |
-
|
55 |
-
self.log_dict(
|
56 |
-
{
|
57 |
-
"map": batch_metrics["map"],
|
58 |
-
"map_50": batch_metrics["map_50"],
|
59 |
-
},
|
60 |
-
batch_size=batch_size,
|
61 |
-
)
|
62 |
return predicts
|
63 |
|
64 |
def on_validation_epoch_end(self):
|
|
|
48 |
batch_size, images, targets, rev_tensor, img_paths = batch
|
49 |
H, W = images.shape[2:]
|
50 |
predicts = self.post_process(self.ema(images), image_size=[W, H])
|
51 |
+
self.metric.update([to_metrics_format(predict) for predict in predicts],
|
52 |
+
[to_metrics_format(target) for target in targets])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
return predicts
|
54 |
|
55 |
def on_validation_epoch_end(self):
|
yolo/utils/bounding_box_utils.py
CHANGED
@@ -484,6 +484,7 @@ def calculate_map(predictions, ground_truths) -> Dict[str, Tensor]:
|
|
484 |
|
485 |
|
486 |
def to_metrics_format(prediction: Tensor) -> Dict[str, Union[float, Tensor]]:
|
|
|
487 |
bbox = {"boxes": prediction[:, 1:5], "labels": prediction[:, 0].int()}
|
488 |
if prediction.size(1) == 6:
|
489 |
bbox["scores"] = prediction[:, 5]
|
|
|
484 |
|
485 |
|
486 |
def to_metrics_format(prediction: Tensor) -> Dict[str, Union[float, Tensor]]:
|
487 |
+
prediction = prediction[prediction[:, 0] != -1]
|
488 |
bbox = {"boxes": prediction[:, 1:5], "labels": prediction[:, 0].int()}
|
489 |
if prediction.size(1) == 6:
|
490 |
bbox["scores"] = prediction[:, 5]
|