Kalbe-x-Bangkit
commited on
Commit
•
1259972
1
Parent(s):
1fe7054
Update app.py
Browse files
app.py
CHANGED
@@ -469,14 +469,9 @@ if uploaded_file is not None:
|
|
469 |
image = cv2.imdecode(file_bytes, 1)
|
470 |
if st.button('Auto Detect'):
|
471 |
st.write("Processing...")
|
472 |
-
input_image = image
|
473 |
-
# input_image = enhancement_type
|
474 |
-
# input_image = cv2.resize(enhanced_image, (W, H)) # Resize the enhanced image to the required input size
|
475 |
-
# input_image = (input_image - 127.5) / 127.5 # Normalize to [-1, +1]
|
476 |
-
# input_image = np.expand_dims(input_image, axis=0).astype(np.float32) # Expand dimensions and convert to float32
|
477 |
-
|
478 |
pred_bbox, pred_label, pred_label_confidence = predict(model_detection, input_image)
|
479 |
-
|
480 |
# Updated label mapping based on the dataset
|
481 |
label_mapping = {
|
482 |
0: 'Atelectasis',
|
@@ -488,7 +483,7 @@ if uploaded_file is not None:
|
|
488 |
6: 'Pneumonia',
|
489 |
7: 'Pneumothorax'
|
490 |
}
|
491 |
-
|
492 |
if pred_label_confidence < 0.2:
|
493 |
st.write("May not detect a disease.")
|
494 |
else:
|
@@ -496,9 +491,43 @@ if uploaded_file is not None:
|
|
496 |
st.write(f"Prediction Label: {pred_label_name}")
|
497 |
st.write(f"Prediction Bounding Box: {pred_bbox}")
|
498 |
st.write(f"Prediction Confidence: {pred_label_confidence:.2f}")
|
499 |
-
|
500 |
output_image = draw_bbox(image.copy(), pred_bbox)
|
501 |
st.image(output_image, caption='Detected Image.', use_column_width=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
502 |
|
503 |
with col3:
|
504 |
if st.button('Generate Grad-CAM'):
|
|
|
469 |
image = cv2.imdecode(file_bytes, 1)
|
470 |
if st.button('Auto Detect'):
|
471 |
st.write("Processing...")
|
472 |
+
input_image = preprocess_image(image)
|
|
|
|
|
|
|
|
|
|
|
473 |
pred_bbox, pred_label, pred_label_confidence = predict(model_detection, input_image)
|
474 |
+
|
475 |
# Updated label mapping based on the dataset
|
476 |
label_mapping = {
|
477 |
0: 'Atelectasis',
|
|
|
483 |
6: 'Pneumonia',
|
484 |
7: 'Pneumothorax'
|
485 |
}
|
486 |
+
|
487 |
if pred_label_confidence < 0.2:
|
488 |
st.write("May not detect a disease.")
|
489 |
else:
|
|
|
491 |
st.write(f"Prediction Label: {pred_label_name}")
|
492 |
st.write(f"Prediction Bounding Box: {pred_bbox}")
|
493 |
st.write(f"Prediction Confidence: {pred_label_confidence:.2f}")
|
494 |
+
|
495 |
output_image = draw_bbox(image.copy(), pred_bbox)
|
496 |
st.image(output_image, caption='Detected Image.', use_column_width=True)
|
497 |
+
|
498 |
+
|
499 |
+
# if st.button('Auto Detect'):
|
500 |
+
# st.write("Processing...")
|
501 |
+
# input_image = image
|
502 |
+
# # input_image = enhancement_type
|
503 |
+
# # input_image = cv2.resize(enhanced_image, (W, H)) # Resize the enhanced image to the required input size
|
504 |
+
# # input_image = (input_image - 127.5) / 127.5 # Normalize to [-1, +1]
|
505 |
+
# # input_image = np.expand_dims(input_image, axis=0).astype(np.float32) # Expand dimensions and convert to float32
|
506 |
+
|
507 |
+
# pred_bbox, pred_label, pred_label_confidence = predict(model_detection, input_image)
|
508 |
+
|
509 |
+
# # Updated label mapping based on the dataset
|
510 |
+
# label_mapping = {
|
511 |
+
# 0: 'Atelectasis',
|
512 |
+
# 1: 'Cardiomegaly',
|
513 |
+
# 2: 'Effusion',
|
514 |
+
# 3: 'Infiltrate',
|
515 |
+
# 4: 'Mass',
|
516 |
+
# 5: 'Nodule',
|
517 |
+
# 6: 'Pneumonia',
|
518 |
+
# 7: 'Pneumothorax'
|
519 |
+
# }
|
520 |
+
|
521 |
+
# if pred_label_confidence < 0.2:
|
522 |
+
# st.write("May not detect a disease.")
|
523 |
+
# else:
|
524 |
+
# pred_label_name = label_mapping[pred_label]
|
525 |
+
# st.write(f"Prediction Label: {pred_label_name}")
|
526 |
+
# st.write(f"Prediction Bounding Box: {pred_bbox}")
|
527 |
+
# st.write(f"Prediction Confidence: {pred_label_confidence:.2f}")
|
528 |
+
|
529 |
+
# output_image = draw_bbox(image.copy(), pred_bbox)
|
530 |
+
# st.image(output_image, caption='Detected Image.', use_column_width=True)
|
531 |
|
532 |
with col3:
|
533 |
if st.button('Generate Grad-CAM'):
|