Suweeraya commited on
Commit
273f442
·
1 Parent(s): 70fc611

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -1
app.py CHANGED
@@ -1,9 +1,46 @@
1
  import gradio as gr
2
  from PIL import Image
3
 
4
- size = 128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  model = build_model(input_shape=(size, size, 1))
 
6
  model.load_weights('BreastCancerSegmentation.h5')
 
7
 
8
  def preprocess_image(image, size=128):
9
  image = cv2.resize(image, (size, size))
 
1
  import gradio as gr
2
  from PIL import Image
3
 
4
+ def conv_block(input, num_filters):
5
+ conv = Conv2D(num_filters, (3, 3), activation="relu", padding="same", kernel_initializer='he_normal')(input)
6
+ conv = Conv2D(num_filters, (3, 3), activation="relu", padding="same", kernel_initializer='he_normal')(conv)
7
+ return conv
8
+
9
+ def encoder_block(input, num_filters):
10
+ conv = conv_block(input, num_filters)
11
+ pool = MaxPooling2D((2, 2))(conv)
12
+ return conv, pool
13
+
14
+ def decoder_block(input, skip_features, num_filters):
15
+ uconv = Conv2DTranspose(num_filters, (2, 2), strides=2, padding="same")(input)
16
+ con = concatenate([uconv, skip_features])
17
+ conv = conv_block(con, num_filters)
18
+ return conv
19
+
20
+ def build_model(input_shape):
21
+ input_layer = Input(input_shape)
22
+
23
+ s1, p1 = encoder_block(input_layer, 64)
24
+ s2, p2 = encoder_block(p1, 128)
25
+ s3, p3 = encoder_block(p2, 256)
26
+ s4, p4 = encoder_block(p3, 512)
27
+
28
+ b1 = conv_block(p4, 1024)
29
+
30
+ d1 = decoder_block(b1, s4, 512)
31
+ d2 = decoder_block(d1, s3, 256)
32
+ d3 = decoder_block(d2, s2, 128)
33
+ d4 = decoder_block(d3, s1, 64)
34
+
35
+ output_layer = Conv2D(1, 1, padding="same", activation="sigmoid")(d4)
36
+
37
+ model = Model(input_layer, output_layer, name="U-Net")
38
+ return model
39
+
40
  model = build_model(input_shape=(size, size, 1))
41
+ model.compile(loss="binary_crossentropy", optimizer="Adam", metrics=["accuracy"])
42
  model.load_weights('BreastCancerSegmentation.h5')
43
+ size = 128
44
 
45
  def preprocess_image(image, size=128):
46
  image = cv2.resize(image, (size, size))