Kalbe-x-Bangkit commited on
Commit
d0e2a94
·
verified ·
1 Parent(s): 1259972

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -8
app.py CHANGED
@@ -33,8 +33,8 @@ enhancement_type = st.sidebar.selectbox(
33
  ["Invert", "High Pass Filter", "Unsharp Masking", "Histogram Equalization", "CLAHE"]
34
  )
35
 
36
- # H = 224
37
- # W = 224
38
 
39
  @st.cache_resource
40
  def load_model_detection():
@@ -52,14 +52,14 @@ def load_model_detection():
52
  )
53
  return model
54
 
55
- # def preprocess_image(image):
56
  # """ Preprocess the image to the required size and normalization. """
57
  # W = 320
58
  # H = 320
59
- # image = cv2.resize(image, (W, H))
60
- # image = (image - 127.5) / 127.5 # Normalize to [-1, +1]
61
- # image = np.expand_dims(image, axis=0).astype(np.float32)
62
- # return image
63
 
64
 
65
 
@@ -79,7 +79,20 @@ model_detection = load_model_detection()
79
 
80
  @st.cache_resource
81
  def load_gradcam_model():
82
- model = keras.models.load_model('./model_renamed.h5')
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  return model
84
 
85
 
 
33
  ["Invert", "High Pass Filter", "Unsharp Masking", "Histogram Equalization", "CLAHE"]
34
  )
35
 
36
+ H = 224
37
+ W = 224
38
 
39
  @st.cache_resource
40
  def load_model_detection():
 
52
  )
53
  return model
54
 
55
+ def preprocess_image(image):
56
  # """ Preprocess the image to the required size and normalization. """
57
  # W = 320
58
  # H = 320
59
+ image = cv2.resize(image, (W, H))
60
+ image = (image - 127.5) / 127.5 # Normalize to [-1, +1]
61
+ image = np.expand_dims(image, axis=0).astype(np.float32)
62
+ return image
63
 
64
 
65
 
 
79
 
80
  @st.cache_resource
81
  def load_gradcam_model():
82
+ base_model = DenseNet121(weights="./densenet.hdf5",
83
+ include_top=False)
84
+ x = base_model.output
85
+
86
+ # add a global spatial average pooling layer
87
+ x = GlobalAveragePooling2D()(x)
88
+
89
+ # and a logistic layer
90
+ predictions = Dense(len(labels), activation="sigmoid")(x)
91
+
92
+ model = Model(inputs=base_model.input, outputs=predictions)
93
+ model.compile(optimizer='adam', loss="categorical_crossentropy")
94
+ model.load_weights("./model_renamed.h5")
95
+
96
  return model
97
 
98