valor-lite 0.33.16__tar.gz → 0.33.18__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of valor-lite might be problematic. Click here for more details.

Files changed (124) hide show
  1. {valor_lite-0.33.16 → valor_lite-0.33.18}/PKG-INFO +1 -1
  2. valor_lite-0.33.18/benchmarks/synthetic/benchmark_semantic_segmentation.py +94 -0
  3. valor_lite-0.33.18/examples/benchmarking.ipynb +279 -0
  4. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/object_detection/test_dataloader.py +55 -4
  5. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/semantic_segmentation/test_annotation.py +57 -1
  6. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/semantic_segmentation/test_confusion_matrix.py +62 -0
  7. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite/object_detection/annotation.py +0 -24
  8. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite/object_detection/manager.py +77 -82
  9. valor_lite-0.33.18/valor_lite/profiling.py +374 -0
  10. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite/semantic_segmentation/__init__.py +2 -1
  11. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite/semantic_segmentation/annotation.py +84 -1
  12. valor_lite-0.33.18/valor_lite/semantic_segmentation/benchmark.py +151 -0
  13. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite/semantic_segmentation/computation.py +13 -26
  14. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite/semantic_segmentation/manager.py +6 -2
  15. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite.egg-info/PKG-INFO +1 -1
  16. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite.egg-info/SOURCES.txt +4 -0
  17. {valor_lite-0.33.16 → valor_lite-0.33.18}/LICENSE +0 -0
  18. {valor_lite-0.33.16 → valor_lite-0.33.18}/README.md +0 -0
  19. {valor_lite-0.33.16 → valor_lite-0.33.18}/benchmarks/.gitignore +0 -0
  20. {valor_lite-0.33.16 → valor_lite-0.33.18}/benchmarks/benchmark_classification.py +0 -0
  21. {valor_lite-0.33.16 → valor_lite-0.33.18}/benchmarks/benchmark_objdet.py +0 -0
  22. {valor_lite-0.33.16 → valor_lite-0.33.18}/examples/.gitignore +0 -0
  23. {valor_lite-0.33.16 → valor_lite-0.33.18}/examples/object-detection.ipynb +0 -0
  24. {valor_lite-0.33.16 → valor_lite-0.33.18}/examples/tabular_classification.ipynb +0 -0
  25. {valor_lite-0.33.16 → valor_lite-0.33.18}/examples/text_generation.ipynb +0 -0
  26. {valor_lite-0.33.16 → valor_lite-0.33.18}/pyproject.toml +0 -0
  27. {valor_lite-0.33.16 → valor_lite-0.33.18}/setup.cfg +0 -0
  28. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/__init__.py +0 -0
  29. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/classification/__init__.py +0 -0
  30. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/classification/conftest.py +0 -0
  31. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/classification/test_accuracy.py +0 -0
  32. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/classification/test_confusion_matrix.py +0 -0
  33. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/classification/test_counts.py +0 -0
  34. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/classification/test_dataloader.py +0 -0
  35. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/classification/test_evaluator.py +0 -0
  36. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/classification/test_f1.py +0 -0
  37. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/classification/test_filtering.py +0 -0
  38. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/classification/test_metric.py +0 -0
  39. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/classification/test_precision.py +0 -0
  40. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/classification/test_recall.py +0 -0
  41. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/classification/test_rocauc.py +0 -0
  42. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/classification/test_schemas.py +0 -0
  43. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/classification/test_stability.py +0 -0
  44. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/object_detection/__init__.py +0 -0
  45. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/object_detection/conftest.py +0 -0
  46. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/object_detection/test_accuracy.py +0 -0
  47. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/object_detection/test_average_precision.py +0 -0
  48. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/object_detection/test_average_recall.py +0 -0
  49. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/object_detection/test_confusion_matrix.py +0 -0
  50. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/object_detection/test_counts.py +0 -0
  51. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/object_detection/test_evaluator.py +0 -0
  52. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/object_detection/test_f1.py +0 -0
  53. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/object_detection/test_filtering.py +0 -0
  54. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/object_detection/test_iou.py +0 -0
  55. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/object_detection/test_metric.py +0 -0
  56. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/object_detection/test_pr_curve.py +0 -0
  57. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/object_detection/test_precision.py +0 -0
  58. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/object_detection/test_recall.py +0 -0
  59. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/object_detection/test_schemas.py +0 -0
  60. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/object_detection/test_stability.py +0 -0
  61. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/semantic_segmentation/__init__.py +0 -0
  62. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/semantic_segmentation/conftest.py +0 -0
  63. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/semantic_segmentation/test_accuracy.py +0 -0
  64. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/semantic_segmentation/test_dataloader.py +0 -0
  65. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/semantic_segmentation/test_evaluator.py +0 -0
  66. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/semantic_segmentation/test_f1.py +0 -0
  67. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/semantic_segmentation/test_filtering.py +0 -0
  68. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/semantic_segmentation/test_iou.py +0 -0
  69. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/semantic_segmentation/test_metric.py +0 -0
  70. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/semantic_segmentation/test_precision.py +0 -0
  71. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/semantic_segmentation/test_recall.py +0 -0
  72. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/semantic_segmentation/test_stability.py +0 -0
  73. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/text_generation/__init__.py +0 -0
  74. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/text_generation/conftest.py +0 -0
  75. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/text_generation/llm/__init__.py +0 -0
  76. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/text_generation/llm/test_generation.py +0 -0
  77. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/text_generation/llm/test_integrations.py +0 -0
  78. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/text_generation/llm/test_utilities.py +0 -0
  79. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/text_generation/llm/test_validators.py +0 -0
  80. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/text_generation/metrics/test_answer_correctness.py +0 -0
  81. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/text_generation/metrics/test_answer_relevance.py +0 -0
  82. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/text_generation/metrics/test_bias.py +0 -0
  83. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/text_generation/metrics/test_context_precision.py +0 -0
  84. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/text_generation/metrics/test_context_recall.py +0 -0
  85. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/text_generation/metrics/test_context_relevance.py +0 -0
  86. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/text_generation/metrics/test_faithfulness.py +0 -0
  87. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/text_generation/metrics/test_hallucination.py +0 -0
  88. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/text_generation/metrics/test_metric.py +0 -0
  89. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/text_generation/metrics/test_rouge.py +0 -0
  90. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/text_generation/metrics/test_sentence_bleu.py +0 -0
  91. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/text_generation/metrics/test_summary_coherence.py +0 -0
  92. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/text_generation/metrics/test_toxicity.py +0 -0
  93. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/text_generation/test_evaluator.py +0 -0
  94. {valor_lite-0.33.16 → valor_lite-0.33.18}/tests/text_generation/test_manager.py +0 -0
  95. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite/LICENSE +0 -0
  96. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite/__init__.py +0 -0
  97. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite/classification/__init__.py +0 -0
  98. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite/classification/annotation.py +0 -0
  99. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite/classification/computation.py +0 -0
  100. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite/classification/manager.py +0 -0
  101. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite/classification/metric.py +0 -0
  102. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite/classification/utilities.py +0 -0
  103. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite/object_detection/__init__.py +0 -0
  104. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite/object_detection/computation.py +0 -0
  105. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite/object_detection/metric.py +0 -0
  106. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite/object_detection/utilities.py +0 -0
  107. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite/schemas.py +0 -0
  108. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite/semantic_segmentation/metric.py +0 -0
  109. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite/semantic_segmentation/utilities.py +0 -0
  110. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite/text_generation/__init__.py +0 -0
  111. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite/text_generation/annotation.py +0 -0
  112. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite/text_generation/computation.py +0 -0
  113. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite/text_generation/llm/__init__.py +0 -0
  114. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite/text_generation/llm/exceptions.py +0 -0
  115. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite/text_generation/llm/generation.py +0 -0
  116. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite/text_generation/llm/instructions.py +0 -0
  117. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite/text_generation/llm/integrations.py +0 -0
  118. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite/text_generation/llm/utilities.py +0 -0
  119. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite/text_generation/llm/validators.py +0 -0
  120. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite/text_generation/manager.py +0 -0
  121. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite/text_generation/metric.py +0 -0
  122. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite.egg-info/dependency_links.txt +0 -0
  123. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite.egg-info/requires.txt +0 -0
  124. {valor_lite-0.33.16 → valor_lite-0.33.18}/valor_lite.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: valor-lite
3
- Version: 0.33.16
3
+ Version: 0.33.18
4
4
  Summary: Compute valor metrics locally.
5
5
  License: MIT License
6
6
 
@@ -0,0 +1,94 @@
1
+ from valor_lite.profiling import Benchmark, BenchmarkError
2
+ from valor_lite.semantic_segmentation.benchmark import (
3
+ benchmark_add_data,
4
+ benchmark_evaluate,
5
+ benchmark_finalize,
6
+ )
7
+
8
+
9
+ def benchmark(
10
+ bitmask_shape: tuple[int, int],
11
+ number_of_unique_labels: int,
12
+ number_of_images: int,
13
+ *_,
14
+ memory_limit: float = 4.0,
15
+ time_limit: float = 10.0,
16
+ repeat: int = 1,
17
+ verbose: bool = False,
18
+ ):
19
+ """
20
+ Runs a single benchmark.
21
+
22
+ Parameters
23
+ ----------
24
+ bitmask_shape : tuple[int, int]
25
+ The size (h, w) of the bitmask array.
26
+ number_of_unique_labels : int
27
+ The number of unique labels used in the synthetic example.
28
+ number_of_images : int
29
+ The number of distinct datums that are created.
30
+ memory_limit : float
31
+ The maximum amount of system memory allowed in gigabytes (GB).
32
+ time_limit : float
33
+ The maximum amount of time permitted before killing the benchmark.
34
+ repeat : int
35
+ The number of times to run a benchmark to produce an average runtime.
36
+ verbose : bool, default=False
37
+ Toggles terminal output of benchmark results.
38
+ """
39
+
40
+ b = Benchmark(
41
+ time_limit=time_limit,
42
+ memory_limit=int(memory_limit * (1024**3)),
43
+ repeat=repeat,
44
+ verbose=verbose,
45
+ )
46
+
47
+ _, failed, details = b.run(
48
+ benchmark=benchmark_add_data,
49
+ n_labels=[number_of_unique_labels],
50
+ shape=[bitmask_shape],
51
+ )
52
+ if failed:
53
+ raise BenchmarkError(
54
+ benchmark=details["benchmark"],
55
+ error_type=failed[0]["error"],
56
+ error_message=failed[0]["msg"],
57
+ )
58
+
59
+ _, failed, details = b.run(
60
+ benchmark=benchmark_finalize,
61
+ n_datums=[number_of_images],
62
+ n_labels=[number_of_unique_labels],
63
+ )
64
+ if failed:
65
+ raise BenchmarkError(
66
+ benchmark=details["benchmark"],
67
+ error_type=failed[0]["error"],
68
+ error_message=failed[0]["msg"],
69
+ )
70
+
71
+ _, failed, details = b.run(
72
+ benchmark=benchmark_evaluate,
73
+ n_datums=[number_of_images],
74
+ n_labels=[number_of_unique_labels],
75
+ )
76
+ if failed:
77
+ raise BenchmarkError(
78
+ benchmark=details["benchmark"],
79
+ error_type=failed[0]["error"],
80
+ error_message=failed[0]["msg"],
81
+ )
82
+
83
+
84
+ if __name__ == "__main__":
85
+
86
+ benchmark(
87
+ bitmask_shape=(4000, 4000),
88
+ number_of_images=1000,
89
+ number_of_unique_labels=10,
90
+ memory_limit=4.0,
91
+ time_limit=10.0,
92
+ repeat=1,
93
+ verbose=True,
94
+ )
@@ -0,0 +1,279 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "from valor_lite.profiling import Benchmark\n",
10
+ "\n",
11
+ "b = Benchmark(\n",
12
+ " time_limit=5.0, # 5s\n",
13
+ " memory_limit=8 * (1024 ** 3), # 8 GB\n",
14
+ " repeat=1,\n",
15
+ " verbose=True,\n",
16
+ ")"
17
+ ]
18
+ },
19
+ {
20
+ "attachments": {},
21
+ "cell_type": "markdown",
22
+ "metadata": {},
23
+ "source": [
24
+ "# Semantic Segmentation"
25
+ ]
26
+ },
27
+ {
28
+ "cell_type": "code",
29
+ "execution_count": 2,
30
+ "metadata": {},
31
+ "outputs": [],
32
+ "source": [
33
+ "from valor_lite.semantic_segmentation.benchmark import (\n",
34
+ " benchmark_add_data as semseg_add_data,\n",
35
+ " benchmark_finalize as semseg_finalize,\n",
36
+ " benchmark_evaluate as semseg_evaluate,\n",
37
+ ")"
38
+ ]
39
+ },
40
+ {
41
+ "cell_type": "code",
42
+ "execution_count": 3,
43
+ "metadata": {},
44
+ "outputs": [],
45
+ "source": [
46
+ "n_datums = [\n",
47
+ " 10000,\n",
48
+ " 1000,\n",
49
+ " 100,\n",
50
+ " 10,\n",
51
+ " 1,\n",
52
+ "]\n",
53
+ "\n",
54
+ "n_labels = [\n",
55
+ " 1000,\n",
56
+ " 100,\n",
57
+ " 10,\n",
58
+ " 3,\n",
59
+ "]\n",
60
+ "\n",
61
+ "shapes = [\n",
62
+ " (10000, 10000),\n",
63
+ " (2500, 2500),\n",
64
+ " (1000, 1000),\n",
65
+ " (100, 100),\n",
66
+ "]"
67
+ ]
68
+ },
69
+ {
70
+ "cell_type": "code",
71
+ "execution_count": 4,
72
+ "metadata": {},
73
+ "outputs": [
74
+ {
75
+ "name": "stderr",
76
+ "output_type": "stream",
77
+ "text": [
78
+ " 69%|██████▉ | 11/16 [00:46<00:21, 4.26s/it]"
79
+ ]
80
+ },
81
+ {
82
+ "name": "stdout",
83
+ "output_type": "stream",
84
+ "text": [
85
+ "=====================================================================\n",
86
+ "Details\n",
87
+ "{\n",
88
+ " \"benchmark\": \"benchmark_add_data\",\n",
89
+ " \"limits\": {\n",
90
+ " \"memory_limit\": \"8.0 GB\",\n",
91
+ " \"time_limit\": \"5.0 seconds\",\n",
92
+ " \"repeat\": 1\n",
93
+ " },\n",
94
+ " \"passed\": 8,\n",
95
+ " \"failed\": 8,\n",
96
+ " \"total\": 16\n",
97
+ "}\n",
98
+ "\n",
99
+ "Passed\n",
100
+ " complexity | runtime | n_labels | shape \n",
101
+ "---------------------------------------------------------------------\n",
102
+ " 300000000 | 1.5151 | 3 | (10000, 10000) \n",
103
+ " 62500000 | 0.5952 | 10 | (2500, 2500) \n",
104
+ " 10000000 | 0.0911 | 10 | (1000, 1000) \n",
105
+ " 1000000 | 0.0582 | 100 | (100, 100) \n",
106
+ "\n",
107
+ "Failed\n",
108
+ " complexity | error | n_labels | shape | msg \n",
109
+ "---------------------------------------------------------------------------------------\n",
110
+ " 100000000000 | MemoryError | 1000 | (10000, 10000) | Unable to allocate 186. GiB for an array with shape (1001, 20000, 10000) and data type bool\n",
111
+ " 10000000000 | MemoryError | 100 | (10000, 10000) | Unable to allocate 18.8 GiB for an array with shape (101, 20000, 10000) and data type bool\n",
112
+ " 6250000000 | MemoryError | 1000 | (2500, 2500) | Unable to allocate 11.7 GiB for an array with shape (1001, 5000, 2500) and data type bool\n",
113
+ " 1000000000 | MemoryError | 10 | (10000, 10000) | Unable to allocate 9.31 GiB for an array with shape (10, 10, 100000000) and data type bool\n",
114
+ " 1000000000 | MemoryError | 1000 | (1000, 1000) | Unable to allocate 931. GiB for an array with shape (1000, 1000, 1000000) and data type bool\n",
115
+ " 625000000 | MemoryError | 100 | (2500, 2500) | Unable to allocate 58.2 GiB for an array with shape (100, 100, 6250000) and data type bool\n",
116
+ " 100000000 | MemoryError | 100 | (1000, 1000) | Unable to allocate 9.31 GiB for an array with shape (100, 100, 1000000) and data type bool\n",
117
+ " 10000000 | MemoryError | 1000 | (100, 100) | Unable to allocate 9.31 GiB for an array with shape (1000, 1000, 10000) and data type bool\n"
118
+ ]
119
+ },
120
+ {
121
+ "name": "stderr",
122
+ "output_type": "stream",
123
+ "text": [
124
+ "\n"
125
+ ]
126
+ }
127
+ ],
128
+ "source": [
129
+ "_ = b.run(\n",
130
+ " benchmark=semseg_add_data,\n",
131
+ " n_labels=n_labels,\n",
132
+ " shape=shapes,\n",
133
+ ")"
134
+ ]
135
+ },
136
+ {
137
+ "cell_type": "code",
138
+ "execution_count": 5,
139
+ "metadata": {},
140
+ "outputs": [
141
+ {
142
+ "name": "stderr",
143
+ "output_type": "stream",
144
+ "text": [
145
+ " 20%|██ | 4/20 [02:35<10:22, 38.92s/it]"
146
+ ]
147
+ },
148
+ {
149
+ "name": "stdout",
150
+ "output_type": "stream",
151
+ "text": [
152
+ "=====================================================================\n",
153
+ "Details\n",
154
+ "{\n",
155
+ " \"benchmark\": \"benchmark_finalize\",\n",
156
+ " \"limits\": {\n",
157
+ " \"memory_limit\": \"8.0 GB\",\n",
158
+ " \"time_limit\": \"5.0 seconds\",\n",
159
+ " \"repeat\": 1\n",
160
+ " },\n",
161
+ " \"passed\": 18,\n",
162
+ " \"failed\": 2,\n",
163
+ " \"total\": 20\n",
164
+ "}\n",
165
+ "\n",
166
+ "Passed\n",
167
+ " complexity | runtime | n_datums | n_labels \n",
168
+ "---------------------------------------------------------------------\n",
169
+ " 1000000 | 1.1142 | 10000 | 100 \n",
170
+ " 100000 | 0.1748 | 100 | 1000 \n",
171
+ " 100000 | 0.1086 | 1000 | 100 \n",
172
+ "\n",
173
+ "Failed\n",
174
+ " complexity | error | n_datums | n_labels | msg \n",
175
+ "---------------------------------------------------------------------------------------\n",
176
+ " 10000000 | MemoryError | 10000 | 1000 | Unable to allocate 7.63 MiB for an array with shape (1000, 1000) and data type int64\n",
177
+ " 1000000 | MemoryError | 1000 | 1000 | \n"
178
+ ]
179
+ },
180
+ {
181
+ "name": "stderr",
182
+ "output_type": "stream",
183
+ "text": [
184
+ "\n"
185
+ ]
186
+ }
187
+ ],
188
+ "source": [
189
+ "_ = b.run(\n",
190
+ " benchmark=semseg_finalize,\n",
191
+ " n_datums=n_datums,\n",
192
+ " n_labels=n_labels,\n",
193
+ ")"
194
+ ]
195
+ },
196
+ {
197
+ "cell_type": "code",
198
+ "execution_count": 6,
199
+ "metadata": {},
200
+ "outputs": [
201
+ {
202
+ "name": "stderr",
203
+ "output_type": "stream",
204
+ "text": [
205
+ " 20%|██ | 4/20 [02:25<09:40, 36.28s/it]"
206
+ ]
207
+ },
208
+ {
209
+ "name": "stdout",
210
+ "output_type": "stream",
211
+ "text": [
212
+ "=====================================================================\n",
213
+ "Details\n",
214
+ "{\n",
215
+ " \"benchmark\": \"benchmark_evaluate\",\n",
216
+ " \"limits\": {\n",
217
+ " \"memory_limit\": \"8.0 GB\",\n",
218
+ " \"time_limit\": \"5.0 seconds\",\n",
219
+ " \"repeat\": 1\n",
220
+ " },\n",
221
+ " \"passed\": 18,\n",
222
+ " \"failed\": 2,\n",
223
+ " \"total\": 20\n",
224
+ "}\n",
225
+ "\n",
226
+ "Passed\n",
227
+ " complexity | runtime | n_datums | n_labels \n",
228
+ "---------------------------------------------------------------------\n",
229
+ " 1000000 | 0.0537 | 10000 | 100 \n",
230
+ " 100000 | 0.0815 | 100 | 1000 \n",
231
+ " 100000 | 0.0137 | 1000 | 100 \n",
232
+ "\n",
233
+ "Failed\n",
234
+ " complexity | error | n_datums | n_labels | msg \n",
235
+ "---------------------------------------------------------------------------------------\n",
236
+ " 10000000 | MemoryError | 10000 | 1000 | Unable to allocate 23.8 MiB for an array with shape (1000, 1000, 25) and data type bool\n",
237
+ " 1000000 | MemoryError | 1000 | 1000 | Unable to allocate 3.73 GiB for an array with shape (1000, 1001, 1001) and data type int32\n"
238
+ ]
239
+ },
240
+ {
241
+ "name": "stderr",
242
+ "output_type": "stream",
243
+ "text": [
244
+ "\n"
245
+ ]
246
+ }
247
+ ],
248
+ "source": [
249
+ "_ = b.run(\n",
250
+ " benchmark=semseg_evaluate,\n",
251
+ " n_datums=n_datums,\n",
252
+ " n_labels=n_labels,\n",
253
+ ")"
254
+ ]
255
+ }
256
+ ],
257
+ "metadata": {
258
+ "kernelspec": {
259
+ "display_name": ".env-valor",
260
+ "language": "python",
261
+ "name": "python3"
262
+ },
263
+ "language_info": {
264
+ "codemirror_mode": {
265
+ "name": "ipython",
266
+ "version": 3
267
+ },
268
+ "file_extension": ".py",
269
+ "mimetype": "text/x-python",
270
+ "name": "python",
271
+ "nbconvert_exporter": "python",
272
+ "pygments_lexer": "ipython3",
273
+ "version": "3.10.15"
274
+ },
275
+ "orig_nbformat": 4
276
+ },
277
+ "nbformat": 4,
278
+ "nbformat_minor": 2
279
+ }
@@ -16,6 +16,49 @@ def test_no_data():
16
16
  loader.finalize()
17
17
 
18
18
 
19
+ def test_iou_computation():
20
+
21
+ detection = Detection(
22
+ uid="uid",
23
+ groundtruths=[
24
+ BoundingBox(xmin=0, xmax=10, ymin=0, ymax=10, labels=["0"]),
25
+ BoundingBox(xmin=100, xmax=110, ymin=100, ymax=110, labels=["0"]),
26
+ BoundingBox(
27
+ xmin=1000, xmax=1100, ymin=1000, ymax=1100, labels=["0"]
28
+ ),
29
+ ],
30
+ predictions=[
31
+ BoundingBox(
32
+ xmin=1,
33
+ xmax=11,
34
+ ymin=1,
35
+ ymax=11,
36
+ labels=["0", "1", "2"],
37
+ scores=[0.5, 0.25, 0.25],
38
+ ),
39
+ BoundingBox(
40
+ xmin=105,
41
+ xmax=116,
42
+ ymin=105,
43
+ ymax=116,
44
+ labels=["0", "1", "2"],
45
+ scores=[0.5, 0.25, 0.25],
46
+ ),
47
+ ],
48
+ )
49
+
50
+ loader = DataLoader()
51
+ loader.add_bounding_boxes([detection])
52
+
53
+ assert len(loader.pairs) == 1
54
+
55
+ # show that three unique IOUs exist
56
+ unique_ious = np.unique(loader.pairs[0][:, 3])
57
+ assert np.isclose(
58
+ unique_ious, np.array([0.0, 0.12755102, 0.68067227])
59
+ ).all()
60
+
61
+
19
62
  def test_mixed_annotations(
20
63
  rect1: tuple[float, float, float, float],
21
64
  rect1_rotated_5_degrees_around_origin: tuple[float, float, float, float],
@@ -87,7 +130,15 @@ def test_mixed_annotations(
87
130
 
88
131
  loader = DataLoader()
89
132
 
90
- for input_ in mixed_detections:
91
- with pytest.raises(ValueError) as e:
92
- loader.add_bounding_boxes([input_])
93
- assert "but annotation is of type" in str(e)
133
+ for detection in mixed_detections:
134
+
135
+ # anything can be converted to a bbox
136
+ loader.add_bounding_boxes([detection])
137
+
138
+ with pytest.raises(AttributeError) as e:
139
+ loader.add_polygons([detection])
140
+ assert "no attribute 'shape'" in str(e)
141
+
142
+ with pytest.raises(AttributeError) as e:
143
+ loader.add_bitmasks([detection])
144
+ assert "no attribute 'mask'" in str(e)
@@ -1,6 +1,10 @@
1
1
  import numpy as np
2
2
  import pytest
3
- from valor_lite.semantic_segmentation import Bitmask, Segmentation
3
+ from valor_lite.semantic_segmentation import (
4
+ Bitmask,
5
+ Segmentation,
6
+ generate_segmentation,
7
+ )
4
8
 
5
9
 
6
10
  def test_bitmask():
@@ -78,3 +82,55 @@ def test_segmentation():
78
82
  predictions=[],
79
83
  )
80
84
  assert "missing predictions" in str(e)
85
+
86
+
87
+ def test_generate_segmentation():
88
+
89
+ # N labels > 1
90
+ segmentation = generate_segmentation(
91
+ datum_uid="uid1",
92
+ number_of_unique_labels=3,
93
+ mask_height=2,
94
+ mask_width=3,
95
+ )
96
+
97
+ assert segmentation.uid == "uid1"
98
+ assert segmentation.shape == (2, 3)
99
+ assert segmentation.size == 6
100
+
101
+ assert len(segmentation.groundtruths) == 3
102
+ assert all(gt.mask.dtype == np.bool_ for gt in segmentation.groundtruths)
103
+ assert all(gt.mask.shape == (2, 3) for gt in segmentation.groundtruths)
104
+
105
+ assert len(segmentation.predictions) == 3
106
+ assert all(pd.mask.dtype == np.bool_ for pd in segmentation.predictions)
107
+ assert all(pd.mask.shape == (2, 3) for pd in segmentation.predictions)
108
+
109
+ # N labels = 1
110
+ segmentation = generate_segmentation(
111
+ datum_uid="uid1",
112
+ number_of_unique_labels=1,
113
+ mask_height=2,
114
+ mask_width=3,
115
+ )
116
+
117
+ assert segmentation.uid == "uid1"
118
+ assert segmentation.shape == (2, 3)
119
+ assert segmentation.size == 6
120
+
121
+ assert len(segmentation.groundtruths) == 1
122
+ assert all(gt.mask.dtype == np.bool_ for gt in segmentation.groundtruths)
123
+ assert all(gt.mask.shape == (2, 3) for gt in segmentation.groundtruths)
124
+
125
+ assert len(segmentation.predictions) == 1
126
+ assert all(pd.mask.dtype == np.bool_ for pd in segmentation.predictions)
127
+ assert all(pd.mask.shape == (2, 3) for pd in segmentation.predictions)
128
+
129
+ # N labels = 0
130
+ with pytest.raises(ValueError):
131
+ generate_segmentation(
132
+ datum_uid="uid1",
133
+ number_of_unique_labels=0,
134
+ mask_height=2,
135
+ mask_width=3,
136
+ )
@@ -1,4 +1,6 @@
1
+ import numpy as np
1
2
  from valor_lite.semantic_segmentation import (
3
+ Bitmask,
2
4
  DataLoader,
3
5
  MetricType,
4
6
  Segmentation,
@@ -89,3 +91,63 @@ def test_confusion_matrix_segmentations_from_boxes(
89
91
  assert m in expected_metrics
90
92
  for m in expected_metrics:
91
93
  assert m in actual_metrics
94
+
95
+
96
+ def test_confusion_matrix_intermediate_counting():
97
+
98
+ segmentation = Segmentation(
99
+ uid="uid1",
100
+ groundtruths=[
101
+ Bitmask(
102
+ mask=np.array([[False, False], [True, False]]),
103
+ label="a",
104
+ ),
105
+ Bitmask(
106
+ mask=np.array([[False, False], [False, True]]),
107
+ label="b",
108
+ ),
109
+ Bitmask(
110
+ mask=np.array([[True, False], [False, False]]),
111
+ label="c",
112
+ ),
113
+ Bitmask(
114
+ mask=np.array([[False, True], [False, False]]),
115
+ label="d",
116
+ ),
117
+ ],
118
+ predictions=[
119
+ Bitmask(
120
+ mask=np.array([[False, False], [False, False]]),
121
+ label="a",
122
+ ),
123
+ Bitmask(
124
+ mask=np.array([[False, False], [False, False]]),
125
+ label="b",
126
+ ),
127
+ Bitmask(
128
+ mask=np.array([[True, True], [True, True]]),
129
+ label="c",
130
+ ),
131
+ Bitmask(
132
+ mask=np.array([[False, False], [False, False]]),
133
+ label="d",
134
+ ),
135
+ ],
136
+ )
137
+
138
+ loader = DataLoader()
139
+ loader.add_data([segmentation])
140
+
141
+ assert len(loader.matrices) == 1
142
+ assert (
143
+ loader.matrices[0]
144
+ == np.array(
145
+ [
146
+ [0, 0, 0, 0, 0],
147
+ [0, 0, 0, 1, 0],
148
+ [0, 0, 0, 1, 0],
149
+ [0, 0, 0, 1, 0],
150
+ [0, 0, 0, 1, 0],
151
+ ]
152
+ )
153
+ ).all()
@@ -142,18 +142,6 @@ class Polygon:
142
142
  xmin, ymin, xmax, ymax = self.shape.bounds
143
143
  return (xmin, xmax, ymin, ymax)
144
144
 
145
- @property
146
- def annotation(self) -> ShapelyPolygon:
147
- """
148
- Returns the annotation's data representation.
149
-
150
- Returns
151
- -------
152
- shapely.geometry.Polygon
153
- The polygon shape.
154
- """
155
- return self.shape
156
-
157
145
 
158
146
  @dataclass
159
147
  class Bitmask:
@@ -222,18 +210,6 @@ class Bitmask:
222
210
  rows, cols = np.nonzero(self.mask)
223
211
  return (cols.min(), cols.max(), rows.min(), rows.max())
224
212
 
225
- @property
226
- def annotation(self) -> NDArray[np.bool_]:
227
- """
228
- Returns the annotation's data representation.
229
-
230
- Returns
231
- -------
232
- NDArray[np.bool_]
233
- The binary mask array.
234
- """
235
- return self.mask
236
-
237
213
 
238
214
  @dataclass
239
215
  class Detection: