Revise if detection.
Browse files
app.py
CHANGED
|
@@ -241,7 +241,7 @@ def compute_gradcam(model_gradcam, img_path, layer_name='bn'):
|
|
| 241 |
# model_gradcam.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.0001),
|
| 242 |
# loss='sparse_categorical_crossentropy')
|
| 243 |
# model.load_weights('./pretrained_model.h5')
|
| 244 |
-
model_gradcam = keras.models.load_model('./
|
| 245 |
|
| 246 |
preprocessed_input = load_image(img_path)
|
| 247 |
predictions = model_gradcam.predict(preprocessed_input)
|
|
@@ -456,40 +456,38 @@ if uploaded_file is not None:
|
|
| 456 |
redirect_button("https://new-ohif-viewer-k7c3gdlxua-et.a.run.app/")
|
| 457 |
|
| 458 |
with col2:
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
input_image = np.expand_dims(input_image, axis=0).astype(np.float32) # Expand dimensions and convert to float32
|
| 469 |
-
pred_bbox, pred_label, pred_label_confidence = predict(model, input_image)
|
| 470 |
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
|
| 491 |
-
|
| 492 |
-
|
| 493 |
|
| 494 |
with col3:
|
| 495 |
if st.button('Generate Grad-CAM'):
|
|
|
|
| 241 |
# model_gradcam.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.0001),
|
| 242 |
# loss='sparse_categorical_crossentropy')
|
| 243 |
# model.load_weights('./pretrained_model.h5')
|
| 244 |
+
model_gradcam = keras.models.load_model('./model_renamed.h5')
|
| 245 |
|
| 246 |
preprocessed_input = load_image(img_path)
|
| 247 |
predictions = model_gradcam.predict(preprocessed_input)
|
|
|
|
| 456 |
redirect_button("https://new-ohif-viewer-k7c3gdlxua-et.a.run.app/")
|
| 457 |
|
| 458 |
with col2:
|
| 459 |
+
image = cv2.imdecode(file_bytes, 1)
|
| 460 |
+
if st.button('Auto Detect'):
|
| 461 |
+
st.write("Processing...")
|
| 462 |
+
# input_image = preprocess_image(image)
|
| 463 |
+
# input_image = enhancement_type
|
| 464 |
+
input_image = cv2.resize(enhanced_image, (W, H)) # Resize the enhanced image to the required input size
|
| 465 |
+
input_image = (input_image - 127.5) / 127.5 # Normalize to [-1, +1]
|
| 466 |
+
input_image = np.expand_dims(input_image, axis=0).astype(np.float32) # Expand dimensions and convert to float32
|
| 467 |
+
pred_bbox, pred_label, pred_label_confidence = predict(model, input_image)
|
|
|
|
|
|
|
| 468 |
|
| 469 |
+
# Updated label mapping based on the dataset
|
| 470 |
+
label_mapping = {
|
| 471 |
+
0: 'Atelectasis',
|
| 472 |
+
1: 'Cardiomegaly',
|
| 473 |
+
2: 'Effusion',
|
| 474 |
+
3: 'Infiltrate',
|
| 475 |
+
4: 'Mass',
|
| 476 |
+
5: 'Nodule',
|
| 477 |
+
6: 'Pneumonia',
|
| 478 |
+
7: 'Pneumothorax'
|
| 479 |
+
}
|
| 480 |
|
| 481 |
+
if pred_label_confidence < 0.2:
|
| 482 |
+
st.write("May not detect a disease.")
|
| 483 |
+
else:
|
| 484 |
+
pred_label_name = label_mapping[pred_label]
|
| 485 |
+
st.write(f"Prediction Label: {pred_label_name}")
|
| 486 |
+
st.write(f"Prediction Bounding Box: {pred_bbox}")
|
| 487 |
+
st.write(f"Prediction Confidence: {pred_label_confidence:.2f}")
|
| 488 |
|
| 489 |
+
output_image = draw_bbox(image.copy(), pred_bbox)
|
| 490 |
+
st.image(output_image, caption='Detected Image.', use_column_width=True)
|
| 491 |
|
| 492 |
with col3:
|
| 493 |
if st.button('Generate Grad-CAM'):
|