File size: 1,795 Bytes
d1d16da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c24222d
d1d16da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
52
53
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 = (64, 64, 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.1))
        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, (64,64))
        img = img.reshape(1,64,64,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()