Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -86,12 +86,14 @@ def scale_coords(img1_shape, coords, img0_shape, ratio_pad=None):
|
|
| 86 |
coords[:, :4].clip_(min=0, max=img1_shape[0]) # clip boxes
|
| 87 |
return coords
|
| 88 |
|
| 89 |
-
def postprocess(pred, img0_shape, img):
|
|
|
|
| 90 |
pred = non_max_suppression(pred, conf_thres=0.25, iou_thres=0.45, classes=None, agnostic=False)
|
| 91 |
results = []
|
| 92 |
for det in pred: # detections per image
|
| 93 |
if len(det):
|
| 94 |
-
det[:, :4] = scale_coords(img.shape[2:], det[:, :4], img0_shape).round()
|
|
|
|
| 95 |
for *xyxy, conf, cls in reversed(det):
|
| 96 |
results.append((xyxy, conf, cls))
|
| 97 |
return results
|
|
@@ -101,7 +103,8 @@ def detect_objects(image_path):
|
|
| 101 |
#img, img0 = preprocess_image(image_path)
|
| 102 |
img, img0 = preprocess_image(dicom_image)
|
| 103 |
pred = infer(model, img)
|
| 104 |
-
results = postprocess(pred, img0.shape, img)
|
|
|
|
| 105 |
return results
|
| 106 |
|
| 107 |
def draw_bounding_boxes(img, results):
|
|
@@ -112,8 +115,10 @@ def draw_bounding_boxes(img, results):
|
|
| 112 |
return img
|
| 113 |
|
| 114 |
def show_preds_image(filepath):
|
|
|
|
| 115 |
results = detect_objects(filepath)
|
| 116 |
-
img0 = cv2.imread(filepath)
|
|
|
|
| 117 |
img_with_boxes = draw_bounding_boxes(img0, results)
|
| 118 |
return cv2.cvtColor(img_with_boxes, cv2.COLOR_BGR2RGB)
|
| 119 |
|
|
|
|
| 86 |
coords[:, :4].clip_(min=0, max=img1_shape[0]) # clip boxes
|
| 87 |
return coords
|
| 88 |
|
| 89 |
+
#def postprocess(pred, img0_shape, img):
|
| 90 |
+
def postprocess(pred, img0, img):
|
| 91 |
pred = non_max_suppression(pred, conf_thres=0.25, iou_thres=0.45, classes=None, agnostic=False)
|
| 92 |
results = []
|
| 93 |
for det in pred: # detections per image
|
| 94 |
if len(det):
|
| 95 |
+
#det[:, :4] = scale_coords(img.shape[2:], det[:, :4], img0_shape).round()
|
| 96 |
+
det[:, :4] = scale_coords(img.shape[2:], det[:, :4], img0.shape).round()
|
| 97 |
for *xyxy, conf, cls in reversed(det):
|
| 98 |
results.append((xyxy, conf, cls))
|
| 99 |
return results
|
|
|
|
| 103 |
#img, img0 = preprocess_image(image_path)
|
| 104 |
img, img0 = preprocess_image(dicom_image)
|
| 105 |
pred = infer(model, img)
|
| 106 |
+
#results = postprocess(pred, img0.shape, img)
|
| 107 |
+
results = postprocess(pred, dicom_image, img)
|
| 108 |
return results
|
| 109 |
|
| 110 |
def draw_bounding_boxes(img, results):
|
|
|
|
| 115 |
return img
|
| 116 |
|
| 117 |
def show_preds_image(filepath):
|
| 118 |
+
dicom_image, dicom_meta = read_and_preprocess_dicom(image_path)
|
| 119 |
results = detect_objects(filepath)
|
| 120 |
+
#img0 = cv2.imread(filepath)
|
| 121 |
+
#img_with_boxes = draw_bounding_boxes(img0, results)
|
| 122 |
img_with_boxes = draw_bounding_boxes(img0, results)
|
| 123 |
return cv2.cvtColor(img_with_boxes, cv2.COLOR_BGR2RGB)
|
| 124 |
|