Federico Galatolo commited on
Commit
6e5a614
1 Parent(s): e6c8bda

missing fix gradcam without file

Browse files
Files changed (1) hide show
  1. app.py +17 -26
app.py CHANGED
@@ -106,24 +106,6 @@ def load_model():
106
  cfg=cfg
107
  )
108
 
109
-
110
-
111
-
112
- def compute_similarities(features, database):
113
- similarities = dict()
114
- dist_fn = getattr(spatial.distance, DISTANCE)
115
- for file_name, elems in database.items():
116
- for elem in elems:
117
- similarities[file_name] = dict(
118
- dist=dist_fn(elem["features"], features),
119
- file_name=file_name,
120
- box=elem["roi"],
121
- type=elem["type"]
122
- )
123
- similarities = OrderedDict(sorted(similarities.items(), key=lambda e: e[1]["dist"]))
124
- return similarities
125
-
126
-
127
  def draw_box(file_name, box, type, model, resize_input=False):
128
  height, width, channels = img.shape
129
 
@@ -225,15 +207,24 @@ MODEL = "./models/model.pth"
225
  PCA_MODEL = "./models/pca.pkl"
226
  FEATURES_DATABASE = "./assets/features/features.json"
227
 
228
- DISTANCE = "cosine"
229
- TH = 0.5
 
 
 
 
 
 
 
230
 
231
  state = st.empty()
232
- tooltip = st.empty()
233
 
234
- state.write("Loading model...")
235
- model = load_model()
 
236
 
237
- img = cv2.imread(FILE)
238
- img = cv2.resize(img, (800, 800))
239
- explain(img, model)
 
 
 
106
  cfg=cfg
107
  )
108
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  def draw_box(file_name, box, type, model, resize_input=False):
110
  height, width, channels = img.shape
111
 
 
207
  PCA_MODEL = "./models/pca.pkl"
208
  FEATURES_DATABASE = "./assets/features/features.json"
209
 
210
+ st.header("Explainable oral lesion detection")
211
+ st.markdown("""Demo for the paper [Explainable diagnosis of oral cancer via deep learning and case-based reasoning](https://mlpi.ing.unipi.it/doctoralai/)
212
+
213
+ Upload an image using the form below and click on "Process"
214
+ """)
215
+ FILE = st.file_uploader("Image", type=["jpg", "jpeg", "png"])
216
+ TH = st.slider("Threshold", min_value=0.0, max_value=1.0, value=0.5)
217
+
218
+ process = st.button("Process")
219
 
220
  state = st.empty()
 
221
 
222
+ if process:
223
+ state.write("Loading model...")
224
+ model = load_model()
225
 
226
+ nparr = np.fromstring(FILE.getvalue(), np.uint8)
227
+ img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
228
+ #img = cv2.imread(FILE)
229
+ img = cv2.resize(img, (800, 800))
230
+ explain(img, model)