Junathan Richie commited on
Commit
d00e3b8
·
1 Parent(s): 2ea67b5

feat: add handle dont draw if no tumor

Browse files
Files changed (1) hide show
  1. app.py +14 -4
app.py CHANGED
@@ -34,13 +34,18 @@ async def inference(file: UploadFile):
34
  for r in results:
35
  boxes = r.boxes
36
  for box in boxes:
 
 
 
 
 
 
 
37
  x1, y1, x2, y2 = box.xyxy[0]
38
  x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2)
39
 
40
  cv2.rectangle(img, (x1, y1), (x2, y2), (255, 0, 255), 2)
41
 
42
- label = box.cls[0].item()
43
- label_name = model.names[label]
44
  detections.append(label_name)
45
  (text_width, text_height), baseline = cv2.getTextSize(label_name, cv2.FONT_HERSHEY_SIMPLEX, 0.9, 2)
46
  cv2.rectangle(img, (x1, y1 - text_height - baseline - 5), (x1 + text_width, y1), (255, 0, 255), -1)
@@ -102,6 +107,13 @@ async def inference_volume(file: UploadFile):
102
  boxes = r.boxes
103
 
104
  for box in boxes:
 
 
 
 
 
 
 
105
  x1, y1, x2, y2 = box.xyxy[0]
106
  x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2)
107
 
@@ -112,8 +124,6 @@ async def inference_volume(file: UploadFile):
112
  volume_mm3 = calculate_sphere_volume(width, height)
113
  print("VOLUME")
114
  print(volume_mm3)
115
- label = int(box.cls[0].item())
116
- label_name = model.names[label]
117
 
118
  detections.append({
119
  "class": label_name,
 
34
  for r in results:
35
  boxes = r.boxes
36
  for box in boxes:
37
+ label = box.cls[0].item()
38
+ label_name = model.names[label]
39
+
40
+ # Skip NoTumor class - don't draw bounding box
41
+ if label_name.lower() == "notumor":
42
+ continue
43
+
44
  x1, y1, x2, y2 = box.xyxy[0]
45
  x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2)
46
 
47
  cv2.rectangle(img, (x1, y1), (x2, y2), (255, 0, 255), 2)
48
 
 
 
49
  detections.append(label_name)
50
  (text_width, text_height), baseline = cv2.getTextSize(label_name, cv2.FONT_HERSHEY_SIMPLEX, 0.9, 2)
51
  cv2.rectangle(img, (x1, y1 - text_height - baseline - 5), (x1 + text_width, y1), (255, 0, 255), -1)
 
107
  boxes = r.boxes
108
 
109
  for box in boxes:
110
+ label = int(box.cls[0].item())
111
+ label_name = model.names[label]
112
+
113
+ # Skip NoTumor class - don't draw bounding box or include in detections
114
+ if label_name.lower() == "notumor":
115
+ continue
116
+
117
  x1, y1, x2, y2 = box.xyxy[0]
118
  x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2)
119
 
 
124
  volume_mm3 = calculate_sphere_volume(width, height)
125
  print("VOLUME")
126
  print(volume_mm3)
 
 
127
 
128
  detections.append({
129
  "class": label_name,