Revise file_bytes for detection.
Browse files
app.py
CHANGED
|
@@ -86,7 +86,7 @@ model = load_model()
|
|
| 86 |
# file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
|
| 87 |
# image = cv2.imdecode(file_bytes, 1)
|
| 88 |
|
| 89 |
-
|
| 90 |
|
| 91 |
|
| 92 |
# Utility Functions
|
|
@@ -440,33 +440,36 @@ if uploaded_file is not None:
|
|
| 440 |
redirect_button("https://new-ohif-viewer-k7c3gdlxua-et.a.run.app/")
|
| 441 |
|
| 442 |
with col2:
|
| 443 |
-
if
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
|
|
|
|
|
|
|
|
|
| 470 |
|
| 471 |
with col3:
|
| 472 |
if st.button('Generate Grad-CAM'):
|
|
|
|
| 86 |
# file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
|
| 87 |
# image = cv2.imdecode(file_bytes, 1)
|
| 88 |
|
| 89 |
+
# st.image(image, caption='Uploaded Image.', use_column_width=True)
|
| 90 |
|
| 91 |
|
| 92 |
# Utility Functions
|
|
|
|
| 440 |
redirect_button("https://new-ohif-viewer-k7c3gdlxua-et.a.run.app/")
|
| 441 |
|
| 442 |
with col2:
|
| 443 |
+
if uploaded_file is not None:
|
| 444 |
+
file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
|
| 445 |
+
image = cv2.imdecode(file_bytes, 1)
|
| 446 |
+
if st.button('Auto Detect'):
|
| 447 |
+
st.write("Processing...")
|
| 448 |
+
input_image = preprocess_image(image)
|
| 449 |
+
pred_bbox, pred_label, pred_label_confidence = predict(model, input_image)
|
| 450 |
+
|
| 451 |
+
# Updated label mapping based on the dataset
|
| 452 |
+
label_mapping = {
|
| 453 |
+
0: 'Atelectasis',
|
| 454 |
+
1: 'Cardiomegaly',
|
| 455 |
+
2: 'Effusion',
|
| 456 |
+
3: 'Infiltrate',
|
| 457 |
+
4: 'Mass',
|
| 458 |
+
5: 'Nodule',
|
| 459 |
+
6: 'Pneumonia',
|
| 460 |
+
7: 'Pneumothorax'
|
| 461 |
+
}
|
| 462 |
+
|
| 463 |
+
if pred_label_confidence < 0.2:
|
| 464 |
+
st.write("May not detect a disease.")
|
| 465 |
+
else:
|
| 466 |
+
pred_label_name = label_mapping[pred_label]
|
| 467 |
+
st.write(f"Prediction Label: {pred_label_name}")
|
| 468 |
+
st.write(f"Prediction Bounding Box: {pred_bbox}")
|
| 469 |
+
st.write(f"Prediction Confidence: {pred_label_confidence:.2f}")
|
| 470 |
+
|
| 471 |
+
output_image = draw_bbox(image.copy(), pred_bbox)
|
| 472 |
+
st.image(output_image, caption='Detected Image.', use_column_width=True)
|
| 473 |
|
| 474 |
with col3:
|
| 475 |
if st.button('Generate Grad-CAM'):
|