Martin Tomov commited on
Commit
484046d
·
verified ·
1 Parent(s): 33709f3

adjustment output

Browse files
Files changed (1) hide show
  1. app.py +14 -8
app.py CHANGED
@@ -34,15 +34,21 @@ class DetectionResult:
34
 
35
  @classmethod
36
  def from_dict(cls, detection_dict: Dict) -> 'DetectionResult':
37
- return cls(
38
- score=detection_dict['score'],
39
- label=detection_dict['label'],
40
- box=BoundingBox(
41
- xmin=detection_dict['box']['xmin'],
42
- ymin=detection_dict['box']['ymin'],
43
- xmax=detection_dict['box']['xmax']
 
 
 
 
 
44
  )
45
- )
 
46
 
47
  def annotate(image: Union[Image.Image, np.ndarray], detection_results: List[DetectionResult]) -> np.ndarray:
48
  image_cv2 = np.array(image) if isinstance(image, Image.Image) else image
 
34
 
35
  @classmethod
36
  def from_dict(cls, detection_dict: Dict) -> 'DetectionResult':
37
+ # Debugging: Print the dictionary to see its structure
38
+ print("Detection Dictionary:", detection_dict)
39
+ try:
40
+ return cls(
41
+ score=detection_dict['score'],
42
+ label=detection_dict['label'],
43
+ box=BoundingBox(
44
+ xmin=detection_dict['box']['xmin'],
45
+ ymin=detection_dict['box']['ymin'],
46
+ xmax=detection_dict['box']['xmax'],
47
+ ymax=detection_dict['box']['ymax']
48
+ )
49
  )
50
+ except KeyError as e:
51
+ raise ValueError(f"Missing key in detection dictionary: {e}")
52
 
53
  def annotate(image: Union[Image.Image, np.ndarray], detection_results: List[DetectionResult]) -> np.ndarray:
54
  image_cv2 = np.array(image) if isinstance(image, Image.Image) else image