Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

test_depth_estimation_metrics.py 3.7 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
  1. import torch
  2. import unittest
  3. from super_gradients.training.metrics import Delta1, Delta2, Delta3, DepthMAE, DepthMAPE, DepthMSE, DepthRMSE, DepthMSLE
  4. class TestDepthEstimationMetrics(unittest.TestCase):
  5. def test_delta_metrics(self):
  6. # Specific example data
  7. pred_depth = torch.tensor([[[[1.0, 2.0], [3.0, 4.0]]]], dtype=torch.float32)
  8. gt_depth = torch.tensor([[[1.5, 2.5], [3.5, 4.5]]], dtype=torch.float32)
  9. # Create instances of delta metrics
  10. delta1_metric = Delta1()
  11. delta2_metric = Delta2()
  12. delta3_metric = Delta3()
  13. # Update metrics with specific example data
  14. delta1_metric.update(pred_depth, gt_depth)
  15. delta2_metric.update(pred_depth, gt_depth)
  16. delta3_metric.update(pred_depth, gt_depth)
  17. # Compute and assert the delta metrics
  18. self.assertAlmostEqual(delta1_metric.compute().item(), 0.5)
  19. self.assertAlmostEqual(delta2_metric.compute().item(), 1.0)
  20. self.assertAlmostEqual(delta3_metric.compute().item(), 1.0)
  21. def test_mae_metric(self):
  22. # Specific example data
  23. pred_depth = torch.tensor([[[[1.0, 2.0], [3.0, 4.0]]]], dtype=torch.float32)
  24. gt_depth = torch.tensor([[[[1.5, 2.5], [3.5, 4.5]]]], dtype=torch.float32)
  25. # Create instances of MAE and MAPE metrics
  26. mae_metric = DepthMAE(ignore_val=-1)
  27. # Update metrics with specific example data
  28. mae_metric.update(pred_depth, gt_depth)
  29. # Compute and assert the MAE metric
  30. self.assertAlmostEqual(mae_metric.compute().item(), 0.5, places=5)
  31. def test_mape_metric(self):
  32. # Specific example data
  33. pred_depth = torch.tensor([[[[1.0, 2.0], [3.0, 4.0]]]], dtype=torch.float32)
  34. gt_depth = torch.tensor([[[[1.5, 2.5], [3.5, 4.5]]]], dtype=torch.float32)
  35. # Create an instance of MAPE metric
  36. mape_metric = DepthMAPE()
  37. # Update metric with specific example data
  38. mape_metric.update(pred_depth, gt_depth)
  39. # Compute and assert the MAPE metric
  40. self.assertAlmostEqual(mape_metric.compute().item(), (0.5 / 1.5 + 0.5 / 2.5 + 0.5 / 3.5 + 0.5 / 4.5) / 4)
  41. def test_mse_metric(self):
  42. # Specific example data
  43. pred_depth = torch.tensor([[[[1.0, 2.0], [3.0, 4.0]]]], dtype=torch.float32)
  44. gt_depth = torch.tensor([[[[1.5, 2.5], [3.5, 4.5]]]], dtype=torch.float32)
  45. # Create an instance of MSE metric
  46. mse_metric = DepthMSE()
  47. # Update metric with specific example data
  48. mse_metric.update(pred_depth, gt_depth)
  49. # Compute and assert the MSE metric
  50. self.assertAlmostEqual(mse_metric.compute().item(), 0.25)
  51. def test_rmse_metric(self):
  52. # Specific example data
  53. pred_depth = torch.tensor([[[[1.0, 2.0], [3.0, 4.0]]]], dtype=torch.float32)
  54. gt_depth = torch.tensor([[[[1.5, 2.5], [3.5, 4.5]]]], dtype=torch.float32)
  55. # Create an instance of RMSE metric
  56. rmse_metric = DepthRMSE()
  57. # Update metric with specific example data
  58. rmse_metric.update(pred_depth, gt_depth)
  59. # Compute and assert the RMSE metric
  60. self.assertAlmostEqual(rmse_metric.compute().item(), 0.5)
  61. def test_msle_metric(self):
  62. # Specific example data
  63. pred_depth = torch.tensor([[[[1.0, 2.0], [3.0, 4.0]]]], dtype=torch.float32)
  64. gt_depth = torch.tensor([[[[1.5, 2.5], [3.5, 4.5]]]], dtype=torch.float32)
  65. # Create an instance of MSLE metric
  66. msle_metric = DepthMSLE()
  67. # Update metric with specific example data
  68. msle_metric.update(pred_depth, gt_depth)
  69. # Compute and assert the MSLE metric
  70. self.assertAlmostEqual(msle_metric.compute().item(), 0.024128085002303123)
  71. if __name__ == "__main__":
  72. unittest.main()
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...