MohamedSherif commited on
Commit
0f017dd
1 Parent(s): 427a239

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -0
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ import cv2
4
+ from skimage.transform import resize
5
+ from tensorflow.keras.models import Sequential, load_model
6
+ from tensorflow.keras.layers import Conv2D, MaxPool2D, Dropout, Dense, Flatten, BatchNormalization
7
+
8
+ class SkinCancer :
9
+ def __init__ (self):
10
+ self.model = self.load_model()
11
+
12
+ def build_model (self) :
13
+ model = Sequential()
14
+ model.add(Conv2D(filters = 128, kernel_size = (4,4), input_shape = (64, 64, 3), activation = 'relu'))
15
+ model.add(MaxPool2D(pool_size = (4,4)))
16
+ model.add(Conv2D(filters = 64, kernel_size = (2,2), activation = 'relu'))
17
+ model.add(MaxPool2D(pool_size = (2,2)))
18
+ model.add(BatchNormalization())
19
+ #model.add(GlobalAveragePooling2D())
20
+
21
+ model.add(Flatten())
22
+ model.add(Dense(128, activation = 'relu'))
23
+ model.add(Dropout(0.1))
24
+ model.add(Dense(2, activation = 'sigmoid')) # sigmoid is better for binary classification
25
+
26
+ #model.summary()
27
+ return model
28
+
29
+ def load_model(self):
30
+ model = self.build_model()
31
+ model = load_model("Normal_skin_cancer_model.h5")
32
+ return model
33
+
34
+ def preprocess_image(self,img):
35
+ img = cv2.resize(img, (64,64))
36
+ img = img.reshape(1,64,64,3)
37
+ return img
38
+
39
+ def predict(self,img):
40
+ real_labels = ["benign", "malignant"]
41
+ img = self.preprocess_image(img)
42
+ res = np.argmax(self.model.predict(img))
43
+ return real_labels[res]
44
+
45
+ def Test(img):
46
+ model_new = SkinCancer()
47
+ res = model_new.predict(img)
48
+ return res
49
+ #interface
50
+ interface = gr.Interface(fn = Test,
51
+ inputs = gr.inputs.Image(shape=(200,200)),
52
+ outputs=["text"],
53
+ title="Skin Cancer detection")
54
+ interface.launch()