main.py
def layers(vgg_layer3_out, vgg_layer4_out, vgg_layer7_out, num_classes):
    """
    Create the layers for a fully convolutional network.  Build skip-layers using the vgg layers.
    :param vgg_layer3_out: TF Tensor for VGG Layer 3 output
    :param vgg_layer4_out: TF Tensor for VGG Layer 4 output
    :param vgg_layer7_out: TF Tensor for VGG Layer 7 output
    :param num_classes: Number of classes to classify
    :return: The Tensor for the last layer of output
    """    
    # Scale the pooling layers (as reccomended by Pierluigi Ferrari in his
    # project tips document):
    pool3_out_scaled = tf.multiply(vgg_layer3_out, 0.0001, name= "pool3_out_scaled")
    pool4_out_scaled = tf.multiply(vgg_layer4_out, 0.01, name="pool4_out_scaled")
                                              
    #1x1 Convolution, replaces "fully connected layer", reduces # of filters to num_classes
    conv1x1 = tf.layers.conv2d(inputs = vgg_layer7_out, \
                             filters = num_classes, \
                             kernel_size = 1, \
                             padding = 'same', \
                             kernel_regularizer = tf.contrib.layers.l2_regularizer(L2_REG), \
                             kernel_initializer = tf.random_normal_initializer(stddev = STD_DEV));       
    
    # Implement Transpose Convolutional Layers to  increase the height and width dimensions of
    # the 4D input tensor from VGG.

    # Transpose Convolution Layer 1, T1:
    conv_T1= tf.layers.conv2d_transpose(inputs = conv1x1, \
                                        filters = num_classes, \
                                        kernel_size = 4 , \
                                        strides = (2,2), \
                                        padding = 'same', \
                                        kernel_regularizer = tf.contrib.layers.l2_regularizer(L2_REG), \
                                        kernel_initializer = tf.random_normal_initializer(stddev = STD_DEV));
    
    # Adjust size of the skip connection layer using 1x1 convolutions:
    pool4_out_scaled_adj = tf.layers.conv2d(inputs = pool4_out_scaled, \
                                            filters = num_classes, \
                                            kernel_size = 1, \
                                            padding = 'same', \
                                            kernel_regularizer = tf.contrib.layers.l2_regularizer(L2_REG), \
                                            kernel_initializer = tf.random_normal_initializer(stddev = STD_DEV)); 
    #Add-in Skip Connection - conv_T1 with vgg layer 3
    T1 = tf.add(conv_T1,pool4_out_scaled_adj)
    
    # Transpose Convolution Layer 2, conv_T2:
    conv_T2 = tf.layers.conv2d_transpose(inputs = T1, \
                                         filters = num_classes, \
                                         kernel_size =  4 , \
                                         strides = (2,2), padding = 'same', \
                                         kernel_regularizer = tf.contrib.layers.l2_regularizer(L2_REG), \
                                         kernel_initializer = tf.random_normal_initializer(stddev = STD_DEV)); 
    

    # Adjust size of the skip connection layer using 1x1 convolutions:
    pool3_out_scaled_adj = tf.layers.conv2d(inputs = pool3_out_scaled, \
                                            filters = num_classes, \
                                            kernel_size = 1, \
                                            padding = 'same', \
                                            kernel_regularizer = tf.contrib.layers.l2_regularizer(L2_REG), \
                                            kernel_initializer = tf.random_normal_initializer(stddev = STD_DEV));   
    # Add-in Skip Connection - conv_T2 with vgg layer 4
    T2 = tf.add(conv_T2,pool3_out_scaled_adj)
    
    # Transpose Convolution Layer 2, conv_T2:
    output= tf.layers.conv2d_transpose(inputs = T2, \
                                       filters = num_classes, \
                                       kernel_size =  16, \
                                       strides = (8,8), padding = 'same', \
                                       kernel_regularizer = tf.contrib.layers.l2_regularizer(L2_REG), \
                                       kernel_initializer = tf.random_normal_initializer(stddev = STD_DEV)); 
    return output

    Create the layers for a fully convolutional network.  Build skip-layers using the vgg layers.
    :param vgg_layer3_out: TF Tensor for VGG Layer 3 output
    :param vgg_layer4_out: TF Tensor for VGG Layer 4 output
    :param vgg_layer7_out: TF Tensor for VGG Layer 7 output
    :param num_classes: Number of classes to classify
    :return: The Tensor for the last layer of output
    
Create the layers for a fully convolutional network.  Build skip-layers using the vgg layers.
Create the layers for a fully convolutional network . Build skip - layers using the vgg layers .
def layers(vgg_layer3_out, vgg_layer4_out, vgg_layer7_out, num_classes):
    pool3_out_scaled = tf.multiply(vgg_layer3_out, 0.0001, name= "pool3_out_scaled")
    pool4_out_scaled = tf.multiply(vgg_layer4_out, 0.01, name="pool4_out_scaled")
    conv1x1 = tf.layers.conv2d(inputs = vgg_layer7_out, \
                             filters = num_classes, \
                             kernel_size = 1, \
                             padding = 'same', \
                             kernel_regularizer = tf.contrib.layers.l2_regularizer(L2_REG), \
                             kernel_initializer = tf.random_normal_initializer(stddev = STD_DEV));       
    conv_T1= tf.layers.conv2d_transpose(inputs = conv1x1, \
                                        filters = num_classes, \
                                        kernel_size = 4 , \
                                        strides = (2,2), \
                                        padding = 'same', \
                                        kernel_regularizer = tf.contrib.layers.l2_regularizer(L2_REG), \
                                        kernel_initializer = tf.random_normal_initializer(stddev = STD_DEV));
    pool4_out_scaled_adj = tf.layers.conv2d(inputs = pool4_out_scaled, \
                                            filters = num_classes, \
                                            kernel_size = 1, \
                                            padding = 'same', \
                                            kernel_regularizer = tf.contrib.layers.l2_regularizer(L2_REG), \
                                            kernel_initializer = tf.random_normal_initializer(stddev = STD_DEV)); 
    T1 = tf.add(conv_T1,pool4_out_scaled_adj)
    conv_T2 = tf.layers.conv2d_transpose(inputs = T1, \
                                         filters = num_classes, \
                                         kernel_size =  4 , \
                                         strides = (2,2), padding = 'same', \
                                         kernel_regularizer = tf.contrib.layers.l2_regularizer(L2_REG), \
                                         kernel_initializer = tf.random_normal_initializer(stddev = STD_DEV)); 
    pool3_out_scaled_adj = tf.layers.conv2d(inputs = pool3_out_scaled, \
                                            filters = num_classes, \
                                            kernel_size = 1, \
                                            padding = 'same', \
                                            kernel_regularizer = tf.contrib.layers.l2_regularizer(L2_REG), \
                                            kernel_initializer = tf.random_normal_initializer(stddev = STD_DEV));   
    T2 = tf.add(conv_T2,pool3_out_scaled_adj)
    output= tf.layers.conv2d_transpose(inputs = T2, \
                                       filters = num_classes, \
                                       kernel_size =  16, \
                                       strides = (8,8), padding = 'same', \
                                       kernel_regularizer = tf.contrib.layers.l2_regularizer(L2_REG), \
                                       kernel_initializer = tf.random_normal_initializer(stddev = STD_DEV)); 
    return output
def layers ( vgg_layer3_out , vgg_layer4_out , vgg_layer7_out , num_classes ) : pool3_out_scaled = tf . multiply ( vgg_layer3_out , 0.0001 , name = "pool3_out_scaled" ) pool4_out_scaled = tf . multiply ( vgg_layer4_out , 0.01 , name = "pool4_out_scaled" ) conv1x1 = tf . layers . conv2d ( inputs = vgg_layer7_out , filters = num_classes , kernel_size = 1 , padding = 'same' , kernel_regularizer = tf . contrib . layers . l2_regularizer ( L2_REG ) , kernel_initializer = tf . random_normal_initializer ( stddev = STD_DEV ) ) ; conv_T1 = tf . layers . conv2d_transpose ( inputs = conv1x1 , filters = num_classes , kernel_size = 4 , strides = ( 2 , 2 ) , padding = 'same' , kernel_regularizer = tf . contrib . layers . l2_regularizer ( L2_REG ) , kernel_initializer = tf . random_normal_initializer ( stddev = STD_DEV ) ) ; pool4_out_scaled_adj = tf . layers . conv2d ( inputs = pool4_out_scaled , filters = num_classes , kernel_size = 1 , padding = 'same' , kernel_regularizer = tf . contrib . layers . l2_regularizer ( L2_REG ) , kernel_initializer = tf . random_normal_initializer ( stddev = STD_DEV ) ) ; T1 = tf . add ( conv_T1 , pool4_out_scaled_adj ) conv_T2 = tf . layers . conv2d_transpose ( inputs = T1 , filters = num_classes , kernel_size = 4 , strides = ( 2 , 2 ) , padding = 'same' , kernel_regularizer = tf . contrib . layers . l2_regularizer ( L2_REG ) , kernel_initializer = tf . random_normal_initializer ( stddev = STD_DEV ) ) ; pool3_out_scaled_adj = tf . layers . conv2d ( inputs = pool3_out_scaled , filters = num_classes , kernel_size = 1 , padding = 'same' , kernel_regularizer = tf . contrib . layers . l2_regularizer ( L2_REG ) , kernel_initializer = tf . random_normal_initializer ( stddev = STD_DEV ) ) ; T2 = tf . add ( conv_T2 , pool3_out_scaled_adj ) output = tf . layers . conv2d_transpose ( inputs = T2 , filters = num_classes , kernel_size = 16 , strides = ( 8 , 8 ) , padding = 'same' , kernel_regularizer = tf . contrib . layers . l2_regularizer ( L2_REG ) , kernel_initializer = tf . random_normal_initializer ( stddev = STD_DEV ) ) ; return output
Create the layers for a fully convolutional network.
Create the layers for a fully convolutional network .
"""
    Create the layers for a fully convolutional network.  Build skip-layers using the vgg layers.
    :param vgg_layer3_out: TF Tensor for VGG Layer 3 output
    :param vgg_layer4_out: TF Tensor for VGG Layer 4 output
    :param vgg_layer7_out: TF Tensor for VGG Layer 7 output
    :param num_classes: Number of classes to classify
    :return: The Tensor for the last layer of output
    """ # Scale the pooling layers (as reccomended by Pierluigi Ferrari in his # project tips document): #1x1 Convolution, replaces "fully connected layer", reduces # of filters to num_classes # Implement Transpose Convolutional Layers to  increase the height and width dimensions of # the 4D input tensor from VGG. # Transpose Convolution Layer 1, T1: # Adjust size of the skip connection layer using 1x1 convolutions: #Add-in Skip Connection - conv_T1 with vgg layer 3 # Transpose Convolution Layer 2, conv_T2: # Adjust size of the skip connection layer using 1x1 convolutions: # Add-in Skip Connection - conv_T2 with vgg layer 4 # Transpose Convolution Layer 2, conv_T2:
The Tensor for the last layer of output
The Tensor for the last layer of output
vgg_layer3_out
TF Tensor for VGG Layer 3 output
TF Tensor for VGG Layer 3 output
vgg_layer4_out
TF Tensor for VGG Layer 4 output
TF Tensor for VGG Layer 4 output
vgg_layer7_out
TF Tensor for VGG Layer 7 output
TF Tensor for VGG Layer 7 output
num_classes
Number of classes to classify
Number of classes to classify