File size: 1,843 Bytes
0f017dd
 
 
 
 
 
 
 
 
 
e70ceb6
0f017dd
1c92103
0f017dd
 
 
 
 
 
 
69073a0
0f017dd
a86a87c
0f017dd
 
 
 
 
 
 
 
b289100
 
0f017dd
 
 
028fd87
0f017dd
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import gradio as gr
import numpy as np
from skimage.transform import resize
from tensorflow.keras.models import Sequential, load_model
from tensorflow.keras.layers import Conv2D, MaxPool2D, Dropout, Dense, Flatten, BatchNormalization

class SkinCancer :
    def __init__ (self):
        self.model = self.load_model()

    def build_model (self) :
        model = Sequential()
        model.add(Conv2D(filters = 128, kernel_size = (4,4), input_shape = (32, 32, 3), activation = 'relu'))
        model.add(MaxPool2D(pool_size = (4,4)))
        model.add(Conv2D(filters = 64, kernel_size = (2,2), activation = 'relu'))
        model.add(MaxPool2D(pool_size = (2,2)))
        model.add(BatchNormalization())
        #model.add(GlobalAveragePooling2D())
        model.add(Flatten())
        model.add(Dense(128, activation = 'relu'))
        model.add(Dropout(0.2))
        model.add(Dense(2, activation = 'sigmoid')) # sigmoid is better for binary classification
        #model.summary()
        return model

    def load_model(self):
        model = self.build_model()
        model = load_model("Normal_skin_cancer_model.h5")
        return model

    def preprocess_image(self,img):
        img = resize(img, (32,32))
        img = img.reshape(1,32,32,3)
        return img

    def predict(self,img):
        real_labels = ["benign", "malignant"]
        img = self.preprocess_image(img)
        res = np.argmax(self.model.predict(img))
        return real_labels[res]

def Test(img):
    model_new = SkinCancer()
    res = model_new.predict(img)
    return res
#interface
interface = gr.Interface(fn = Test,
                        inputs = gr.inputs.Image(shape=(200,200)),
                        outputs=["text"],
                        title="Skin Cancer detection")
interface.launch()