Kalbe-x-Bangkit commited on
Commit
93641ab
1 Parent(s): 204cc82

Revise if detection.

Browse files
Files changed (1) hide show
  1. app.py +30 -32
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('./gradcam_model.h5')
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
- if uploaded_file is not None:
460
- file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
461
- image = cv2.imdecode(file_bytes, 1)
462
- if st.button('Auto Detect'):
463
- st.write("Processing...")
464
- # input_image = preprocess_image(image)
465
- # input_image = enhancement_type
466
- input_image = cv2.resize(enhanced_image, (W, H)) # Resize the enhanced image to the required input size
467
- input_image = (input_image - 127.5) / 127.5 # Normalize to [-1, +1]
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
- # Updated label mapping based on the dataset
472
- label_mapping = {
473
- 0: 'Atelectasis',
474
- 1: 'Cardiomegaly',
475
- 2: 'Effusion',
476
- 3: 'Infiltrate',
477
- 4: 'Mass',
478
- 5: 'Nodule',
479
- 6: 'Pneumonia',
480
- 7: 'Pneumothorax'
481
- }
482
 
483
- if pred_label_confidence < 0.2:
484
- st.write("May not detect a disease.")
485
- else:
486
- pred_label_name = label_mapping[pred_label]
487
- st.write(f"Prediction Label: {pred_label_name}")
488
- st.write(f"Prediction Bounding Box: {pred_bbox}")
489
- st.write(f"Prediction Confidence: {pred_label_confidence:.2f}")
490
 
491
- output_image = draw_bbox(image.copy(), pred_bbox)
492
- st.image(output_image, caption='Detected Image.', use_column_width=True)
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'):