hasibzunair commited on
Commit
76fcfbc
·
1 Parent(s): ef3a966
Files changed (2) hide show
  1. app.py +54 -0
  2. requirements.txt +8 -0
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ os.environ['CUDA_VISIBLE_DEVICES'] = '-1'
3
+ import tensorflow as tf
4
+ import keras.backend.tensorflow_backend as tb
5
+ tb._SYMBOLIC_SCOPE.value = True
6
+ import numpy as np
7
+ import gradio as gr
8
+ import cv2
9
+ from PIL import Image
10
+ from tensorflow.keras.models import load_model
11
+
12
+ # Get model weights
13
+ #os.system("wget https://github.com/hasibzunair/adversarial-lesions/releases/latest/download/MelaNet.h5")
14
+
15
+ # Load model
16
+ model = None
17
+ model = load_model("MelaNet.h5", compile=False)
18
+ model.summary()
19
+
20
+ examples = None #["./examples/covid.jpeg", "./examples/normal.jpeg"]
21
+ labels = ["Benign", "Malignant"]
22
+
23
+ # Helpers
24
+ def preprocess_image(img_array):
25
+ # Normalize to [0,1]
26
+ img_array = img_array.astype('float32')
27
+ img_array /= 255
28
+ # Check that images are 2D arrays
29
+ if len(img_array.shape) > 2:
30
+ img_array = img_array[:, :, 0]
31
+ # Convert to 3-channel
32
+ img_array = np.stack((img_array, img_array, img_array), axis=-1)
33
+ # Convert to array
34
+ img_array = cv2.resize(img_array, (224, 224))
35
+ return img_array
36
+
37
+
38
+ def inference(image):
39
+ img = preprocess_image(img)
40
+ preds = model.predict(img)
41
+ img = np.expand_dims(img, 0)
42
+ # Predict
43
+ preds = model.predict(image)[0]
44
+ labels_probs = {labels[i]: float(preds[i]) for i, _ in enumerate(labels)}
45
+ return labels_probs
46
+
47
+ gr.Interface(
48
+ fn=inference,
49
+ title="Benign or Malignant",
50
+ description = "Predict if this image has benign or malignant symptoms",
51
+ inputs="image",
52
+ outputs="label",
53
+ examples=examples,
54
+ ).launch(debug=True, enable_queue=True)
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ scipy==1.4.1
2
+ tensorflow==2.2.0
3
+ keras==2.3.1
4
+ h5py==2.10.0
5
+ numpy==1.18.1
6
+ opencv-python-headless==4.2.0.32
7
+ Pillow
8
+