示例#1
0
 def maxpoolLayer(self, size, stride=None, pad='SAME'):
     if stride == None:
         stride = size
     self.result = L.maxpooling(self.result,
                                size,
                                stride,
                                'maxpool_' + str(self.layernum),
                                pad=pad)
     self.inpsize = self.result.get_shape().as_list()
     return self.result
示例#2
0
def get_rpn_layers(c2,c3,c4,c5):
	P5 = L.conv2D(c5,1,256,'P5')
	P4 = L.upSampling(P5,2,'U5') + L.conv2D(c4,1,256,'P4')
	P3 = L.upSampling(P4,2,'U4') + L.conv2D(c3,1,256,'P3')
	P2 = L.upSampling(P3,2,'U3') + L.conv2D(c2,1,256,'P2')
	P2 = L.conv2D(P2,3,256,'P22')
	P3 = L.conv2D(P3,3,256,'P32')
	P4 = L.conv2D(P4,3,256,'P42')
	P5 = L.conv2D(P5,3,256,'P52')
	P6 = L.maxpooling(P5,1,2,'P6')
	return P2,P3,P4,P5,P6
示例#3
0
    def fcn_net(self, x, train=True):
        conv1 = conv2d(x, [3, 3, 3, 32], 'conv1')
        maxp1 = maxpooling(conv1)

        conv2 = conv2d(maxp1, [3, 3, 32, 32], 'conv2')
        maxp2 = maxpooling(conv2)

        conv3 = conv2d(maxp2, [3, 3, 32, 64], 'conv3')
        maxp3 = maxpooling(conv3)

        conv4 = conv2d(maxp3, [3, 3, 64, 64], 'conv4')
        maxp4 = maxpooling(conv4)

        conv5 = conv2d(maxp4, [3, 3, 64, 128], 'conv5')
        maxp5 = maxpooling(conv5)

        conv6 = conv2d(maxp5, [3, 3, 128, 128], 'conv6')
        maxp6 = maxpooling(conv6)

        conv7 = conv2d(maxp6, [3, 3, 128, 256], 'conv7')
        maxp7 = maxpooling(conv7)

        conv8 = conv2d(maxp7, [3, 3, 256, 256], 'conv8')
        maxp8 = maxpooling(conv8)

        conv9 = conv2d(maxp8, [3, 3, 256, 512], 'conv9')
        maxp9 = maxpooling(conv9)

        drop = tf.nn.dropout(maxp9, self.dropout)

        # 1x1 convolution + sigmoid activation
        net = conv2d(drop, [1, 1, 512, self.input_size * self.input_size],
                     'conv10',
                     activation='no')

        # squeeze the last two dimension in train
        if train:
            net = tf.squeeze(net, [1, 2], name="squeezed")

        return net
示例#4
0
    def u_net(self, x, layers=4, base_channel=64, train=True):
        ds_layers = {}
        ds_layer_shape = {}

        # down sample layers
        for layer in range(0, layers-1):
            f_channels = base_channel * (2**layer)
            layer_name = 'ds_{}'.format(layer)
            if layer == 0:
                x = conv2d(x, [3, 3, 3, f_channels], layer_name + '_1')
            else:
                x = conv2d(x, [3, 3, f_channels/2, f_channels], layer_name + '_1')

            x = conv2d(x, [3, 3, f_channels, f_channels], layer_name + '_2')
            ds_layers[layer] = x
            ds_layer_shape[layer] = tf.shape(x)

            x = maxpooling(x)

        # bottom layer
        f_channels = base_channel * (2**(layers-1))
        x = conv2d(x, [3, 3, f_channels/2, f_channels], 'bottom_1')
        x = conv2d(x, [3, 3, f_channels, f_channels], 'bottom_2')

        # up sample layers
        for layer in range(layers-2, -1, -1):
            f_channels = base_channel * (2**layer)
            layer_name = 'up_{}'.format(layer)
            x = deconv2d(x, [3, 3, f_channels, 2*f_channels], ds_layer_shape[layer], layer_name + '_deconv2d')

            # add the previous down sumple layer to the up sample layer
            x = concat(ds_layers[layer], x)

            x = conv2d(x, [3, 3, 2*f_channels, f_channels], layer_name + '_conv_1')
            x = conv2d(x, [3, 3, f_channels, f_channels], layer_name + '_conv_2')
            #if train:
            #    x = tf.nn.dropout(x, self.dropout)

        # add 1x1 convolution layer to change channel to one
        x = conv2d(x, [1, 1, base_channel, 1], 'conv_1x1', activation='no')

        logits = tf.squeeze(x, axis=3)

        return logits
 def maxpoolLayer(self, size, pad='SAME', stride=None):
     if stride == None:
         stride = size
     self.result = L.maxpooling(self.result,
                                size,
                                stride,
                                'maxpool_' + str(self.layernum),
                                pad=pad)
     if pad == 'VALID':
         self.inpsize[1] -= size - stride
         self.inpsize[2] -= size - stride
     else:
         if self.inpsize[1] % 2 == 1:
             self.inpsize[1] += 1
         if self.inpsize[2] % 2 == 1:
             self.inpsize[2] += 1
     self.inpsize[1] = self.inpsize[1] // stride
     self.inpsize[2] = self.inpsize[2] // stride
     return [self.result, list(self.inpsize)]
示例#6
0
def vgg_7(x, layers=3, base_channel=32, input_channel=2):
    output_channel = input_channel

    for i in range(layers):
        x = conv2d(x, [3, 3, input_channel, output_channel], 'conv_0_'+str(i))
        input_channel = output_channel

        x = conv2d(x, [3, 3, input_channel, output_channel], 'conv_1_'+str(i))
        input_channel = output_channel
        output_channel *= 2

        x = maxpooling(x)

    x = flatten(x)
    x = fully_connnected(x, 256, 'fc_1')
    x = fully_connnected(x, 1, 'fc_2', activation='no')

    logits = tf.squeeze(x)

    return logits
示例#7
0
    # Normalize the data
    print("normalize data")
    X_train = X_train / 255.0
    print(len(X_train))
    X_dev = X_dev / 255.0

    test = test / 255.0 
    # Reshape image in 3 dimensions (height = 28px, width = 28px , canal = 1)
    X_train = X_train.values.reshape(-1,28,28,1)
    X_dev = X_dev.values.reshape(-1,28,28,1)
    X_train.shape

    test = test.values.reshape(-1,28,28,1)
    # initialize weights
    conv_ = conv(8)
    pool = maxpooling(2)
    fully_c=fully_connected(13*13*8,10)
    # Train!
    loss = 0
    n_epochs=2
    losses=[]
    accs=[]
    num_correct = 0
    print('start training')
    for i, (im, label) in enumerate(zip(X_train, Y_train)):
      # print(im.shape)
    #   print(label)
      if i % 100 == 99:
        print('[Step %d] Past 100 steps: Average Loss %.3f | Accuracy: %d%%' %(i + 1, loss / 100, num_correct))
        losses.append(loss / 100)
        accs.append(num_correct)