valor-lite 0.36.4__py3-none-any.whl → 0.36.5__py3-none-any.whl

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.
@@ -1,3 +1,4 @@
1
+ import warnings
1
2
  from dataclasses import dataclass, field
2
3
 
3
4
  import numpy as np
@@ -79,30 +80,37 @@ class Segmentation:
79
80
  )
80
81
  self.size = self.shape[0] * self.shape[1]
81
82
 
82
- mask_accumulation = None
83
- for groundtruth in self.groundtruths:
84
- if self.shape != groundtruth.mask.shape:
85
- raise ValueError(
86
- f"ground truth masks for datum '{self.uid}' should have shape '{self.shape}'. Received mask with shape '{groundtruth.mask.shape}'"
87
- )
88
-
89
- if mask_accumulation is None:
90
- mask_accumulation = groundtruth.mask.copy()
91
- elif np.logical_and(mask_accumulation, groundtruth.mask).any():
92
- raise ValueError("ground truth masks cannot overlap")
93
- else:
94
- mask_accumulation = mask_accumulation | groundtruth.mask
83
+ self._validate_bitmasks(self.groundtruths, "ground truth")
84
+ self._validate_bitmasks(self.predictions, "prediction")
95
85
 
86
+ def _validate_bitmasks(self, bitmasks: list[Bitmask], key: str):
96
87
  mask_accumulation = None
97
- for prediction in self.predictions:
98
- if self.shape != prediction.mask.shape:
88
+ mask_overlap_accumulation = None
89
+ for idx, bitmask in enumerate(bitmasks):
90
+ if not isinstance(bitmask, Bitmask):
91
+ raise ValueError(f"expected 'Bitmask', got '{bitmask}'")
92
+ if self.shape != bitmask.mask.shape:
99
93
  raise ValueError(
100
- f"prediction masks for datum '{self.uid}' should have shape '{self.shape}'. Received mask with shape '{prediction.mask.shape}'"
94
+ f"{key} masks for datum '{self.uid}' should have shape '{self.shape}'. Received mask with shape '{bitmask.mask.shape}'"
101
95
  )
102
96
 
103
97
  if mask_accumulation is None:
104
- mask_accumulation = prediction.mask.copy()
105
- elif np.logical_and(mask_accumulation, prediction.mask).any():
106
- raise ValueError("prediction masks cannot overlap")
98
+ mask_accumulation = bitmask.mask.copy()
99
+ mask_overlap_accumulation = np.zeros_like(mask_accumulation)
100
+ elif np.logical_and(mask_accumulation, bitmask.mask).any():
101
+ mask_overlap = np.logical_and(mask_accumulation, bitmask.mask)
102
+ bitmasks[idx].mask[mask_overlap] = False
103
+ mask_overlap_accumulation = (
104
+ mask_overlap_accumulation | mask_overlap
105
+ )
107
106
  else:
108
- mask_accumulation = mask_accumulation | prediction.mask
107
+ mask_accumulation = mask_accumulation | bitmask.mask
108
+ if (
109
+ mask_overlap_accumulation is not None
110
+ and mask_overlap_accumulation.any()
111
+ ):
112
+ count = mask_overlap_accumulation.sum()
113
+ total = mask_overlap_accumulation.size
114
+ warnings.warn(
115
+ f"{key} masks for datum '{self.uid}' had {count} / {total} pixels overlapped."
116
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: valor-lite
3
- Version: 0.36.4
3
+ Version: 0.36.5
4
4
  Summary: Evaluate machine learning models.
5
5
  Project-URL: homepage, https://www.striveworks.com
6
6
  Requires-Python: >=3.10
@@ -17,7 +17,7 @@ valor_lite/object_detection/manager.py,sha256=HfSbq4vfKv2Q3kBRIqpBbq7VCrOxCl7_Pd
17
17
  valor_lite/object_detection/metric.py,sha256=sUYSZwXYfIyfmXG6_7Tje1_ZL_QwvecPq85jrGmwOWE,22739
18
18
  valor_lite/object_detection/utilities.py,sha256=tNdv5dL7JhzOamGQkZ8x3ocZoTwPI6K8rcRAGMhp2nc,11217
19
19
  valor_lite/semantic_segmentation/__init__.py,sha256=3YdItCThY_tW23IChCBm-R0zahnbZ06JDVjs-gQLVes,293
20
- valor_lite/semantic_segmentation/annotation.py,sha256=XRMV32Sx9A1bAVMFQdBGc3tN5Xz2RfmlyKGXCzdee7A,3705
20
+ valor_lite/semantic_segmentation/annotation.py,sha256=KrDqmSVzBsutxEdh0Kl8VqcEpTe4S68UdkVg-nyxcFg,4025
21
21
  valor_lite/semantic_segmentation/benchmark.py,sha256=uxd0SiDY3npsgU5pdeT4HvNP_au9GVRWzoqT6br9DtM,5961
22
22
  valor_lite/semantic_segmentation/computation.py,sha256=ZO0qAFmq8lN73UjCyiynSv18qQDtn35FNOmvuXY4rOw,7380
23
23
  valor_lite/semantic_segmentation/manager.py,sha256=h5w8Xl-O9gZxAzqT-ESofVE2th7d3cYahx4hHBic3pw,14256
@@ -35,7 +35,7 @@ valor_lite/text_generation/llm/instructions.py,sha256=fz2onBZZWcl5W8iy7zEWkPGU9N
35
35
  valor_lite/text_generation/llm/integrations.py,sha256=-rTfdAjq1zH-4ixwYuMQEOQ80pIFzMTe0BYfroVx3Pg,6974
36
36
  valor_lite/text_generation/llm/utilities.py,sha256=bjqatGgtVTcl1PrMwiDKTYPGJXKrBrx7PDtzIblGSys,1178
37
37
  valor_lite/text_generation/llm/validators.py,sha256=Wzr5RlfF58_2wOU-uTw7C8skan_fYdhy4Gfn0jSJ8HM,2700
38
- valor_lite-0.36.4.dist-info/METADATA,sha256=2UmPknazuM-lpHiYGqEDGl_JBr7dX-HJPCGFJKY5kck,5071
39
- valor_lite-0.36.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
40
- valor_lite-0.36.4.dist-info/top_level.txt,sha256=9ujykxSwpl2Hu0_R95UQTR_l07k9UUTSdrpiqmq6zc4,11
41
- valor_lite-0.36.4.dist-info/RECORD,,
38
+ valor_lite-0.36.5.dist-info/METADATA,sha256=Ttur0Z2wqHuaN6cOYousNZUqBL9A9qZFEnZejPSFRdo,5071
39
+ valor_lite-0.36.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
40
+ valor_lite-0.36.5.dist-info/top_level.txt,sha256=9ujykxSwpl2Hu0_R95UQTR_l07k9UUTSdrpiqmq6zc4,11
41
+ valor_lite-0.36.5.dist-info/RECORD,,