def _make_body(self, inputs, in_transfers, training): channels, res_blocks, num_trans_blocks = self._get_structure_info( 'body') output_blocks = [inputs] for idx, objects in enumerate(zip(channels, res_blocks, num_trans_blocks, in_transfers)): filters, blocks, trans_blocks, in_transfer = objects k = get_filters(inputs, self.data_format) // filters dilation = 2 ** idx inputs = bottleneck_block( inputs, filters, blocks, 1, training, 'UP', 'body_bottleneck_block_' + str(idx), self.data_format, k=k, dilation=dilation) inputs = up_sample(inputs, self.data_format) trans_filters = get_filters(in_transfer, self.data_format) in_transfer = bottleneck_block( in_transfer, trans_filters, trans_blocks, 1, training, 'NORM', 'body_in_transfer_' + str(idx), self.data_format, k=1, dilation=1) if self.data_format == 'channels_first': inputs = tf.concat( values=[inputs, in_transfer], axis=1, name='body_block_' + str(idx)) else: inputs = tf.concat( values=[inputs, in_transfer], axis=3, name='body_block_' + str(idx)) output_blocks.append(inputs) return output_blocks
def _make_score_feats(self, inputs, training): in_filters = get_filters(inputs, self.data_format) inputs = batch_norm_relu(inputs, training, self.data_format) inputs = conv2d_fixed_padding(inputs, in_filters // 2, kernel_size=1, strides=1, data_format=self.data_format) inputs = batch_norm_relu(inputs, training, self.data_format) # 1056 inputs = conv2d_fixed_padding(inputs, 512, kernel_size=3, strides=2, data_format=self.data_format) inputs = batch_norm_relu(inputs, training, self.data_format) # 512 inputs = conv2d_fixed_padding(inputs, 128, kernel_size=1, strides=1, data_format=self.data_format) inputs = batch_norm_relu(inputs, training, self.data_format) inputs = conv2d_fixed_padding(inputs, 128, kernel_size=3, strides=1, data_format=self.data_format) inputs = batch_norm_relu(inputs, training, self.data_format) inputs = conv2d_fixed_padding(inputs, 32, kernel_size=2, strides=2, data_format=self.data_format) inputs = batch_norm_relu(inputs, training, self.data_format) inputs = tf.reshape(inputs, [-1, 2 * 2 * 32]) fc1 = tf.add(tf.matmul(inputs, variable(128, 32)), bias([32])) fc1 = tf.nn.relu(fc1) fc3 = tf.add(tf.matmul(fc1, variable(32, 6)), bias([6])) # inputs = squeeze(inputs, self.data_format) # # inputs = tf.layers.dense(inputs, units=6, use_bias=True) return tf.identity(fc3, 'final_dense')
def _make_se_score_feats(self, inputs, out_filters, training): in_filters = get_filters(inputs, self.data_format) inputs = batch_norm_relu(inputs, training, self.data_format) inputs = conv2d_fixed_padding(inputs, in_filters // 2, kernel_size=1, strides=1, data_format=self.data_format) inputs = batch_norm_relu(inputs, training, self.data_format) inputs = conv2d_fixed_padding(inputs, out_filters, kernel_size=1, strides=1, data_format=self.data_format) return inputs
def _make_se_block(self, inputs, training): in_filters = get_filters(inputs, self.data_format)# 512 blocks = self.res_blocks['se'] scale_channels = self.channels['se'] se_ratio = self.se_ratio score_feats = self._make_se_score_feats( inputs, in_filters * 2, training) scales = get_scale(score_feats, se_ratio,scale_channels, training, self.data_format) outputs = bottleneck_block(inputs, in_filters, blocks, strides=1,training=training, mode='NORM', name=None, data_format=self.data_format, k=1, dilation=1) * scales + scales return tf.identity(outputs, 'se_block')
def _make_score_feats(self, inputs, training): in_filters = get_filters(inputs, self.data_format) inputs = batch_norm_relu(inputs, training, self.data_format) inputs = conv2d_fixed_padding(inputs, in_filters // 2, kernel_size=1, strides=1, data_format=self.data_format) inputs = batch_norm_relu(inputs, training, self.data_format) inputs = squeeze(inputs, self.data_format) inputs = tf.layers.dense(inputs, units=self.num_classes, use_bias=True) return tf.identity(inputs, 'final_dense')