def forward(self, inputs): """ Forward process Parameters ---------- inputs: Input tensor """ # encoder process outputs = inputs encoders = [] for i, filters in enumerate(self.block_filters): first_blocks = i == 0 outputs = self.build_res_blocks(outputs, filters, self.block_res_nums[i], first_blocks) if i != len(self.block_filters) - 1: encoders.append(outputs) outputs = maxpool(outputs, pool_size=2) # decoder process encoder_num = len(encoders) for k, encoder in enumerate(encoders[::-1]): i = encoder_num - k - 1 first_blocks = i == 0 filters = int(encoder.get_shape()[-1]) outputs = conv_bn_relu(outputs, filters, 3, 1, 1, use_bn=self.use_bn, training=self.training) outputs = upsample(outputs, 2, self.interpolation_type) outputs = concat([encoder, outputs]) outputs = self.build_res_blocks(outputs, filters, self.block_res_nums[i], first_blocks) outputs = conv(outputs, self.config.get('output_channel')) outputs = softmax(outputs) return outputs
def build_one_dense_block(self, inputs, growth_rate): """ Build one dense conv block Parameters ---------- inputs: Input tensor growth_rate: number of channel growth for each dense block """ if self.config.get('bottleneck'): shrinked_filters = self.config.get('bottleneck_factor') * \ growth_rate branch = self.conv_block(inputs, shrinked_filters, ksize=1) branch = self.conv_block(branch, growth_rate, ksize=3) else: branch = self.conv_block(inputs, growth_rate, ksize=3) if self.config.get('dropout_rate'): branch = dropout(branch, self.config.get('dropout_rate')) outputs = concat([inputs, branch]) return outputs