valor-lite 0.33.16__py3-none-any.whl → 0.33.17__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.

Potentially problematic release.


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

@@ -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:
@@ -1,17 +1,10 @@
1
1
  from collections import defaultdict
2
2
  from dataclasses import dataclass
3
- from typing import Type
4
3
 
5
4
  import numpy as np
6
- import valor_lite.object_detection.annotation as annotation
7
5
  from numpy.typing import NDArray
8
6
  from tqdm import tqdm
9
- from valor_lite.object_detection.annotation import (
10
- Bitmask,
11
- BoundingBox,
12
- Detection,
13
- Polygon,
14
- )
7
+ from valor_lite.object_detection.annotation import Detection
15
8
  from valor_lite.object_detection.computation import (
16
9
  compute_bbox_iou,
17
10
  compute_bitmask_iou,
@@ -396,74 +389,47 @@ class DataLoader:
396
389
 
397
390
  return self._evaluator.label_to_index[label]
398
391
 
399
- def _compute_ious_and_cache_pairs(
392
+ def _cache_pairs(
400
393
  self,
401
394
  uid_index: int,
402
395
  groundtruths: list,
403
396
  predictions: list,
404
- annotation_type: Type[BoundingBox] | Type[Polygon] | Type[Bitmask],
397
+ ious: NDArray[np.float64],
405
398
  ) -> None:
406
399
  """
407
400
  Compute IOUs between groundtruths and preditions before storing as pairs.
408
401
 
409
402
  Parameters
410
403
  ----------
411
- uid_index: int
404
+ uid_index : int
412
405
  The index of the detection.
413
- groundtruths: list
406
+ groundtruths : list
414
407
  A list of groundtruths.
415
- predictions: list
408
+ predictions : list
416
409
  A list of predictions.
417
- annotation_type: type[BoundingBox] | type[Polygon] | type[Bitmask]
418
- The type of annotation to compute IOUs for.
410
+ ious : NDArray[np.float64]
411
+ An array with shape (n_preds, n_gts) containing IOUs.
419
412
  """
420
413
 
421
- pairs = list()
422
- n_predictions = len(predictions)
423
- n_groundtruths = len(groundtruths)
424
-
425
- all_pairs = np.array(
426
- [
427
- np.array([gann, pann])
428
- for _, _, _, pann in predictions
429
- for _, _, gann in groundtruths
430
- ]
431
- )
432
-
433
- match annotation_type:
434
- case annotation.BoundingBox:
435
- ious = compute_bbox_iou(all_pairs)
436
- case annotation.Polygon:
437
- ious = compute_polygon_iou(all_pairs)
438
- case annotation.Bitmask:
439
- ious = compute_bitmask_iou(all_pairs)
440
- case _:
441
- raise ValueError(
442
- f"Invalid annotation type `{annotation_type}`."
443
- )
444
-
445
- ious = ious.reshape(n_predictions, n_groundtruths)
446
414
  predictions_with_iou_of_zero = np.where((ious < 1e-9).all(axis=1))[0]
447
415
  groundtruths_with_iou_of_zero = np.where((ious < 1e-9).all(axis=0))[0]
448
416
 
449
- pairs.extend(
450
- [
451
- np.array(
452
- [
453
- float(uid_index),
454
- float(gidx),
455
- float(pidx),
456
- ious[pidx, gidx],
457
- float(glabel),
458
- float(plabel),
459
- float(score),
460
- ]
461
- )
462
- for pidx, plabel, score, _ in predictions
463
- for gidx, glabel, _ in groundtruths
464
- if ious[pidx, gidx] >= 1e-9
465
- ]
466
- )
417
+ pairs = [
418
+ np.array(
419
+ [
420
+ float(uid_index),
421
+ float(gidx),
422
+ float(pidx),
423
+ ious[pidx, gidx],
424
+ float(glabel),
425
+ float(plabel),
426
+ float(score),
427
+ ]
428
+ )
429
+ for pidx, plabel, score in predictions
430
+ for gidx, glabel in groundtruths
431
+ if ious[pidx, gidx] >= 1e-9
432
+ ]
467
433
  pairs.extend(
468
434
  [
469
435
  np.array(
@@ -496,13 +462,12 @@ class DataLoader:
496
462
  for index in groundtruths_with_iou_of_zero
497
463
  ]
498
464
  )
499
-
500
465
  self.pairs.append(np.array(pairs))
501
466
 
502
467
  def _add_data(
503
468
  self,
504
469
  detections: list[Detection],
505
- annotation_type: type[Bitmask] | type[BoundingBox] | type[Polygon],
470
+ detection_ious: list[NDArray[np.float64]],
506
471
  show_progress: bool = False,
507
472
  ):
508
473
  """
@@ -512,13 +477,15 @@ class DataLoader:
512
477
  ----------
513
478
  detections : list[Detection]
514
479
  A list of Detection objects.
515
- annotation_type : type[Bitmask] | type[BoundingBox] | type[Polygon]
516
- The annotation type to process.
480
+ detection_ious : list[NDArray[np.float64]]
481
+ A list of arrays containing IOUs per detection.
517
482
  show_progress : bool, default=False
518
483
  Toggle for tqdm progress bar.
519
484
  """
520
485
  disable_tqdm = not show_progress
521
- for detection in tqdm(detections, disable=disable_tqdm):
486
+ for detection, ious in tqdm(
487
+ zip(detections, detection_ious), disable=disable_tqdm
488
+ ):
522
489
 
523
490
  # update metadata
524
491
  self._evaluator.n_datums += 1
@@ -541,11 +508,6 @@ class DataLoader:
541
508
  predictions = list()
542
509
 
543
510
  for gidx, gann in enumerate(detection.groundtruths):
544
- if not isinstance(gann, annotation_type):
545
- raise ValueError(
546
- f"Expected {annotation_type}, but annotation is of type {type(gann)}."
547
- )
548
-
549
511
  self._evaluator.groundtruth_examples[uid_index][
550
512
  gidx
551
513
  ] = gann.extrema
@@ -556,16 +518,10 @@ class DataLoader:
556
518
  (
557
519
  gidx,
558
520
  label_idx,
559
- gann.annotation,
560
521
  )
561
522
  )
562
523
 
563
524
  for pidx, pann in enumerate(detection.predictions):
564
- if not isinstance(pann, annotation_type):
565
- raise ValueError(
566
- f"Expected {annotation_type}, but annotation is of type {type(pann)}."
567
- )
568
-
569
525
  self._evaluator.prediction_examples[uid_index][
570
526
  pidx
571
527
  ] = pann.extrema
@@ -577,15 +533,14 @@ class DataLoader:
577
533
  pidx,
578
534
  label_idx,
579
535
  pscore,
580
- pann.annotation,
581
536
  )
582
537
  )
583
538
 
584
- self._compute_ious_and_cache_pairs(
539
+ self._cache_pairs(
585
540
  uid_index=uid_index,
586
541
  groundtruths=groundtruths,
587
542
  predictions=predictions,
588
- annotation_type=annotation_type,
543
+ ious=ious,
589
544
  )
590
545
 
591
546
  def add_bounding_boxes(
@@ -603,10 +558,22 @@ class DataLoader:
603
558
  show_progress : bool, default=False
604
559
  Toggle for tqdm progress bar.
605
560
  """
561
+ ious = [
562
+ compute_bbox_iou(
563
+ np.array(
564
+ [
565
+ [gt.extrema, pd.extrema]
566
+ for pd in detection.predictions
567
+ for gt in detection.groundtruths
568
+ ]
569
+ )
570
+ ).reshape(len(detection.predictions), len(detection.groundtruths))
571
+ for detection in detections
572
+ ]
606
573
  return self._add_data(
607
574
  detections=detections,
575
+ detection_ious=ious,
608
576
  show_progress=show_progress,
609
- annotation_type=BoundingBox,
610
577
  )
611
578
 
612
579
  def add_polygons(
@@ -624,10 +591,22 @@ class DataLoader:
624
591
  show_progress : bool, default=False
625
592
  Toggle for tqdm progress bar.
626
593
  """
594
+ ious = [
595
+ compute_polygon_iou(
596
+ np.array(
597
+ [
598
+ [gt.shape, pd.shape] # type: ignore - using the AttributeError as a validator
599
+ for pd in detection.predictions
600
+ for gt in detection.groundtruths
601
+ ]
602
+ )
603
+ ).reshape(len(detection.predictions), len(detection.groundtruths))
604
+ for detection in detections
605
+ ]
627
606
  return self._add_data(
628
607
  detections=detections,
608
+ detection_ious=ious,
629
609
  show_progress=show_progress,
630
- annotation_type=Polygon,
631
610
  )
632
611
 
633
612
  def add_bitmasks(
@@ -645,10 +624,22 @@ class DataLoader:
645
624
  show_progress : bool, default=False
646
625
  Toggle for tqdm progress bar.
647
626
  """
627
+ ious = [
628
+ compute_bitmask_iou(
629
+ np.array(
630
+ [
631
+ [gt.mask, pd.mask] # type: ignore - using the AttributeError as a validator
632
+ for pd in detection.predictions
633
+ for gt in detection.groundtruths
634
+ ]
635
+ )
636
+ ).reshape(len(detection.predictions), len(detection.groundtruths))
637
+ for detection in detections
638
+ ]
648
639
  return self._add_data(
649
640
  detections=detections,
641
+ detection_ious=ious,
650
642
  show_progress=show_progress,
651
- annotation_type=Bitmask,
652
643
  )
653
644
 
654
645
  def finalize(self) -> Evaluator:
@@ -46,8 +46,8 @@ def compute_intermediate_confusion_matrices(
46
46
  predictions.reshape(1, n_pd_labels, -1),
47
47
  ).sum(axis=2)
48
48
 
49
- intersected_groundtruth_counts = intersection_counts.sum(axis=0)
50
- intersected_prediction_counts = intersection_counts.sum(axis=1)
49
+ intersected_groundtruth_counts = intersection_counts.sum(axis=1)
50
+ intersected_prediction_counts = intersection_counts.sum(axis=0)
51
51
 
52
52
  confusion_matrix = np.zeros((n_labels + 1, n_labels + 1), dtype=np.int32)
53
53
  confusion_matrix[0, 0] = background_counts
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: valor-lite
3
- Version: 0.33.16
3
+ Version: 0.33.17
4
4
  Summary: Compute valor metrics locally.
5
5
  License: MIT License
6
6
 
@@ -8,14 +8,14 @@ valor_lite/classification/manager.py,sha256=8GXZECSx4CBbG5NfPrA19BPENqmrjo-wZBma
8
8
  valor_lite/classification/metric.py,sha256=fkAo-_3s4EIRSkyn3owBSf4_Gp6lBK9xdToDYMWmT8A,12236
9
9
  valor_lite/classification/utilities.py,sha256=PmQar06Vt-ew4Jvnn0IM63mq730QVTsdRtFdVu1HMFU,6885
10
10
  valor_lite/object_detection/__init__.py,sha256=Ql8rju2q7y0Zd9zFvtBJDRhgQFDm1RSYkTsyH3ZE6pA,648
11
- valor_lite/object_detection/annotation.py,sha256=o6VfiRobiB0ljqsNBLAYMXgi32RSIR7uTA-dgxq6zBI,8248
11
+ valor_lite/object_detection/annotation.py,sha256=x9bsl8b75yvkMByXXiIYI9d9T03olDqtykSvKJc3aFw,7729
12
12
  valor_lite/object_detection/computation.py,sha256=P5ijxEBuZ3mxYjBQy24TiQpGxRmPuS40Gwn44uv0J7M,28064
13
- valor_lite/object_detection/manager.py,sha256=rHY6-aiPVOXKQk7e_MmKpZxn6wdLAhdlj_njaNdYG7Q,23299
13
+ valor_lite/object_detection/manager.py,sha256=I1AwelhxeOA7GJ31eCw8ubNvmprIEGRmbxONozQMsC4,22998
14
14
  valor_lite/object_detection/metric.py,sha256=8QhdauuaRrzE39idetkFYTPxA12wrBalQDIR4IUzEbg,24794
15
15
  valor_lite/object_detection/utilities.py,sha256=98VSW-g8EYI8Cdd9KHLHdm6F4fI89jaX5I4z99zny4s,16271
16
16
  valor_lite/semantic_segmentation/__init__.py,sha256=HQQkr3iBPQfdUrsu0uvx-Uyv9SYmumU1B3slbWOnpNY,245
17
17
  valor_lite/semantic_segmentation/annotation.py,sha256=CujYFdHS3fgr4Y7mEDs_u1XBmbPJzNU2CdqvjCT_d_A,2938
18
- valor_lite/semantic_segmentation/computation.py,sha256=rrql3zmpqt4Zygc2BD4SyUfNW_NXC93_kHB-lGBzjXU,5122
18
+ valor_lite/semantic_segmentation/computation.py,sha256=471Pl-0TCFBdkgZMvYDFs4aa6Ak5kv31xarK_USl3pU,5122
19
19
  valor_lite/semantic_segmentation/manager.py,sha256=pMepH3zk_fApyFtC9tLrmEYuCbg1n5TLh1J8QRadE44,14287
20
20
  valor_lite/semantic_segmentation/metric.py,sha256=aJv3wPEl6USLhZ3c4yz6prnBU-EaG4Kz16f0BXcodd4,7046
21
21
  valor_lite/semantic_segmentation/utilities.py,sha256=vZM66YNMz9VJclhuKvcWp74nF65s6bscnnD5U9iDW7Q,2925
@@ -31,8 +31,8 @@ valor_lite/text_generation/llm/instructions.py,sha256=fz2onBZZWcl5W8iy7zEWkPGU9N
31
31
  valor_lite/text_generation/llm/integrations.py,sha256=-rTfdAjq1zH-4ixwYuMQEOQ80pIFzMTe0BYfroVx3Pg,6974
32
32
  valor_lite/text_generation/llm/utilities.py,sha256=bjqatGgtVTcl1PrMwiDKTYPGJXKrBrx7PDtzIblGSys,1178
33
33
  valor_lite/text_generation/llm/validators.py,sha256=Wzr5RlfF58_2wOU-uTw7C8skan_fYdhy4Gfn0jSJ8HM,2700
34
- valor_lite-0.33.16.dist-info/LICENSE,sha256=M0L53VuwfEEqezhHb7NPeYcO_glw7-k4DMLZQ3eRN64,1068
35
- valor_lite-0.33.16.dist-info/METADATA,sha256=mpXXDWKiCL8OsCLqRevVH6AkWMsYBT4Qjqdum3ZYFos,5888
36
- valor_lite-0.33.16.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
37
- valor_lite-0.33.16.dist-info/top_level.txt,sha256=9ujykxSwpl2Hu0_R95UQTR_l07k9UUTSdrpiqmq6zc4,11
38
- valor_lite-0.33.16.dist-info/RECORD,,
34
+ valor_lite-0.33.17.dist-info/LICENSE,sha256=M0L53VuwfEEqezhHb7NPeYcO_glw7-k4DMLZQ3eRN64,1068
35
+ valor_lite-0.33.17.dist-info/METADATA,sha256=7YPVo6unLWsA7zNV7LcKnwBJm6AqCWjfaeM5nVyVKho,5888
36
+ valor_lite-0.33.17.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
37
+ valor_lite-0.33.17.dist-info/top_level.txt,sha256=9ujykxSwpl2Hu0_R95UQTR_l07k9UUTSdrpiqmq6zc4,11
38
+ valor_lite-0.33.17.dist-info/RECORD,,