Exemple #1
0
    def inference(self, input_layer, reuse, is_training, name, print_shape=True):
        """Forward propagation of computational graph."""
        # Check input layer dimensions
        assert input_layer.shape[1] == self.length
        assert input_layer.shape[2] == self.channels

        # Define a scope for reusing the variables
        with tf.variable_scope(name, reuse=reuse):

            # Set variables
            kernel_size = 3
            conv_filts = 128
            res_filts = 128
            skip_filts = 128
            skips = list()

            # Print shape
            print_output_shape(layer_name='input', net=input_layer, print_shape=print_shape)

            """Block Series 1"""
            # --- Layer 1 (Convolution) ------------------------------------------------------------------------------ #

            # Set name
            layer_name = 'layer_1'

            # Set layer scope
            with tf.variable_scope(layer_name):

                # Convolution
                net = conv_layer(input_layer=input_layer, kernel_size=kernel_size, strides=1, dilation_rate=1,
                                 filters=res_filts, padding='SAME', activation=None, use_bias=False,
                                 name=layer_name + '_conv', seed=self.seed)

            # Print shape
            print_output_shape(layer_name=layer_name, net=net, print_shape=print_shape)

            # --- Layer 2 (Convolution) ------------------------------------------------------------------------------ #

            # Set name
            layer_name = 'layer_2'

            # Compute block
            outputs = self._residual_block(input_layer=net, kernel_size=kernel_size, layer_name=layer_name,
                                           conv_filts=conv_filts, res_filts=res_filts, skip_filts=skip_filts,
                                           dilation_rate=2, res=True, skip=True)

            # Collect skip
            skips.append(outputs['skip'])

            # Print shape
            print_output_shape(layer_name=layer_name + '_res', net=outputs['res'], print_shape=print_shape)
            print_output_shape(layer_name=layer_name + '_skip', net=outputs['skip'], print_shape=print_shape)

            # --- Layer 3 (Convolution) ------------------------------------------------------------------------------ #

            # Set name
            layer_name = 'layer_3'

            # Compute block
            outputs = self._residual_block(input_layer=outputs['res'], kernel_size=kernel_size, layer_name=layer_name,
                                           conv_filts=conv_filts, res_filts=res_filts, skip_filts=skip_filts,
                                           dilation_rate=4, res=True, skip=True)

            # Collect skip
            skips.append(outputs['skip'])

            # Print shape
            print_output_shape(layer_name=layer_name + '_res', net=outputs['res'], print_shape=print_shape)
            print_output_shape(layer_name=layer_name + '_skip', net=outputs['skip'], print_shape=print_shape)

            # --- Layer 4 (Convolution) ------------------------------------------------------------------------------ #

            # Set name
            layer_name = 'layer_4'

            # Compute block
            outputs = self._residual_block(input_layer=outputs['res'], kernel_size=kernel_size, layer_name=layer_name,
                                           conv_filts=conv_filts, res_filts=res_filts, skip_filts=skip_filts,
                                           dilation_rate=8, res=True, skip=True)

            # Collect skip
            skips.append(outputs['skip'])

            # Print shape
            print_output_shape(layer_name=layer_name + '_res', net=outputs['res'], print_shape=print_shape)
            print_output_shape(layer_name=layer_name + '_skip', net=outputs['skip'], print_shape=print_shape)

            # --- Layer 5 (Convolution) ------------------------------------------------------------------------------ #

            # Set name
            layer_name = 'layer_5'

            # Compute block
            outputs = self._residual_block(input_layer=outputs['res'], kernel_size=kernel_size, layer_name=layer_name,
                                           conv_filts=conv_filts, res_filts=res_filts, skip_filts=skip_filts,
                                           dilation_rate=16, res=True, skip=True)

            # Collect skip
            skips.append(outputs['skip'])

            # Print shape
            print_output_shape(layer_name=layer_name + '_res', net=outputs['res'], print_shape=print_shape)
            print_output_shape(layer_name=layer_name + '_skip', net=outputs['skip'], print_shape=print_shape)

            # --- Layer 6 (Convolution) ------------------------------------------------------------------------------ #

            # Set name
            layer_name = 'layer_6'

            # Compute block
            outputs = self._residual_block(input_layer=outputs['res'], kernel_size=kernel_size, layer_name=layer_name,
                                           conv_filts=conv_filts, res_filts=res_filts, skip_filts=skip_filts,
                                           dilation_rate=32, res=True, skip=True)

            # Collect skip
            skips.append(outputs['skip'])

            # Print shape
            print_output_shape(layer_name=layer_name + '_res', net=outputs['res'], print_shape=print_shape)
            print_output_shape(layer_name=layer_name + '_skip', net=outputs['skip'], print_shape=print_shape)

            # --- Layer 7 (Convolution) ------------------------------------------------------------------------------ #

            # Set name
            layer_name = 'layer_7'

            # Compute block
            outputs = self._residual_block(input_layer=outputs['res'], kernel_size=kernel_size, layer_name=layer_name,
                                           conv_filts=conv_filts, res_filts=res_filts, skip_filts=skip_filts,
                                           dilation_rate=64, res=True, skip=True)

            # Collect skip
            skips.append(outputs['skip'])

            # Print shape
            print_output_shape(layer_name=layer_name + '_res', net=outputs['res'], print_shape=print_shape)
            print_output_shape(layer_name=layer_name + '_skip', net=outputs['skip'], print_shape=print_shape)

            # --- Layer 8 (Convolution) ------------------------------------------------------------------------------ #

            # Set name
            layer_name = 'layer_8'

            # Compute block
            outputs = self._residual_block(input_layer=outputs['res'], kernel_size=kernel_size, layer_name=layer_name,
                                           conv_filts=conv_filts, res_filts=res_filts, skip_filts=skip_filts,
                                           dilation_rate=128, res=True, skip=True)

            # Collect skip
            skips.append(outputs['skip'])

            # Print shape
            print_output_shape(layer_name=layer_name + '_res', net=outputs['res'], print_shape=print_shape)
            print_output_shape(layer_name=layer_name + '_skip', net=outputs['skip'], print_shape=print_shape)

            # --- Layer 9 (Convolution) ------------------------------------------------------------------------------ #

            # Set name
            layer_name = 'layer_9'

            # Compute block
            outputs = self._residual_block(input_layer=outputs['res'], kernel_size=kernel_size, layer_name=layer_name,
                                           conv_filts=conv_filts, res_filts=res_filts, skip_filts=skip_filts,
                                           dilation_rate=256, res=True, skip=True)

            # Collect skip
            skips.append(outputs['skip'])

            # Print shape
            print_output_shape(layer_name=layer_name + '_res', net=outputs['res'], print_shape=print_shape)
            print_output_shape(layer_name=layer_name + '_skip', net=outputs['skip'], print_shape=print_shape)

            # --- Layer 10 (Convolution) ----------------------------------------------------------------------------- #

            # Set name
            layer_name = 'layer_10'

            # Compute block
            outputs = self._residual_block(input_layer=outputs['res'], kernel_size=kernel_size, layer_name=layer_name,
                                           conv_filts=conv_filts, res_filts=res_filts, skip_filts=skip_filts,
                                           dilation_rate=512, res=False, skip=True)

            # Collect skip
            skips.append(outputs['skip'])

            # Print shape
            print_output_shape(layer_name=layer_name + '_skip', net=outputs['skip'], print_shape=print_shape)

            # Add all skips to res output
            with tf.variable_scope('skips'):
                output = tf.add_n(inputs=skips, name='add_skips')

            # Print shape
            print_output_shape(layer_name='output_skip_addition', net=output, print_shape=print_shape)

            # Activation
            with tf.variable_scope('relu') as scope:
                output = tf.nn.relu(output, name=scope.name)

            # Dropout
            output = dropout_layer(input_layer=output, drop_rate=0.3, seed=self.seed,
                                   training=is_training, name='dropout1')

            # Convolution
            output = conv_layer(input_layer=output, kernel_size=kernel_size, strides=1, dilation_rate=1,
                                filters=256, padding='SAME', activation=tf.nn.relu, use_bias=False,
                                name='conv1', seed=self.seed)

            # Dropout
            output = dropout_layer(input_layer=output, drop_rate=0.3, seed=self.seed,
                                   training=is_training, name='dropout1')

            # Print shape
            print_output_shape(layer_name='output_conv1', net=output, print_shape=print_shape)

            # Convolution
            output = conv_layer(input_layer=output, kernel_size=kernel_size, strides=1, dilation_rate=1,
                                filters=512, padding='SAME', activation=tf.nn.relu, use_bias=False,
                                name='conv2', seed=self.seed)

            # Dropout
            output = dropout_layer(input_layer=output, drop_rate=0.3, seed=self.seed,
                                   training=is_training, name='dropout1')

            # Print shape
            print_output_shape(layer_name='output_conv2', net=output, print_shape=print_shape)

            """Network Output"""
            # --- Global Average Pooling Layer ----------------------------------------------------------------------- #

            # Set name
            layer_name = 'gap'

            # Set layer scope
            with tf.variable_scope(layer_name):

                # Reduce mean along dimension 1
                gap = tf.reduce_mean(input_tensor=output, axis=1)

            # Print shape
            print_output_shape(layer_name=layer_name, net=gap, print_shape=print_shape)

            # --- Softmax Layer -------------------------------------------------------------------------------------- #

            # Set name
            layer_name = 'logits'

            # Softmax activation
            logits = fc_layer(input_layer=gap, neurons=self.classes, activation=None, use_bias=False,
                              name=layer_name, seed=self.seed)

            # Print shape
            print_output_shape(layer_name=layer_name, net=logits, print_shape=print_shape)

            # Compute Class Activation Maps
            cams = self._get_cams(net=output, is_training=is_training)

        return logits, cams
Exemple #2
0
    def inference(self,
                  input_layer,
                  reuse,
                  is_training,
                  name,
                  print_shape=True):
        """Forward propagation of computational graph."""
        # Check input layer dimensions
        assert input_layer.shape[1] == self.length
        assert input_layer.shape[2] == self.channels

        # Define a scope for reusing the variables
        with tf.variable_scope(name, reuse=reuse):
            """Network Stem"""
            # --- Layer 1 (Convolution) ------------------------------------------------------------------------------ #

            # Set name
            layer_name = 'layer_1'

            # Set layer scope
            with tf.variable_scope(layer_name):
                # Convolution
                net = conv_layer(input_layer=input_layer,
                                 kernel_size=3,
                                 strides=2,
                                 dilation_rate=1,
                                 filters=32,
                                 padding='VALID',
                                 activation=tf.nn.relu,
                                 use_bias=True,
                                 name=layer_name + '_conv_ks3_dr1',
                                 seed=self.seed)

                # Batch Norm
                net = batch_norm_layer(input_layer=net,
                                       training=is_training,
                                       name=layer_name + '_batchnorm')

                # Dropout
                net = dropout_layer(input_layer=net,
                                    drop_rate=0.3,
                                    seed=self.seed,
                                    training=is_training,
                                    name=layer_name + '_dropout')

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=net,
                               print_shape=print_shape)

            # --- Layer 2 (Convolution) ------------------------------------------------------------------------------ #

            # Set name
            layer_name = 'layer_2'

            # Set layer scope
            with tf.variable_scope(layer_name):
                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=3,
                                 strides=1,
                                 dilation_rate=1,
                                 filters=32,
                                 padding='VALID',
                                 activation=tf.nn.relu,
                                 use_bias=True,
                                 name=layer_name + '_conv_ks3_dr1',
                                 seed=self.seed)

                # Batch Norm
                net = batch_norm_layer(input_layer=net,
                                       training=is_training,
                                       name=layer_name + '_batchnorm')

                # Dropout
                net = dropout_layer(input_layer=net,
                                    drop_rate=0.3,
                                    seed=self.seed,
                                    training=is_training,
                                    name=layer_name + '_dropout')

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=net,
                               print_shape=print_shape)

            # --- Layer 3 (Convolution) ------------------------------------------------------------------------------ #

            # Set name
            layer_name = 'layer_3'

            # Set layer scope
            with tf.variable_scope(layer_name):
                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=3,
                                 strides=1,
                                 dilation_rate=1,
                                 filters=64,
                                 padding='VALID',
                                 activation=tf.nn.relu,
                                 use_bias=True,
                                 name=layer_name + '_conv_ks3_dr1',
                                 seed=self.seed)

                # Batch Norm
                net = batch_norm_layer(input_layer=net,
                                       training=is_training,
                                       name=layer_name + '_batchnorm')

                # Dropout
                net = dropout_layer(input_layer=net,
                                    drop_rate=0.3,
                                    seed=self.seed,
                                    training=is_training,
                                    name=layer_name + '_dropout')

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=net,
                               print_shape=print_shape)

            # --- Layer 4 (Mixed - Convolution) ---------------------------------------------------------------------- #

            # Set name
            layer_name = 'layer_4'

            # Set layer scope
            with tf.variable_scope(layer_name):
                # Branch 0
                with tf.variable_scope('branch_0'):
                    # Max pool
                    branch_0 = max_pool_layer(input_layer=net,
                                              pool_size=3,
                                              strides=2,
                                              padding='VALID',
                                              name=layer_name +
                                              '_branch_0_a_maxpool_ps3')

                # Branch 1
                with tf.variable_scope('branch_1'):
                    # Convolution
                    branch_1 = conv_layer(input_layer=net,
                                          kernel_size=3,
                                          strides=2,
                                          dilation_rate=1,
                                          filters=96,
                                          padding='VALID',
                                          activation=tf.nn.relu,
                                          use_bias=True,
                                          name=layer_name +
                                          '_branch_1_a_conv_ks3_dr1',
                                          seed=self.seed)

                # Merge branches
                net = tf.concat(values=[branch_0, branch_1], axis=2)

                # Batch Norm
                net = batch_norm_layer(input_layer=net,
                                       training=is_training,
                                       name=layer_name + '_batchnorm')

                # Dropout
                net = dropout_layer(input_layer=net,
                                    drop_rate=0.3,
                                    seed=self.seed,
                                    training=is_training,
                                    name=layer_name + '_dropout')

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=net,
                               print_shape=print_shape)

            # --- Layer 5 (Mixed - Convolution) ---------------------------------------------------------------------- #

            # Set name
            layer_name = 'layer_5'

            # Set layer scope
            with tf.variable_scope(layer_name):
                # Branch 0
                with tf.variable_scope('branch_0'):
                    # Convolution
                    branch_0 = conv_layer(input_layer=net,
                                          kernel_size=1,
                                          strides=1,
                                          dilation_rate=1,
                                          filters=64,
                                          padding='SAME',
                                          activation=tf.nn.relu,
                                          use_bias=True,
                                          name=layer_name +
                                          '_branch_0_a_conv_ks1_dr1',
                                          seed=self.seed)
                    branch_0 = conv_layer(input_layer=branch_0,
                                          kernel_size=3,
                                          strides=1,
                                          dilation_rate=1,
                                          filters=96,
                                          padding='VALID',
                                          activation=tf.nn.relu,
                                          use_bias=True,
                                          name=layer_name +
                                          '_branch_0_b_conv_ks3_dr1',
                                          seed=self.seed)

                # Branch 1
                with tf.variable_scope('branch_1'):
                    # Convolution
                    branch_1 = conv_layer(input_layer=net,
                                          kernel_size=1,
                                          strides=1,
                                          dilation_rate=1,
                                          filters=64,
                                          padding='SAME',
                                          activation=tf.nn.relu,
                                          use_bias=True,
                                          name=layer_name +
                                          '_branch_1_a_conv_ks1_dr1',
                                          seed=self.seed)
                    branch_1 = conv_layer(input_layer=branch_1,
                                          kernel_size=7,
                                          strides=1,
                                          dilation_rate=2,
                                          filters=64,
                                          padding='SAME',
                                          activation=tf.nn.relu,
                                          use_bias=True,
                                          name=layer_name +
                                          '_branch_1_b_conv_ks7_dr2',
                                          seed=self.seed)
                    branch_1 = conv_layer(input_layer=branch_1,
                                          kernel_size=7,
                                          strides=1,
                                          dilation_rate=4,
                                          filters=64,
                                          padding='SAME',
                                          activation=tf.nn.relu,
                                          use_bias=True,
                                          name=layer_name +
                                          '_branch_1_c_conv_ks7_dr4',
                                          seed=self.seed)
                    branch_1 = conv_layer(input_layer=branch_1,
                                          kernel_size=3,
                                          strides=1,
                                          dilation_rate=1,
                                          filters=96,
                                          padding='VALID',
                                          activation=tf.nn.relu,
                                          use_bias=True,
                                          name=layer_name +
                                          '_branch_1_d_conv_ks3_dr1',
                                          seed=self.seed)

                # Merge branches
                net = tf.concat(values=[branch_0, branch_1], axis=2)

                # Batch Norm
                net = batch_norm_layer(input_layer=net,
                                       training=is_training,
                                       name=layer_name + '_batchnorm')

                # Dropout
                net = dropout_layer(input_layer=net,
                                    drop_rate=0.3,
                                    seed=self.seed,
                                    training=is_training,
                                    name=layer_name + '_dropout')

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=net,
                               print_shape=print_shape)

            # --- Layer 6 (Mixed - Convolution) ---------------------------------------------------------------------- #

            # Set name
            layer_name = 'layer_6'

            # Set layer scope
            with tf.variable_scope(layer_name):
                # Branch 0
                with tf.variable_scope('branch_0'):
                    # Convolution
                    branch_0 = conv_layer(input_layer=net,
                                          kernel_size=3,
                                          strides=2,
                                          dilation_rate=1,
                                          filters=192,
                                          padding='VALID',
                                          activation=tf.nn.relu,
                                          use_bias=True,
                                          name=layer_name +
                                          '_branch_0_a_conv_ks3_dr1',
                                          seed=self.seed)

                # Branch 1
                with tf.variable_scope('branch_1'):
                    # Max pool
                    branch_1 = max_pool_layer(input_layer=net,
                                              pool_size=3,
                                              strides=2,
                                              padding='VALID',
                                              name=layer_name +
                                              '_branch_0_a_maxpool_ps3')

                # Merge branches
                net = tf.concat(values=[branch_0, branch_1], axis=2)

                # Batch Norm
                net = batch_norm_layer(input_layer=net,
                                       training=is_training,
                                       name=layer_name + '_batchnorm')

                # Dropout
                net = dropout_layer(input_layer=net,
                                    drop_rate=0.3,
                                    seed=self.seed,
                                    training=is_training,
                                    name=layer_name + '_dropout')

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=net,
                               print_shape=print_shape)
            """Inception-A (V4)"""
            # Set number of Inception layers and previous layer
            num_layers = 2
            previous_layer = 6

            for layer_id in np.arange(num_layers) + (previous_layer + 1):

                # Set name
                layer_name = 'layer_{}'.format(layer_id)

                # Set layer scope
                with tf.variable_scope(layer_name):
                    # Inception-A (V4)
                    net = self._inception_a(inputs=net, layer_name=layer_name)

                    # Batch Norm
                    net = batch_norm_layer(input_layer=net,
                                           training=is_training,
                                           name=layer_name + '_batchnorm')

                # Print shape
                print_output_shape(layer_name=layer_name,
                                   net=net,
                                   print_shape=print_shape)
            """Reduction-A"""
            """Inception-B"""
            """Reduction-B"""
            """Inception-C"""
            """Network Output"""
            # --- Global Average Pooling Layer ----------------------------------------------------------------------- #

            # Set layer scope
            with tf.variable_scope('GAP'):
                # Reduce mean along dimension 1
                gap = tf.reduce_mean(input_tensor=net, axis=1)

            # --- Softmax Layer -------------------------------------------------------------------------------------- #

            # Softmax activation
            logits = fc_layer(input_layer=gap,
                              neurons=self.classes,
                              activation=None,
                              use_bias=False,
                              name='logits',
                              seed=self.seed)

        return logits, net
Exemple #3
0
    def inference(self,
                  input_layer,
                  reuse,
                  is_training,
                  name,
                  print_shape=True):
        """Forward propagation of computational graph."""
        # Check input layer dimensions
        assert input_layer.shape[1] == self.length
        assert input_layer.shape[2] == self.channels

        # Define a scope for reusing the variables
        with tf.variable_scope(name, reuse=reuse):
            """Block Series 1"""
            # --- Layer 1 (Convolution) ------------------------------------------------------------------------------ #

            # Set name
            layer_name = 'layer_1'

            # Set layer scope
            with tf.variable_scope(layer_name):

                # Convolution
                net = conv_layer(input_layer=input_layer,
                                 kernel_size=3,
                                 strides=1,
                                 dilation_rate=1,
                                 filters=128,
                                 padding='SAME',
                                 activation=None,
                                 use_bias=False,
                                 name=layer_name + '_conv_ks3_dr1',
                                 seed=self.seed)

                # Max pool
                net = max_pool_layer(input_layer=net,
                                     pool_size=3,
                                     strides=2,
                                     padding='SAME',
                                     name=layer_name + '_maxpool_ps3')

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=net,
                               print_shape=print_shape)

            # --- Layer 2 (Convolution) ------------------------------------------------------------------------------ #

            # Set name
            layer_name = 'layer_2'

            # Set identity
            identity = tf.identity(input=net, name=layer_name + '_identity')

            # Set layer scope
            with tf.variable_scope(layer_name):

                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=3,
                                 strides=1,
                                 dilation_rate=2,
                                 filters=128,
                                 padding='SAME',
                                 activation=None,
                                 use_bias=False,
                                 name=layer_name + '_conv_ks3_dr2',
                                 seed=self.seed)

                # Tanh activation
                tanh = tf.nn.tanh(net, name='tanh')

                # Sigmoid activation
                sigmoid = tf.nn.sigmoid(net, name='sigmoid')

                # Combine activations
                net = tf.multiply(tanh, sigmoid, name='activation_gate')

                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=1,
                                 strides=1,
                                 dilation_rate=1,
                                 filters=128,
                                 padding='SAME',
                                 activation=None,
                                 use_bias=False,
                                 name=layer_name + '_conv_ks1_dr1',
                                 seed=self.seed)

            # Add identity
            net = tf.add(net, identity, name=layer_name + '_identity_add')

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=net,
                               print_shape=print_shape)

            # --- Layer 3 (Convolution) ------------------------------------------------------------------------------ #

            # Set name
            layer_name = 'layer_3'

            # Set identity
            identity = tf.identity(input=net, name=layer_name + '_identity')

            # Set layer scope
            with tf.variable_scope(layer_name):

                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=3,
                                 strides=1,
                                 dilation_rate=4,
                                 filters=128,
                                 padding='SAME',
                                 activation=None,
                                 use_bias=False,
                                 name=layer_name + '_conv_ks3_dr4',
                                 seed=self.seed)

                # Tanh activation
                tanh = tf.nn.tanh(net, name='tanh')

                # Sigmoid activation
                sigmoid = tf.nn.sigmoid(net, name='sigmoid')

                # Combine activations
                net = tf.multiply(tanh, sigmoid, name='activation_gate')

                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=1,
                                 strides=1,
                                 dilation_rate=1,
                                 filters=128,
                                 padding='SAME',
                                 activation=None,
                                 use_bias=False,
                                 name=layer_name + '_conv_ks1_dr1',
                                 seed=self.seed)

            # Add identity
            net = tf.add(net, identity, name=layer_name + '_identity_add')

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=net,
                               print_shape=print_shape)

            # --- Layer 4 (Convolution) ------------------------------------------------------------------------------ #

            # Set name
            layer_name = 'layer_4'

            # Set identity
            identity = tf.identity(input=net, name=layer_name + '_identity')

            # Set layer scope
            with tf.variable_scope(layer_name):

                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=3,
                                 strides=1,
                                 dilation_rate=8,
                                 filters=128,
                                 padding='SAME',
                                 activation=None,
                                 use_bias=False,
                                 name=layer_name + '_conv_ks3_dr8',
                                 seed=self.seed)

                # Tanh activation
                tanh = tf.nn.tanh(net, name='tanh')

                # Sigmoid activation
                sigmoid = tf.nn.sigmoid(net, name='sigmoid')

                # Combine activations
                net = tf.multiply(tanh, sigmoid, name='activation_gate')

                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=1,
                                 strides=1,
                                 dilation_rate=1,
                                 filters=128,
                                 padding='SAME',
                                 activation=None,
                                 use_bias=False,
                                 name=layer_name + '_conv_ks1_dr1',
                                 seed=self.seed)

            # Add identity
            net = tf.add(net, identity, name=layer_name + '_identity_add')

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=net,
                               print_shape=print_shape)

            # --- Layer 5 (Convolution) ------------------------------------------------------------------------------ #

            # Set name
            layer_name = 'layer_5'

            # Set identity
            identity = tf.identity(input=net, name=layer_name + '_identity')

            # Set layer scope
            with tf.variable_scope(layer_name):

                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=3,
                                 strides=1,
                                 dilation_rate=16,
                                 filters=128,
                                 padding='SAME',
                                 activation=None,
                                 use_bias=False,
                                 name=layer_name + '_conv_ks3_dr16',
                                 seed=self.seed)

                # Tanh activation
                tanh = tf.nn.tanh(net, name='tanh')

                # Sigmoid activation
                sigmoid = tf.nn.sigmoid(net, name='sigmoid')

                # Combine activations
                net = tf.multiply(tanh, sigmoid, name='activation_gate')

                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=1,
                                 strides=1,
                                 dilation_rate=1,
                                 filters=128,
                                 padding='SAME',
                                 activation=None,
                                 use_bias=False,
                                 name=layer_name + '_conv_ks1_dr1',
                                 seed=self.seed)

            # Add identity
            net = tf.add(net, identity, name=layer_name + '_identity_add')

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=net,
                               print_shape=print_shape)

            # --- Layer 6 (Convolution) ------------------------------------------------------------------------------ #

            # Set name
            layer_name = 'layer_6'

            # Set identity
            identity = tf.identity(input=net, name=layer_name + '_identity')

            # Set layer scope
            with tf.variable_scope(layer_name):

                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=3,
                                 strides=1,
                                 dilation_rate=32,
                                 filters=128,
                                 padding='SAME',
                                 activation=None,
                                 use_bias=False,
                                 name=layer_name + '_conv_ks3_dr32',
                                 seed=self.seed)

                # Tanh activation
                tanh = tf.nn.tanh(net, name='tanh')

                # Sigmoid activation
                sigmoid = tf.nn.sigmoid(net, name='sigmoid')

                # Combine activations
                net = tf.multiply(tanh, sigmoid, name='activation_gate')

                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=1,
                                 strides=1,
                                 dilation_rate=1,
                                 filters=128,
                                 padding='SAME',
                                 activation=None,
                                 use_bias=False,
                                 name=layer_name + '_conv_ks1_dr1',
                                 seed=self.seed)

            # Add identity
            net = tf.add(net, identity, name=layer_name + '_identity_add')

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=net,
                               print_shape=print_shape)

            # --- Layer 7 (Convolution) ------------------------------------------------------------------------------ #

            # Set name
            layer_name = 'layer_7'

            # Set identity
            identity = tf.identity(input=net, name=layer_name + '_identity')

            # Set layer scope
            with tf.variable_scope(layer_name):

                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=3,
                                 strides=1,
                                 dilation_rate=64,
                                 filters=128,
                                 padding='SAME',
                                 activation=None,
                                 use_bias=False,
                                 name=layer_name + '_conv_ks3_dr64',
                                 seed=self.seed)

                # Tanh activation
                tanh = tf.nn.tanh(net, name='tanh')

                # Sigmoid activation
                sigmoid = tf.nn.sigmoid(net, name='sigmoid')

                # Combine activations
                net = tf.multiply(tanh, sigmoid, name='activation_gate')

                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=1,
                                 strides=1,
                                 dilation_rate=1,
                                 filters=128,
                                 padding='SAME',
                                 activation=None,
                                 use_bias=False,
                                 name=layer_name + '_conv_ks1_dr1',
                                 seed=self.seed)

            # Add identity
            net = tf.add(net, identity, name=layer_name + '_identity_add')

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=net,
                               print_shape=print_shape)

            # --- Layer 8 (Convolution) ------------------------------------------------------------------------------ #

            # Set name
            layer_name = 'layer_8'

            # Set identity
            identity = tf.identity(input=net, name=layer_name + '_identity')

            # Set layer scope
            with tf.variable_scope(layer_name):

                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=3,
                                 strides=1,
                                 dilation_rate=128,
                                 filters=128,
                                 padding='SAME',
                                 activation=None,
                                 use_bias=False,
                                 name=layer_name + '_conv_ks3_dr128',
                                 seed=self.seed)

                # Tanh activation
                tanh = tf.nn.tanh(net, name='tanh')

                # Sigmoid activation
                sigmoid = tf.nn.sigmoid(net, name='sigmoid')

                # Combine activations
                net = tf.multiply(tanh, sigmoid, name='activation_gate')

                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=1,
                                 strides=1,
                                 dilation_rate=1,
                                 filters=128,
                                 padding='SAME',
                                 activation=None,
                                 use_bias=False,
                                 name=layer_name + '_conv_ks1_dr1',
                                 seed=self.seed)

            # Add identity
            net = tf.add(net, identity, name=layer_name + '_identity_add')

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=net,
                               print_shape=print_shape)

            # --- Layer 9 (Convolution) ------------------------------------------------------------------------------ #

            # Set name
            layer_name = 'layer_9'

            # Set identity
            identity = tf.identity(input=net, name=layer_name + '_identity')

            # Set layer scope
            with tf.variable_scope(layer_name):

                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=3,
                                 strides=1,
                                 dilation_rate=256,
                                 filters=128,
                                 padding='SAME',
                                 activation=None,
                                 use_bias=False,
                                 name=layer_name + '_conv_ks3_dr256',
                                 seed=self.seed)

                # Tanh activation
                tanh = tf.nn.tanh(net, name='tanh')

                # Sigmoid activation
                sigmoid = tf.nn.sigmoid(net, name='sigmoid')

                # Combine activations
                net = tf.multiply(tanh, sigmoid, name='activation_gate')

                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=1,
                                 strides=1,
                                 dilation_rate=1,
                                 filters=128,
                                 padding='SAME',
                                 activation=None,
                                 use_bias=False,
                                 name=layer_name + '_conv_ks1_dr1',
                                 seed=self.seed)

            # Add identity
            net = tf.add(net, identity, name=layer_name + '_identity_add')

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=net,
                               print_shape=print_shape)

            # --- Layer 10 (Convolution) ----------------------------------------------------------------------------- #

            # Set name
            layer_name = 'layer_10'

            # Set identity
            identity = tf.identity(input=net, name=layer_name + '_identity')

            # Set layer scope
            with tf.variable_scope(layer_name):

                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=3,
                                 strides=1,
                                 dilation_rate=512,
                                 filters=128,
                                 padding='SAME',
                                 activation=None,
                                 use_bias=False,
                                 name=layer_name + '_conv_ks3_dr512',
                                 seed=self.seed)

                # Tanh activation
                tanh = tf.nn.tanh(net, name='tanh')

                # Sigmoid activation
                sigmoid = tf.nn.sigmoid(net, name='sigmoid')

                # Combine activations
                net = tf.multiply(tanh, sigmoid, name='activation_gate')

                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=1,
                                 strides=1,
                                 dilation_rate=1,
                                 filters=128,
                                 padding='SAME',
                                 activation=None,
                                 use_bias=False,
                                 name=layer_name + '_conv_ks1_dr1',
                                 seed=self.seed)

            # Add identity
            net = tf.add(net, identity, name=layer_name + '_identity_add')

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=net,
                               print_shape=print_shape)

            # --- Layer 11 (Convolution) ----------------------------------------------------------------------------- #

            # Set name
            layer_name = 'layer_11'

            # Set identity
            identity = tf.identity(input=net, name=layer_name + '_identity')

            # Set layer scope
            with tf.variable_scope(layer_name):
                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=3,
                                 strides=1,
                                 dilation_rate=1,
                                 filters=128,
                                 padding='SAME',
                                 activation=None,
                                 use_bias=False,
                                 name=layer_name + '_conv_ks3_dr128',
                                 seed=self.seed)

                # Tanh activation
                tanh = tf.nn.tanh(net, name='tanh')

                # Sigmoid activation
                sigmoid = tf.nn.sigmoid(net, name='sigmoid')

                # Combine activations
                net = tf.multiply(tanh, sigmoid, name='activation_gate')

                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=1,
                                 strides=1,
                                 dilation_rate=1,
                                 filters=128,
                                 padding='SAME',
                                 activation=None,
                                 use_bias=False,
                                 name=layer_name + '_conv_ks1_dr1',
                                 seed=self.seed)

            # Add identity
            net = tf.add(net, identity, name=layer_name + '_identity_add')

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=net,
                               print_shape=print_shape)

            # --- Layer 12 (Convolution) ----------------------------------------------------------------------------- #

            # Set name
            layer_name = 'layer_12'

            # Set identity
            identity = tf.identity(input=net, name=layer_name + '_identity')

            # Set layer scope
            with tf.variable_scope(layer_name):
                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=3,
                                 strides=1,
                                 dilation_rate=2,
                                 filters=128,
                                 padding='SAME',
                                 activation=None,
                                 use_bias=False,
                                 name=layer_name + '_conv_ks3_dr128',
                                 seed=self.seed)

                # Tanh activation
                tanh = tf.nn.tanh(net, name='tanh')

                # Sigmoid activation
                sigmoid = tf.nn.sigmoid(net, name='sigmoid')

                # Combine activations
                net = tf.multiply(tanh, sigmoid, name='activation_gate')

                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=1,
                                 strides=1,
                                 dilation_rate=1,
                                 filters=128,
                                 padding='SAME',
                                 activation=None,
                                 use_bias=False,
                                 name=layer_name + '_conv_ks1_dr1',
                                 seed=self.seed)

            # Add identity
            net = tf.add(net, identity, name=layer_name + '_identity_add')

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=net,
                               print_shape=print_shape)

            # --- Layer 13 (Convolution) ----------------------------------------------------------------------------- #

            # Set name
            layer_name = 'layer_13'

            # Set identity
            identity = tf.identity(input=net, name=layer_name + '_identity')

            # Set layer scope
            with tf.variable_scope(layer_name):
                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=3,
                                 strides=1,
                                 dilation_rate=4,
                                 filters=128,
                                 padding='SAME',
                                 activation=None,
                                 use_bias=False,
                                 name=layer_name + '_conv_ks3_dr128',
                                 seed=self.seed)

                # Tanh activation
                tanh = tf.nn.tanh(net, name='tanh')

                # Sigmoid activation
                sigmoid = tf.nn.sigmoid(net, name='sigmoid')

                # Combine activations
                net = tf.multiply(tanh, sigmoid, name='activation_gate')

                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=1,
                                 strides=1,
                                 dilation_rate=1,
                                 filters=128,
                                 padding='SAME',
                                 activation=None,
                                 use_bias=False,
                                 name=layer_name + '_conv_ks1_dr1',
                                 seed=self.seed)

            # Add identity
            net = tf.add(net, identity, name=layer_name + '_identity_add')

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=net,
                               print_shape=print_shape)

            # --- Layer 14 (Convolution) ----------------------------------------------------------------------------- #

            # Set name
            layer_name = 'layer_14'

            # Set identity
            identity = tf.identity(input=net, name=layer_name + '_identity')

            # Set layer scope
            with tf.variable_scope(layer_name):
                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=3,
                                 strides=1,
                                 dilation_rate=8,
                                 filters=128,
                                 padding='SAME',
                                 activation=None,
                                 use_bias=False,
                                 name=layer_name + '_conv_ks3_dr128',
                                 seed=self.seed)

                # Tanh activation
                tanh = tf.nn.tanh(net, name='tanh')

                # Sigmoid activation
                sigmoid = tf.nn.sigmoid(net, name='sigmoid')

                # Combine activations
                net = tf.multiply(tanh, sigmoid, name='activation_gate')

                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=1,
                                 strides=1,
                                 dilation_rate=1,
                                 filters=128,
                                 padding='SAME',
                                 activation=None,
                                 use_bias=False,
                                 name=layer_name + '_conv_ks1_dr1',
                                 seed=self.seed)

            # Add identity
            net = tf.add(net, identity, name=layer_name + '_identity_add')

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=net,
                               print_shape=print_shape)

            # --- Layer 15 (Convolution) ----------------------------------------------------------------------------- #

            # Set name
            layer_name = 'layer_15'

            # Set identity
            identity = tf.identity(input=net, name=layer_name + '_identity')

            # Set layer scope
            with tf.variable_scope(layer_name):
                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=3,
                                 strides=1,
                                 dilation_rate=16,
                                 filters=128,
                                 padding='SAME',
                                 activation=None,
                                 use_bias=False,
                                 name=layer_name + '_conv_ks3_dr128',
                                 seed=self.seed)

                # Tanh activation
                tanh = tf.nn.tanh(net, name='tanh')

                # Sigmoid activation
                sigmoid = tf.nn.sigmoid(net, name='sigmoid')

                # Combine activations
                net = tf.multiply(tanh, sigmoid, name='activation_gate')

                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=1,
                                 strides=1,
                                 dilation_rate=1,
                                 filters=128,
                                 padding='SAME',
                                 activation=None,
                                 use_bias=False,
                                 name=layer_name + '_conv_ks1_dr1',
                                 seed=self.seed)

            # Add identity
            net = tf.add(net, identity, name=layer_name + '_identity_add')

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=net,
                               print_shape=print_shape)

            # --- Layer 16 (Convolution) ----------------------------------------------------------------------------- #

            # Set name
            layer_name = 'layer_16'

            # Set identity
            identity = tf.identity(input=net, name=layer_name + '_identity')

            # Set layer scope
            with tf.variable_scope(layer_name):
                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=3,
                                 strides=1,
                                 dilation_rate=32,
                                 filters=128,
                                 padding='SAME',
                                 activation=None,
                                 use_bias=False,
                                 name=layer_name + '_conv_ks3_dr128',
                                 seed=self.seed)

                # Tanh activation
                tanh = tf.nn.tanh(net, name='tanh')

                # Sigmoid activation
                sigmoid = tf.nn.sigmoid(net, name='sigmoid')

                # Combine activations
                net = tf.multiply(tanh, sigmoid, name='activation_gate')

                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=1,
                                 strides=1,
                                 dilation_rate=1,
                                 filters=128,
                                 padding='SAME',
                                 activation=None,
                                 use_bias=False,
                                 name=layer_name + '_conv_ks1_dr1',
                                 seed=self.seed)

            # Add identity
            net = tf.add(net, identity, name=layer_name + '_identity_add')

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=net,
                               print_shape=print_shape)
            """Network Output"""
            # --- Global Average Pooling Layer ----------------------------------------------------------------------- #

            # Set name
            layer_name = 'gap'

            # Set layer scope
            with tf.variable_scope(layer_name):
                # Reduce mean along dimension 1
                gap = tf.reduce_mean(input_tensor=net, axis=1)

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=gap,
                               print_shape=print_shape)

            # --- Softmax Layer -------------------------------------------------------------------------------------- #

            # Set name
            layer_name = 'logits'

            # Softmax activation
            logits = fc_layer(input_layer=gap,
                              neurons=self.classes,
                              activation=None,
                              use_bias=False,
                              name=layer_name,
                              seed=self.seed)

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=logits,
                               print_shape=print_shape)

            # Compute Class Activation Maps
            cams = self._get_cams(net=net, is_training=is_training)

        return logits, net, cams
Exemple #4
0
    def inference(self,
                  input_layer,
                  reuse,
                  is_training,
                  name,
                  print_shape=True):
        """Forward propagation of computational graph."""
        # Check input layer dimensions
        assert input_layer.shape[1] == self.length
        assert input_layer.shape[2] == self.channels

        # Define a scope for reusing the variables
        with tf.variable_scope(name, reuse=reuse):
            """Block Series 1"""
            # --- Layer 1 (Convolution) ------------------------------------------------------------------------------ #

            # Set name
            layer_name = 'layer_1'

            # Set layer scope
            with tf.variable_scope(layer_name):
                # Convolution
                net = conv_layer(input_layer=input_layer,
                                 kernel_size=24,
                                 strides=1,
                                 dilation_rate=1,
                                 filters=128,
                                 padding='SAME',
                                 activation=tf.nn.relu,
                                 use_bias=True,
                                 name=layer_name + '_conv_ks3_dr1',
                                 seed=self.seed)

                # Max pool
                net = max_pool_layer(input_layer=net,
                                     pool_size=3,
                                     strides=2,
                                     padding='SAME',
                                     name=layer_name + '_maxpool_ps3')

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=net,
                               print_shape=print_shape)

            # --- Layer 2 (Convolution) ------------------------------------------------------------------------------ #

            # Set name
            layer_name = 'layer_2'

            # Set layer scope
            with tf.variable_scope(layer_name):
                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=12,
                                 strides=1,
                                 dilation_rate=2,
                                 filters=128,
                                 padding='SAME',
                                 activation=tf.nn.relu,
                                 use_bias=True,
                                 name=layer_name + '_conv_ks3_dr1',
                                 seed=self.seed)

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=net,
                               print_shape=print_shape)

            # --- Layer 3 (Convolution) ------------------------------------------------------------------------------ #

            # Set name
            layer_name = 'layer_3'

            # Set layer scope
            with tf.variable_scope(layer_name):
                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=12,
                                 strides=1,
                                 dilation_rate=1,
                                 filters=128,
                                 padding='SAME',
                                 activation=tf.nn.relu,
                                 use_bias=True,
                                 name=layer_name + '_conv_ks3_dr1',
                                 seed=self.seed)

                # Max pool
                net = max_pool_layer(input_layer=net,
                                     pool_size=3,
                                     strides=2,
                                     padding='SAME',
                                     name=layer_name + '_maxpool_ps3')

                # Dropout
                net = dropout_layer(input_layer=net,
                                    drop_rate=0.3,
                                    seed=self.seed,
                                    training=is_training,
                                    name=layer_name + '_dropout')

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=net,
                               print_shape=print_shape)
            """Block Series 2"""
            # --- Layer 4 (Convolution) ------------------------------------------------------------------------------ #

            # Set name
            layer_name = 'layer_4'

            # Set layer scope
            with tf.variable_scope(layer_name):
                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=6,
                                 strides=1,
                                 dilation_rate=4,
                                 filters=256,
                                 padding='SAME',
                                 activation=tf.nn.relu,
                                 use_bias=True,
                                 name=layer_name + '_conv_ks3_dr1',
                                 seed=self.seed)

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=net,
                               print_shape=print_shape)

            # --- Layer 5 (Convolution) ------------------------------------------------------------------------------ #

            # Set name
            layer_name = 'layer_5'

            # Set layer scope
            with tf.variable_scope(layer_name):
                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=6,
                                 strides=1,
                                 dilation_rate=1,
                                 filters=256,
                                 padding='SAME',
                                 activation=tf.nn.relu,
                                 use_bias=True,
                                 name=layer_name + '_conv_ks3_dr1',
                                 seed=self.seed)

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=net,
                               print_shape=print_shape)

            # --- Layer 6 (Convolution) ------------------------------------------------------------------------------ #

            # Set name
            layer_name = 'layer_6'

            # Set layer scope
            with tf.variable_scope(layer_name):
                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=6,
                                 strides=1,
                                 dilation_rate=8,
                                 filters=256,
                                 padding='SAME',
                                 activation=tf.nn.relu,
                                 use_bias=True,
                                 name=layer_name + '_conv_ks3_dr1',
                                 seed=self.seed)

                # Max pool
                net = max_pool_layer(input_layer=net,
                                     pool_size=3,
                                     strides=2,
                                     padding='SAME',
                                     name=layer_name + '_maxpool_ps3')

                # Dropout
                net = dropout_layer(input_layer=net,
                                    drop_rate=0.3,
                                    seed=self.seed,
                                    training=is_training,
                                    name=layer_name + '_dropout')

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=net,
                               print_shape=print_shape)
            """Block Series 3"""
            # --- Layer 7 (Convolution) ------------------------------------------------------------------------------ #

            # Set name
            layer_name = 'layer_7'

            # Set layer scope
            with tf.variable_scope(layer_name):
                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=3,
                                 strides=1,
                                 dilation_rate=1,
                                 filters=512,
                                 padding='SAME',
                                 activation=tf.nn.relu,
                                 use_bias=True,
                                 name=layer_name + '_conv_ks3_dr1',
                                 seed=self.seed)

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=net,
                               print_shape=print_shape)

            # --- Layer 8 (Convolution) ------------------------------------------------------------------------------ #

            # Set name
            layer_name = 'layer_8'

            # Set layer scope
            with tf.variable_scope(layer_name):
                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=3,
                                 strides=1,
                                 dilation_rate=16,
                                 filters=512,
                                 padding='SAME',
                                 activation=tf.nn.relu,
                                 use_bias=True,
                                 name=layer_name + '_conv_ks3_dr1',
                                 seed=self.seed)

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=net,
                               print_shape=print_shape)

            # --- Layer 9 (Convolution) ------------------------------------------------------------------------------ #

            # Set name
            layer_name = 'layer_9'

            # Set layer scope
            with tf.variable_scope(layer_name):
                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=3,
                                 strides=1,
                                 dilation_rate=1,
                                 filters=512,
                                 padding='SAME',
                                 activation=tf.nn.relu,
                                 use_bias=True,
                                 name=layer_name + '_conv_ks3_dr1',
                                 seed=self.seed)

                # Dropout
                net = dropout_layer(input_layer=net,
                                    drop_rate=0.3,
                                    seed=self.seed,
                                    training=is_training,
                                    name=layer_name + '_dropout')

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=net,
                               print_shape=print_shape)
            """Block Series 4"""
            # --- Layer 10 (Convolution) ----------------------------------------------------------------------------- #

            # Set name
            layer_name = 'layer_10'

            # Set layer scope
            with tf.variable_scope(layer_name):
                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=3,
                                 strides=1,
                                 dilation_rate=32,
                                 filters=512,
                                 padding='SAME',
                                 activation=tf.nn.relu,
                                 use_bias=True,
                                 name=layer_name + '_conv_ks3_dr1',
                                 seed=self.seed)

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=net,
                               print_shape=print_shape)

            # --- Layer 11 (Convolution) ----------------------------------------------------------------------------- #

            # Set name
            layer_name = 'layer_11'

            # Set layer scope
            with tf.variable_scope(layer_name):
                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=3,
                                 strides=1,
                                 dilation_rate=1,
                                 filters=512,
                                 padding='SAME',
                                 activation=tf.nn.relu,
                                 use_bias=True,
                                 name=layer_name + '_conv_ks3_dr1',
                                 seed=self.seed)

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=net,
                               print_shape=print_shape)

            # --- Layer 12 (Convolution) ----------------------------------------------------------------------------- #

            # Set name
            layer_name = 'layer_12'

            # Set layer scope
            with tf.variable_scope(layer_name):
                # Convolution
                net = conv_layer(input_layer=net,
                                 kernel_size=3,
                                 strides=1,
                                 dilation_rate=64,
                                 filters=512,
                                 padding='SAME',
                                 activation=tf.nn.relu,
                                 use_bias=True,
                                 name=layer_name + '_conv_ks3_dr1',
                                 seed=self.seed)

                # Dropout
                net = dropout_layer(input_layer=net,
                                    drop_rate=0.3,
                                    seed=self.seed,
                                    training=is_training,
                                    name=layer_name + '_dropout')

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=net,
                               print_shape=print_shape)
            """Network Output"""
            # --- Global Average Pooling Layer ----------------------------------------------------------------------- #

            # Set name
            layer_name = 'gap'

            # Set layer scope
            with tf.variable_scope(layer_name):
                # Reduce mean along dimension 1
                gap = tf.reduce_mean(input_tensor=net, axis=1)

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=gap,
                               print_shape=print_shape)

            # --- Softmax Layer -------------------------------------------------------------------------------------- #

            # Set name
            layer_name = 'logits'

            # Softmax activation
            logits = fc_layer(input_layer=gap,
                              neurons=self.classes,
                              activation=None,
                              use_bias=False,
                              name=layer_name,
                              seed=self.seed)

            # Print shape
            print_output_shape(layer_name=layer_name,
                               net=logits,
                               print_shape=print_shape)

            # Compute Class Activation Maps
            cams = self._get_cams(net=net, is_training=is_training)

        return logits, net, cams