-
Notifications
You must be signed in to change notification settings - Fork 170
/
fcn8s_mobilenet.py
69 lines (57 loc) · 3.3 KB
/
fcn8s_mobilenet.py
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from models.basic.basic_model import BasicModel
from models.encoders.VGG import VGG16
from models.encoders.mobilenet import MobileNet
from layers.convolution import conv2d_transpose, conv2d, atrous_conv2d
import tensorflow as tf
class FCN8sMobileNet(BasicModel):
"""
FCN8s with MobileNet as an encoder Model Architecture
"""
def __init__(self, args):
super().__init__(args)
# init encoder
self.encoder = None
# init network layers
def build(self):
print("\nBuilding the MODEL...")
self.init_input()
self.init_network()
self.init_output()
self.init_train()
self.init_summaries()
print("The Model is built successfully\n")
def init_network(self):
"""
Building the Network here
:return:
"""
# Init MobileNet as an encoder
self.encoder = MobileNet(x_input=self.x_pl, num_classes=self.params.num_classes,
pretrained_path=self.args.pretrained_path,
train_flag=self.is_training, width_multipler=1.0, weight_decay=self.args.weight_decay)
# Build Encoding part
self.encoder.build()
# Build Decoding part
with tf.name_scope('upscore_2s'):
self.upscore2 = conv2d_transpose('upscore2', x=self.encoder.score_fr,
output_shape=self.encoder.feed1.shape.as_list()[0:3] + [
self.params.num_classes], batchnorm_enabled= self.args.batchnorm_enabled, is_training=self.is_training,
kernel_size=(4, 4), stride=(2, 2), l2_strength=self.encoder.wd)
self.score_feed1 = conv2d('score_feed1', x=self.encoder.feed1, batchnorm_enabled= self.args.batchnorm_enabled, is_training=self.is_training,
num_filters=self.params.num_classes, kernel_size=(1, 1),
l2_strength=self.encoder.wd)
self.fuse_feed1 = tf.add(self.score_feed1, self.upscore2)
with tf.name_scope('upscore_4s'):
self.upscore4 = conv2d_transpose('upscore4', x=self.fuse_feed1, batchnorm_enabled= self.args.batchnorm_enabled, is_training=self.is_training,
output_shape=self.encoder.feed2.shape.as_list()[0:3] + [
self.params.num_classes],
kernel_size=(4, 4), stride=(2, 2), l2_strength=self.encoder.wd)
self.score_feed2 = conv2d('score_feed2', x=self.encoder.feed2, batchnorm_enabled= self.args.batchnorm_enabled, is_training=self.is_training,
num_filters=self.params.num_classes, kernel_size=(1, 1),
l2_strength=self.encoder.wd)
self.fuse_feed2 = tf.add(self.score_feed2, self.upscore4)
with tf.name_scope('upscore_8s'):
self.upscore8 = conv2d_transpose('upscore8', x=self.fuse_feed2,
output_shape=self.x_pl.shape.as_list()[0:3] + [self.params.num_classes],
kernel_size=(16, 16), stride=(8, 8), l2_strength=self.encoder.wd)
self.logits = self.upscore8