Exemplo n.º 1
0
    def exhaustModel3(self, tensorWidth, tensorHeight, tensorDepth):
        aug = tflearn.ImageAugmentation()

        conv_net = input_data(shape=[None, tensorWidth, tensorHeight, tensorDepth], data_augmentation=aug)

        conv_net = conv_2d(conv_net,
                           nb_filter=27,
                           filter_size=9,
                           strides=1,
                           activation='relu', name='conv_layer_1')
        conv_net = max_pool_2d(conv_net, 2)

        conv_net = conv_2d(conv_net,
                           nb_filter=42,
                           filter_size=11,
                           strides=1,
                           activation='relu', name='conv_layer_2')
        conv_net = max_pool_2d(conv_net, 2)

        conv_net = conv_2d(conv_net,
                           nb_filter=105,
                           filter_size=11,
                           strides=1,
                           activation='relu', name='conv_layer_3')
        conv_net = max_pool_2d(conv_net, 2)

        conv_net = fully_connected(conv_net, 2, activation='softmax', name='output')
        conv_net = regression(conv_net, optimizer='adam', learning_rate=0.001, loss='categorical_crossentropy',
                              name='targets')

        model = tflearn.DNN(conv_net, tensorboard_verbose=0)

        return model
    def net(self, inputList):
        # aggregate inputs
        INPUT_CONCAT = tf.concat(axis=3, values=inputList)

        network = tflearn.conv_2d(INPUT_CONCAT, 64, 3, activation='relu')
        network = tflearn.dropout(network, self.dropout)
        network = tflearn.conv_2d(network, 64, 3, activation='relu')
        network = tflearn.dropout(network, self.dropout)
        network = tflearn.max_pool_2d(network, 2, strides=2)

        network = tflearn.conv_2d(network, 128, 3, activation='relu')
        network = tflearn.dropout(network, self.dropout)
        network = tflearn.conv_2d(network, 128, 3, activation='relu')
        network = tflearn.dropout(network, self.dropout)
        network = tflearn.max_pool_2d(network, 2, strides=2)

        network = tflearn.conv_2d(network, 256, 3, activation='relu')
        network = tflearn.dropout(network, self.dropout)
        network = tflearn.conv_2d(network, 256, 3, activation='relu')
        network = tflearn.dropout(network, self.dropout)
        network = tflearn.conv_2d(network, 256, 3, activation='relu')
        network = tflearn.dropout(network, self.dropout)
        network = tflearn.max_pool_2d(network, 2, strides=2)

        network = tflearn.fully_connected(network, 64, activation='relu')
        network = tflearn.dropout(network, self.dropout)
        network = tflearn.fully_connected(network, 64, activation='relu')
        network = tflearn.dropout(network, self.dropout)
        network = tflearn.fully_connected(network, 1, activation='linear')

        return network
Exemplo n.º 3
0
def vgg16(placeholderX=None):

    x = tflearn.input_data(shape=[None, 224, 224, 3], name='input',
                           placeholder=placeholderX)

    x = tflearn.conv_2d(x, 64, 3, activation='relu', name='conv1_1')
    x = tflearn.conv_2d(x, 64, 3, activation='relu', name='conv1_2')
    x = tflearn.max_pool_2d(x, 2, strides=2, name='pool1')

    x = tflearn.conv_2d(x, 128, 3, activation='relu', name='conv2_1')
    x = tflearn.conv_2d(x, 128, 3, activation='relu', name='conv2_2')
    x = tflearn.max_pool_2d(x, 2, strides=2, name='pool2')

    x = tflearn.conv_2d(x, 256, 3, activation='relu', name='conv3_1')
    x = tflearn.conv_2d(x, 256, 3, activation='relu', name='conv3_2')
    x = tflearn.conv_2d(x, 256, 3, activation='relu', name='conv3_3')
    x = tflearn.max_pool_2d(x, 2, strides=2, name='pool3')

    x = tflearn.conv_2d(x, 512, 3, activation='relu', name='conv4_1')
    x = tflearn.conv_2d(x, 512, 3, activation='relu', name='conv4_2')
    x = tflearn.conv_2d(x, 512, 3, activation='relu', name='conv4_3')
    x = tflearn.max_pool_2d(x, 2, strides=2, name='pool4')

    x = tflearn.conv_2d(x, 512, 3, activation='relu', name='conv5_1')
    x = tflearn.conv_2d(x, 512, 3, activation='relu', name='conv5_2')
    x = tflearn.conv_2d(x, 512, 3, activation='relu', name='conv5_3')
    x = tflearn.max_pool_2d(x, 2, strides=2, name='pool5')

    x = tflearn.conv_2d(x, 4096, 7, activation='relu', name='fc6')
    x = tflearn.dropout(x, 0.5)

    x = tflearn.conv_2d(x, 4096, 1, activation='relu', name='fc7')
    x = tflearn.dropout(x, 0.5)

    return x
    def RyanWilliams(self, tensorWidth, tensorHeight, tensorDepth):

        conv_net = input_data(
            shape=[None, tensorWidth, tensorHeight, tensorDepth])

        conv_net = conv_2d(conv_net,
                           nb_filter=20,
                           filter_size=7,
                           activation='relu',
                           name='conv_layer_1')
        conv_net = max_pool_2d(conv_net, 3, name='pool_layer_1')
        conv_net = conv_2d(conv_net,
                           nb_filter=20,
                           filter_size=5,
                           activation='relu',
                           name='conv_layer_2')
        conv_net = max_pool_2d(conv_net, 2, name='pool_layer_2')
        conv_net = fully_connected(conv_net,
                                   100,
                                   activation='sigmoid',
                                   name='fc_layer_1')

        conv_net = fully_connected(conv_net,
                                   2,
                                   activation='sigmoid',
                                   name='output')
        conv_net = regression(conv_net,
                              optimizer='sgd',
                              learning_rate=0.01,
                              loss='categorical_crossentropy',
                              name='targets')

        model = tflearn.DNN(conv_net, tensorboard_verbose=0)

        return model
Exemplo n.º 5
0
def create_conv_part(net_inputs):
    """Creates an input stream from depth image."""
    net = tflearn.conv_2d(incoming=net_inputs,
                          nb_filter=32,
                          filter_size=5,
                          strides=5,
                          padding='valid',
                          activation='relu')
    net = tflearn.max_pool_2d(incoming=net, kernel_size=2, strides=2)
    net = tflearn.conv_2d(incoming=net,
                          nb_filter=32,
                          filter_size=2,
                          strides=2,
                          padding='valid',
                          activation='relu')
    net = tflearn.max_pool_2d(incoming=net, kernel_size=2, strides=2)
    net = tflearn.conv_2d(incoming=net,
                          nb_filter=64,
                          filter_size=2,
                          strides=2,
                          padding='valid',
                          activation='relu')
    net = tflearn.max_pool_2d(incoming=net, kernel_size=2, strides=2)
    net = tflearn.flatten(incoming=net)
    return net
Exemplo n.º 6
0
    def input_layer(self, INPUT):
        net_layer = tflearn.conv_2d(INPUT,
                                    16 * self.conv_mult,
                                    5,
                                    activation='relu')
        net_layer = tflearn.max_pool_2d(net_layer, 2)
        #net_layer = tflearn.dropout(net_layer, 0.8)

        net_layer = tflearn.conv_2d(net_layer,
                                    32 * self.conv_mult,
                                    3,
                                    activation='relu')
        net_layer = tflearn.max_pool_2d(net_layer, 2)
        #net_layer = tflearn.dropout(net_layer, 0.8)

        net_layer = tflearn.conv_2d(net_layer,
                                    64 * self.conv_mult,
                                    3,
                                    activation='relu')
        net_layer = tflearn.max_pool_2d(net_layer, 2)
        #net_layer = tflearn.dropout(net_layer, 0.8)

        net_layer = tflearn.conv_2d(net_layer,
                                    128 * self.conv_mult,
                                    3,
                                    activation='relu')
        net_layer = tflearn.max_pool_2d(net_layer, 2)

        return net_layer
Exemplo n.º 7
0
def yn_net():
    net = tflearn.input_data(shape=[None, img_rows, img_cols, 1]) #D = 256, 256
    net = tflearn.conv_2d(net,nb_filter=8,filter_size=3, activation='relu', name='conv0.1')
    net = tflearn.conv_2d(net,nb_filter=8,filter_size=3, activation='relu', name='conv0.2')
    net = tflearn.max_pool_2d(net, kernel_size = [2,2], name='maxpool0') #D = 128, 128
    net = tflearn.dropout(net,0.75,name='dropout0')
    net = tflearn.conv_2d(net,nb_filter=16,filter_size=3, activation='relu', name='conv1.1')
    net = tflearn.conv_2d(net,nb_filter=16,filter_size=3, activation='relu', name='conv1.2')
    net = tflearn.max_pool_2d(net, kernel_size = [2,2], name='maxpool1') #D = 64,  64
    net = tflearn.dropout(net,0.75,name='dropout0')
    net = tflearn.conv_2d(net,nb_filter=32,filter_size=3, activation='relu', name='conv2.1')
    net = tflearn.conv_2d(net,nb_filter=32,filter_size=3, activation='relu', name='conv2.2')
    net = tflearn.max_pool_2d(net, kernel_size = [2,2], name='maxpool2') #D = 32 by 32
    net = tflearn.dropout(net,0.75,name='dropout0')
    net = tflearn.conv_2d(net,nb_filter=32,filter_size=3, activation='relu', name='conv3.1')
    net = tflearn.conv_2d(net,nb_filter=32,filter_size=3, activation='relu', name='conv3.2')
    net = tflearn.max_pool_2d(net, kernel_size = [2,2], name='maxpool3') #D = 16 by 16
    net = tflearn.dropout(net,0.75,name='dropout0')
#    net = tflearn.conv_2d(net,nb_filter=64,filter_size=3, activation='relu', name='conv4.1')
#    net = tflearn.conv_2d(net,nb_filter=64,filter_size=3, activation='relu', name='conv4.2')
#    net = tflearn.max_pool_2d(net, kernel_size = [2,2], name='maxpool4') #D = 8 by 8
#    net = tflearn.dropout(net,0.75,name='dropout0')
    net = tflearn.fully_connected(net, n_units = 128, activation='relu', name='fc1')
    net = tflearn.fully_connected(net, 2, activation='sigmoid')
    net = tflearn.regression(net, optimizer='adam', learning_rate=0.001)
    model = tflearn.DNN(net, tensorboard_verbose=1,tensorboard_dir='/tmp/tflearn_logs/')
    return model
Exemplo n.º 8
0
    def net(self, inputList):
        # aggregate inputs in depth
        INPUT_CONCAT = tf.concat(axis=3, values=inputList)

        network = tflearn.conv_2d(INPUT_CONCAT, 64, 3, activation='relu')
        network = tflearn.conv_2d(network, 64, 3, activation='relu')
        network = tflearn.max_pool_2d(network, 2, strides=2)

        network = tflearn.conv_2d(network, 128, 3, activation='relu')
        network = tflearn.conv_2d(network, 128, 3, activation='relu')
        network = tflearn.max_pool_2d(network, 2, strides=2)

        network = tflearn.conv_2d(network, 256, 3, activation='relu')
        network = tflearn.conv_2d(network, 256, 3, activation='relu')
        network = tflearn.conv_2d(network, 256, 3, activation='relu')
        network = tflearn.max_pool_2d(network, 2, strides=2)

        network = tflearn.conv_2d(network, 512, 3, activation='relu')
        network = tflearn.conv_2d(network, 512, 3, activation='relu')
        network = tflearn.conv_2d(network, 512, 3, activation='relu')
        network = tflearn.max_pool_2d(network, 2, strides=2)

        network = tflearn.conv_2d(network, 512, 3, activation='relu')
        network = tflearn.conv_2d(network, 512, 3, activation='relu')
        network = tflearn.conv_2d(network, 512, 3, activation='relu')
        network = tflearn.max_pool_2d(network, 2, strides=2)

        network = tflearn.fully_connected(network, 4096, activation='relu')
        network = tflearn.dropout(network, 0.5)
        network = tflearn.fully_connected(network, 4096, activation='relu')
        network = tflearn.dropout(network, 0.5)
        # output is different from VGG
        network = tflearn.fully_connected(network, 1, activation='linear')

        return network
Exemplo n.º 9
0
def rsd_vgg(incoming, num_classes):

    x = tflearn.conv_2d(incoming, 64, 3, activation='relu', scope='conv1_1')
    x = tflearn.conv_2d(x, 64, 3, activation='relu', scope='conv1_2')
    x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool1')

    x = tflearn.conv_2d(x, 128, 3, activation='relu', scope='conv2_1')
    x = tflearn.conv_2d(x, 128, 3, activation='relu', scope='conv2_2')
    x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool2')

    x = tflearn.conv_2d(x, 256, 3, activation='relu', scope='conv3_1')
    x = tflearn.conv_2d(x, 256, 3, activation='relu', scope='conv3_2')
    x = tflearn.conv_2d(x, 256, 3, activation='relu', scope='conv3_3')
    x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool3')

    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv4_1')
    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv4_2')
    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv4_3')
    x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool4')

    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv5_1')
    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv5_2')
    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv5_3')
    x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool5')

    sal_pred, subitizing = branch(x, num_classes)

    return sal_pred, subitizing
Exemplo n.º 10
0
    def test_conv_layers(self):

        X = [[0., 0., 0., 0.], [1., 1., 1., 1.], [0., 0., 1., 0.], [1., 1., 1., 0.]]
        Y = [[1., 0.], [0., 1.], [1., 0.], [0., 1.]]

        with tf.Graph().as_default():
            g = tflearn.input_data(shape=[None, 4])
            g = tflearn.reshape(g, new_shape=[-1, 2, 2, 1])
            g = tflearn.conv_2d(g, 4, 2, activation='relu')
            g = tflearn.max_pool_2d(g, 2)
            g = tflearn.fully_connected(g, 2, activation='softmax')
            g = tflearn.regression(g, optimizer='sgd', learning_rate=1.)

            m = tflearn.DNN(g)
            m.fit(X, Y, n_epoch=100, snapshot_epoch=False)
            self.assertGreater(m.predict([[1., 0., 0., 0.]])[0][0], 0.9)

        # Bulk Tests
        with tf.Graph().as_default():
            g = tflearn.input_data(shape=[None, 4])
            g = tflearn.reshape(g, new_shape=[-1, 2, 2, 1])
            g = tflearn.conv_2d(g, 4, 2)
            g = tflearn.conv_2d(g, 4, 1)
            g = tflearn.conv_2d_transpose(g, 4, 2, [2, 2])
            g = tflearn.max_pool_2d(g, 2)
Exemplo n.º 11
0
    def create_critic_network(self):
        inputs = tflearn.input_data(shape=[None, 75, 100, 1])
        #inputs = tflearn.input_data(shape=[1, 75, 100, 1])
        action = tflearn.input_data(shape=[None, self.a_dim])

        net = tflearn.conv_2d(inputs, 32, 3, activation='relu', regularizer="L2")
        net = tflearn.max_pool_2d(net, 2)
        net = tflearn.local_response_normalization(net)
        net = tflearn.conv_2d(net, 64, 3, activation='relu', regularizer="L2")
        net = tflearn.max_pool_2d(net, 2)
        net = tflearn.local_response_normalization(net)
        net = tflearn.conv_2d(net, 128, 2, activation='relu', regularizer="L2")
        net = tflearn.fully_connected(net, 256, activation='tanh')
        net = tflearn.dropout(net, 0.8)

        # Add the action tensor in the 2nd hidden layer
        # Use two temp layers to get the corresponding weights and biases
        t1 = tflearn.fully_connected(net, 300)
        t2 = tflearn.fully_connected(action, 1)

        net = tflearn.activation(
            tf.matmul(net, t1.W) + 10*tf.matmul(action, t2.W) + t2.b, activation='relu')

        # linear layer connected to 1 output representing Q(s,a)
        # Weights are init to Uniform[-3e-3, 3e-3]
        w_init = tflearn.initializations.uniform(minval=-0.01, maxval=0.01)
        #w_init = tflearn.initializations.uniform(minval=-0.003, maxval=0.003)
        out = tflearn.fully_connected(net, 1, weights_init=w_init)
        return inputs, action, out
Exemplo n.º 12
0
def vgg16(input, num_class):

    x = tflearn.conv_2d(input, 64, 3, activation='relu', scope='conv1_1')
    x = tflearn.conv_2d(x, 64, 3, activation='relu', scope='conv1_2')
    x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool1')

    x = tflearn.conv_2d(x, 128, 3, activation='relu', scope='conv2_1')
    x = tflearn.conv_2d(x, 128, 3, activation='relu', scope='conv2_2')
    x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool2')

    x = tflearn.conv_2d(x, 256, 3, activation='relu', scope='conv3_1')
    x = tflearn.conv_2d(x, 256, 3, activation='relu', scope='conv3_2')
    x = tflearn.conv_2d(x, 256, 3, activation='relu', scope='conv3_3')
    x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool3')

    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv4_1')
    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv4_2')
    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv4_3')
    x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool4')

    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv5_1')
    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv5_2')
    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv5_3')
    x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool5')

    x = tflearn.fully_connected(x, 4096, activation='relu', scope='fc6')
    x = tflearn.dropout(x, 0.5, name='dropout1')

    x = tflearn.fully_connected(x, 4096, activation='relu', scope='fc7')
    x = tflearn.dropout(x, 0.5, name='dropout2')

    x = tflearn.fully_connected(x, num_class, activation='softmax', scope='fc8',
                                restore=False)

    return x
Exemplo n.º 13
0
    def build_cnn_network(self, network):
        """ Build CNN network.

        Args:
            network: base network.

        Returns:
            model: CNN model.

        """
        print('Building CNN network.')
        # Convolutional network building
        network = tflearn.conv_2d(network, 32,
                            self.IMAGE_CHANNEL_NUM,
                          activation='relu')
        network = tflearn.max_pool_2d(network, 2)
        network = tflearn.conv_2d(network, 64,
                          self.IMAGE_CHANNEL_NUM,
                          activation='relu')
        network = tflearn.conv_2d(network, 64,
                          self.IMAGE_CHANNEL_NUM,
                          activation='relu')
        network = tflearn.max_pool_2d(network, 2)
        network = tflearn.fully_connected(
            network, 32 * 32, activation='relu')
        network = tflearn.dropout(network, 0.5)
        # Two category. positive or negative.
        network = tflearn.fully_connected(network, 2,
                                  activation='softmax')
        network = tflearn.regression(network, optimizer='adam',
                             loss='categorical_crossentropy',
                             learning_rate=0.001)
        print("CNN network built.")
        return network
Exemplo n.º 14
0
def create_alexnet(num_classes=3, imgSize=FLAGS.sample_size):

    # Building 'AlexNet'
    network = tflearn.input_data(shape=[None, imgSize, imgSize, 1])
    network = tflearn.conv_2d(network, 96, 11, strides=4, activation='relu')
    network = tflearn.max_pool_2d(network, 3, strides=2)
    network = tflearn.local_response_normalization(network)
    network = tflearn.conv_2d(network, 256, 5, activation='relu')
    network = tflearn.max_pool_2d(network, 3, strides=2)
    network = tflearn.local_response_normalization(network)
    network = tflearn.conv_2d(network, 384, 3, activation='relu')
    network = tflearn.conv_2d(network, 384, 3, activation='relu')
    network = tflearn.conv_2d(network, 256, 3, activation='relu')
    network = tflearn.max_pool_2d(network, 3, strides=2)
    network = tflearn.local_response_normalization(network)
    network = tflearn.fully_connected(network, 4096, activation='tanh')
    network = tflearn.dropout(network, 0.5)
    network = tflearn.fully_connected(network, 4096, activation='tanh')
    network = tflearn.dropout(network, 0.5)
    network = tflearn.fully_connected(network,
                                      num_classes,
                                      activation='softmax')
    network = tflearn.regression(network,
                                 optimizer='momentum',
                                 loss='categorical_crossentropy',
                                 learning_rate=0.001)
    return network
Exemplo n.º 15
0
def trythisnet(x):
    network = tflearn.conv_2d(x, 64, 5, activation='relu')
    network = tflearn.max_pool_2d(network, 3, 2)
    network = tflearn.local_response_normalization(network,
                                                   4,
                                                   alpha=0.001 / 9.0)
    network = tflearn.conv_2d(network, 64, 5, activation='relu')
    network = tflearn.local_response_normalization(network,
                                                   4,
                                                   alpha=0.001 / 9.0)
    network = tflearn.max_pool_2d(network, 3, 2)
    network = tflearn.fully_connected(network,
                                      384,
                                      activation='relu',
                                      weight_decay=0.004)
    network = tflearn.fully_connected(network,
                                      192,
                                      activation='relu',
                                      weight_decay=0.004)
    network = tflearn.fully_connected(network,
                                      10,
                                      activation='softmax',
                                      weight_decay=0.0)

    return network
    def MichaelGeigl(self, tensorWidth, tensorHeight, tensorDepth):

        conv_net = input_data(
            shape=[None, tensorWidth, tensorHeight, tensorDepth])
        conv_net = conv_2d(conv_net, 50, 4, activation='tanh')
        conv_net = max_pool_2d(conv_net, 5)
        conv_net = conv_2d(conv_net, 50, 4, activation='tanh')
        conv_net = max_pool_2d(conv_net, 5)
        conv_net = conv_2d(conv_net, 100, 4, activation='tanh')
        conv_net = max_pool_2d(conv_net, 5)
        conv_net = fully_connected(conv_net, 50, activation='tanh', name='fl1')

        conv_net = fully_connected(conv_net,
                                   2,
                                   activation='softmax',
                                   name='output')

        conv_net = regression(conv_net,
                              optimizer='sgd',
                              learning_rate=0.01,
                              loss='categorical_crossentropy',
                              name='targets')

        model = tflearn.DNN(conv_net, tensorboard_verbose=0)

        return model
Exemplo n.º 17
0
def conv_net():
    network = tflearn.input_data(shape=[None, height, width, 3])
    network = tflearn.conv_2d(network, 96, 11, strides=4, activation='relu')
    network = tflearn.max_pool_2d(network, 3, strides=2)
    network = tflearn.conv_2d(network, 96, 11, strides=4, activation='relu')
    network = tflearn.max_pool_2d(network, 3, strides=2)
    return network
Exemplo n.º 18
0
    def test_conv_layers(self):

        X = [[0., 0., 0., 0.], [1., 1., 1., 1.], [0., 0., 1., 0.], [1., 1., 1., 0.]]
        Y = [[1., 0.], [0., 1.], [1., 0.], [0., 1.]]

        with tf.Graph().as_default():
            g = tflearn.input_data(shape=[None, 4])
            g = tflearn.reshape(g, new_shape=[-1, 2, 2, 1])
            g = tflearn.conv_2d(g, 4, 2, activation='relu')
            g = tflearn.max_pool_2d(g, 2)
            g = tflearn.fully_connected(g, 2, activation='softmax')
            g = tflearn.regression(g, optimizer='sgd', learning_rate=1.)

            m = tflearn.DNN(g)
            m.fit(X, Y, n_epoch=100, snapshot_epoch=False)
            # TODO: Fix test
            #self.assertGreater(m.predict([[1., 0., 0., 0.]])[0][0], 0.5)

        # Bulk Tests
        with tf.Graph().as_default():
            g = tflearn.input_data(shape=[None, 4])
            g = tflearn.reshape(g, new_shape=[-1, 2, 2, 1])
            g = tflearn.conv_2d(g, 4, 2)
            g = tflearn.conv_2d(g, 4, 1)
            g = tflearn.conv_2d_transpose(g, 4, 2, [2, 2])
            g = tflearn.max_pool_2d(g, 2)
Exemplo n.º 19
0
def vgg16(input=None, classes=1000):
    x = tflearn.conv_2d(input, 64, 3, activation='relu', scope='conv1_1', trainable=False)
    x = tflearn.conv_2d(x, 64, 3, activation='relu', scope='conv1_2', trainable=False)
    x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool1')

    x = tflearn.conv_2d(x, 128, 3, activation='relu', scope='conv2_1', trainable=False)
    x = tflearn.conv_2d(x, 128, 3, activation='relu', scope='conv2_2', trainable=False)
    x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool2')

    x = tflearn.conv_2d(x, 256, 3, activation='relu', scope='conv3_1', trainable=False)
    x = tflearn.conv_2d(x, 256, 3, activation='relu', scope='conv3_2', trainable=False)
    x = tflearn.conv_2d(x, 256, 3, activation='relu', scope='conv3_3', trainable=False)
    x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool3')

    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv4_1', trainable=False)
    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv4_2', trainable=False)
    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv4_3', trainable=False)
    x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool4')

    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv5_1')
    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv5_2')
    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv5_3')
    x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool5')

    x = tflearn.fully_connected(x, 4096, activation='relu', scope='fc6')
    x = tflearn.dropout(x, 0.5, name='dropout1')

    # change the structure, now fc only has 2048, leass parameters, which is enough for this task
    x = tflearn.fully_connected(x, 2048, activation='relu', scope='fc7', restore=False)
    x = tflearn.dropout(x, 0.5, name='dropout2')

    x = tflearn.fully_connected(x, classes, activation='softmax', scope='fc8', restore=False)

    return x
Exemplo n.º 20
0
def build_tflearn_convnet_4():
    # your code here
    input = tflearn.input_data(shape=[None, 28, 28, 1])
    cov1 = tflearn.conv_2d(input,
                           nb_filter=128,
                           filter_size=5,
                           activation='sigmoid',
                           name='conv_layer_1')
    max_pool1 = tflearn.max_pool_2d(cov1, 2, name='pool1')
    lrn = tflearn.local_response_normalization(max_pool1)
    cov2 = tflearn.conv_2d(lrn,
                           nb_filter=64,
                           filter_size=5,
                           activation='sigmoid',
                           name='conv_layer_2')
    max_pool2 = tflearn.max_pool_2d(cov2, 2, name='pool2')
    lrn2 = tflearn.local_response_normalization(max_pool2)
    cov3 = tflearn.conv_2d(lrn2,
                           nb_filter=32,
                           filter_size=5,
                           activation='sigmoid',
                           name='conv_layer_3')
    max_pool3 = tflearn.max_pool_2d(cov3, 2, name='pool3')
    fc1 = tflearn.fully_connected(max_pool3, 100, activation='sigmoid')
    fc2 = tflearn.fully_connected(fc1, 10, activation='softmax')
    reg = tflearn.regression(fc2,
                             optimizer='sgd',
                             loss='categorical_crossentropy',
                             learning_rate=0.1)
    return tflearn.DNN(reg)
Exemplo n.º 21
0
def CNN_Core(x, reuse=False):
    with tf.variable_scope('cnn_core', reuse=reuse):
        network = tflearn.conv_2d(x,
                                  KERNEL,
                                  3,
                                  activation='relu',
                                  regularizer="L2",
                                  weight_decay=0.0001)
        network = tflearn.max_pool_2d(network, 2)
        network = tflearn.conv_2d(network,
                                  KERNEL,
                                  2,
                                  activation='relu',
                                  regularizer="L2",
                                  weight_decay=0.0001)
        network = tflearn.max_pool_2d(network, 2)
        network = tflearn.conv_2d(network,
                                  KERNEL,
                                  2,
                                  activation='relu',
                                  regularizer="L2",
                                  weight_decay=0.0001)
        network = tflearn.max_pool_2d(network, 2)

        split_flat = tflearn.flatten(network)
        return split_flat
    def input_layer(self, INPUT, scope, reuse):
        varscope = scope + "_1"
        net_layer = tflearn.conv_2d(INPUT,
                                    16 * self.conv_mult,
                                    5,
                                    activation='relu',
                                    scope=varscope,
                                    reuse=reuse)
        net_layer = tflearn.max_pool_2d(net_layer, 2)
        #net_layer = tflearn.dropout(net_layer, 0.8)

        varscope = scope + "_2"
        net_layer = tflearn.conv_2d(net_layer,
                                    32 * self.conv_mult,
                                    3,
                                    activation='relu',
                                    scope=varscope,
                                    reuse=reuse)
        net_layer = tflearn.max_pool_2d(net_layer, 2)
        #net_layer = tflearn.dropout(net_layer, 0.8)

        varscope = scope + "_3"
        net_layer = tflearn.conv_2d(net_layer,
                                    64 * self.conv_mult,
                                    3,
                                    activation='relu',
                                    scope=varscope,
                                    reuse=reuse)
        net_layer = tflearn.max_pool_2d(net_layer, 2)
        #net_layer = tflearn.dropout(net_layer, 0.8)

        return net_layer
Exemplo n.º 23
0
    def ConvNet9(tensorWidth, tensorHeight, tensorDepth, tb_verb=0):
        conv_net = input_data(
            shape=[None, tensorWidth, tensorHeight, tensorDepth])

        conv_net = conv_2d(conv_net,
                           nb_filter=20,
                           filter_size=5,
                           activation="relu")
        conv_net = max_pool_2d(conv_net, 2)
        conv_net = conv_2d(conv_net,
                           nb_filter=50,
                           filter_size=5,
                           activation="relu")
        conv_net = max_pool_2d(conv_net, 2)
        conv_net = conv_2d(conv_net,
                           nb_filter=30,
                           filter_size=5,
                           activation="relu")
        conv_net = max_pool_2d(conv_net, 2)
        conv_net = fully_connected(conv_net, 140, activation="relu")
        conv_net = fully_connected(conv_net, 80, activation="sigmoid")
        conv_net = fully_connected(conv_net, 2, activation="sigmoid")

        conv_net = regression(
            conv_net,
            optimizer='adam',
            learning_rate=0.01,
            loss='categorical_crossentropy',
        )

        model = tflearn.DNN(conv_net, tensorboard_verbose=tb_verb)

        return model
Exemplo n.º 24
0
def CNN_encoder_cat(x, tsamples, nsamples, n_output, nlabels=5):
    with tf.variable_scope("CNN_encoder_cat"):
        x = tf.reshape(x, shape=[-1, tsamples, nsamples, 1])
        #x = add_ij(x, tsamples, nsamples)
        encoder = tflearn.conv_2d(x, 32, [3, 3], activation='tanh')
        print(encoder.get_shape())
        #encoder = tflearn.batch_normalization(encoder)
        encoder = tflearn.max_pool_2d(encoder, 2)
        print(encoder.get_shape())
        encoder = tflearn.conv_2d(encoder, 32, [3, 3], activation='tanh')
        print(encoder.get_shape())
        #encoder = tflearn.batch_normalization(encoder)
        encoder = tflearn.max_pool_2d(encoder, 2)
        print(encoder.get_shape())
        encoder = tflearn.conv_2d(encoder, 32, [3, 3], activation='tanh')
        print(encoder.get_shape())
        #encoder = tflearn.batch_normalization(encoder)
        encoder = tflearn.max_pool_2d(encoder, 2)
        print(encoder.get_shape())
        cat = tflearn.fully_connected(encoder,
                                      nlabels,
                                      activation='softmax',
                                      name="catout")
        output = tflearn.fully_connected(encoder,
                                         n_output,
                                         activation='linear',
                                         name="zout")
    return output, cat
Exemplo n.º 25
0
    def ConvNet6(tensorWidth, tensorHeight, tensorDepth, tb_verb=0):
        conv_net = input_data(
            shape=[None, tensorWidth, tensorHeight, tensorDepth])

        conv_net = conv_2d(conv_net,
                           nb_filter=10,
                           filter_size=10,
                           activation='tanh')
        conv_net = max_pool_2d(conv_net, 4)
        conv_net = conv_2d(conv_net,
                           nb_filter=30,
                           filter_size=3,
                           activation='tanh')
        conv_net = max_pool_2d(conv_net, 2)
        conv_net = fully_connected(conv_net, 100, activation='sigmoid')

        conv_net = fully_connected(conv_net, 2, activation='softmax')

        conv_net = regression(conv_net,
                              optimizer='sgd',
                              learning_rate=0.01,
                              loss='categorical_crossentropy')

        model = tflearn.DNN(conv_net, tensorboard_verbose=tb_verb)

        return model
Exemplo n.º 26
0
    def ConvNet8(tensorWidth, tensorHeight, tensorDepth, tb_verb=0):
        conv_net = input_data(
            shape=[None, tensorWidth, tensorHeight, tensorDepth])

        conv_net = conv_2d(conv_net,
                           nb_filter=20,
                           filter_size=7,
                           activation='relu',
                           name='conv_layer_1')
        conv_net = max_pool_2d(conv_net, 3)
        conv_net = conv_2d(conv_net,
                           nb_filter=20,
                           filter_size=5,
                           activation='relu')
        conv_net = max_pool_2d(conv_net, 2)
        conv_net = fully_connected(conv_net, 100, activation='sigmoid')

        conv_net = fully_connected(conv_net, 2, activation='sigmoid')
        conv_net = regression(
            conv_net,
            optimizer='sgd',
            learning_rate=0.01,
            loss='categorical_crossentropy',
        )

        model = tflearn.DNN(conv_net, tensorboard_verbose=tb_verb)

        return model
Exemplo n.º 27
0
def load_cnn_audio_model_buzz3(model_path):
    # Validation Accuracy: 0.9002280501710376
    # Validation Data: BUZZ3_valid_X, BUZZ3_valid_Y
    input_layer = input_data(shape=[None, 4000, 1, 1])
    conv_layer_1 = conv_2d(input_layer,
                           nb_filter=64,
                           filter_size=10,
                           activation='relu',
                           name='conv_layer_1')
    pool_layer_1 = max_pool_2d(conv_layer_1, 4, name='pool_layer_1')
    conv_layer_2 = conv_2d(pool_layer_1,
                           nb_filter=16,
                           filter_size=4,
                           activation='relu',
                           name='conv_layer_2')
    pool_layer_2 = max_pool_2d(conv_layer_2, 4, name='pool_layer_2')

    fc_layer_1 = fully_connected(pool_layer_2,
                                 512,
                                 activation='relu',
                                 name='fc_layer_1')

    d1 = dropout(fc_layer_1, 0.5)

    fc_layer_2 = fully_connected(d1, 128, activation='relu', name='fc_layer_2')
    d2 = dropout(fc_layer_2, 0.5)
    fc_layer_3 = fully_connected(d2,
                                 3,
                                 activation='softmax',
                                 name='fc_layer_3')
    model = tflearn.DNN(fc_layer_3)
    model.load(model_path)
    return model
Exemplo n.º 28
0
    def create_network(self):
        """
			This method creates the convolutional neural network.
		"""

        # creating the input layer
        network = input_data(
            shape=[None, self.max_sentence_length, self.embedding_dim, 1],
            name='input')
        # creating the first convolutional layer
        network = conv_2d(network, 32, 3, activation='relu', regularizer="L2")
        # creating the first pool layer
        network = max_pool_2d(network, 2)
        # creating the second convolutional layer
        network = conv_2d(network, 64, 5, activation='relu', regularizer="L2")
        # creating the first pool layer
        network = max_pool_2d(network, 2)
        # droping out some tensors, for avoiding the network to overfit
        network = dropout(network, 0.5)
        # creating the soft-max layer
        network = fully_connected(network,
                                  self.number_of_classes,
                                  activation='softmax')
        self.network = regression(network,
                                  optimizer='adam',
                                  learning_rate=self.learning_rate,
                                  loss='categorical_crossentropy',
                                  name='target')
Exemplo n.º 29
0
def vgg16(input, num_class):

    x = tflearn.conv_2d(input, 64, 3, activation='relu', scope='conv1_1')
    x = tflearn.conv_2d(x, 64, 3, activation='relu', scope='conv1_2')
    x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool1')

    x = tflearn.conv_2d(x, 128, 3, activation='relu', scope='conv2_1')
    x = tflearn.conv_2d(x, 128, 3, activation='relu', scope='conv2_2')
    x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool2')

    x = tflearn.conv_2d(x, 256, 3, activation='relu', scope='conv3_1')
    x = tflearn.conv_2d(x, 256, 3, activation='relu', scope='conv3_2')
    x = tflearn.conv_2d(x, 256, 3, activation='relu', scope='conv3_3')
    x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool3')

    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv4_1')
    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv4_2')
    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv4_3')
    x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool4')

    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv5_1')
    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv5_2')
    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv5_3')
    x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool5')

    x = tflearn.fully_connected(x, 4096, activation='relu', scope='fc6')
    x = tflearn.dropout(x, 0.5, name='dropout1')

    x = tflearn.fully_connected(x, 4096, activation='relu', scope='fc7')
    x = tflearn.dropout(x, 0.5, name='dropout2')

    x = tflearn.fully_connected(x, num_class, activation='softmax', scope='fc8',
                                restore=False)

    return x
Exemplo n.º 30
0
def VGG_NET_O_tfl(img):
    vgg_net = tfl.conv_2d(img, 64, 3, activation='relu', name='conv1_1')
    vgg_net = tfl.conv_2d(vgg_net, 64, 3, activation='relu', name='conv1_2')
    vgg_net = tfl.max_pool_2d(vgg_net, 2, 2, name='pool1')
    vgg_net = tfl.conv_2d(vgg_net, 128, 3, activation='relu', name='conv2_1')
    vgg_net = tfl.conv_2d(vgg_net, 128, 3, activation='relu', name='conv2_2')
    vgg_net = tfl.max_pool_2d(vgg_net, 2, 2, name='pool2')
    vgg_net = tfl.conv_2d(vgg_net, 256, 3, activation='relu', name='conv3_1')
    vgg_net = tfl.conv_2d(vgg_net, 256, 3, activation='relu', name='conv3_2')
    vgg_net = tfl.conv_2d(vgg_net, 256, 3, activation='relu', name='conv3_3')
    vgg_net = tfl.max_pool_2d(vgg_net, 2, 2, name='pool3')
    vgg_net = tfl.conv_2d(vgg_net, 512, 3, activation='relu', name='conv4_1')
    vgg_net = tfl.conv_2d(vgg_net, 512, 3, activation='relu', name='conv4_2')
    vgg_net = tfl.conv_2d(vgg_net, 512, 3, activation='relu', name='conv4_3')
    vgg_net = tfl.max_pool_2d(vgg_net, 2, 2, name='pool4')
    vgg_net = tfl.conv_2d(vgg_net, 512, 3, activation='relu', name='conv5_1')
    vgg_net = tfl.conv_2d(vgg_net, 512, 3, activation='relu', name='conv5_2')
    vgg_net = tfl.conv_2d(vgg_net, 512, 3, activation='relu', name='conv5_3')
    vgg_net = tfl.max_pool_2d(vgg_net, 2, 2, name='pool5')
    vgg_net = tfl.fully_connected(vgg_net, 4096, activation='tanh', name='fc1')
    vgg_net = tfl.dropout(vgg_net, 0.8, name='drop1')
    vgg_net = tfl.fully_connected(vgg_net, 4096, activation='tanh', name='fc2')
    vgg_net = tfl.dropout(vgg_net, 0.8, name='drop2')
    softmax = tfl.fully_connected(vgg_net,
                                  7,
                                  activation='softmax',
                                  name='prob')

    return softmax
Exemplo n.º 31
0
def mstarnet(x):
    network = tflearn.conv_2d(x, 18, 9, activation='relu')
    network = tflearn.max_pool_2d(network, 6)
    network = tflearn.conv_2d(network, 36, 5, activation='relu')
    network = tflearn.max_pool_2d(network, 4)
    network = tflearn.conv_2d(network, 120, 4, activation='relu')
    network = tflearn.fully_connected(network, 3, activation='softmax')

    return network
Exemplo n.º 32
0
 def create_dual_network_2d_cnn(self, inputs, s_dim):
     with tf.variable_scope(self.scope + '-dual', reuse=self.reuse):
         net = tflearn.conv_2d(inputs, FEATURE_NUM, 3, activation='relu')
         net = tflearn.max_pool_2d(net, FEATURE_NUM, 3)
         net = tflearn.conv_2d(inputs, FEATURE_NUM, 3, activation='relu')
         net = tflearn.max_pool_2d(net, FEATURE_NUM, 3)
         out = tflearn.fully_connected(net, FEATURE_NUM, activation='relu')
         self.reuse = True
         return out
Exemplo n.º 33
0
    def ConvNetGS4(tensorWidth, tensorHeight, tensorDepth, tb_verb=0):
        aug = tflearn.ImageAugmentation()

        conv_net = input_data(
            shape=[None, tensorWidth, tensorHeight, tensorDepth],
            data_augmentation=aug)

        # hidden layer 1
        conv_net = conv_2d(conv_net,
                           nb_filter=27,
                           filter_size=9,
                           strides=1,
                           activation='relu',
                           name='conv_layer_1')
        conv_net = max_pool_2d(conv_net, 2)

        # hidden layer 2
        conv_net = conv_2d(conv_net,
                           nb_filter=38,
                           filter_size=9,
                           strides=1,
                           activation='relu',
                           name='conv_layer_2')
        conv_net = max_pool_2d(conv_net, 2)

        # hidden layer 3
        conv_net = conv_2d(conv_net,
                           nb_filter=85,
                           filter_size=9,
                           strides=1,
                           activation='relu',
                           name='conv_layer_3')
        conv_net = max_pool_2d(conv_net, 2)

        # hidden layer 4
        conv_net = conv_2d(conv_net,
                           nb_filter=220,
                           filter_size=10,
                           strides=1,
                           activation='relu',
                           name='conv_layer_4')
        conv_net = max_pool_2d(conv_net, 2)

        conv_net = fully_connected(conv_net,
                                   2,
                                   activation='softmax',
                                   name='output')
        conv_net = regression(conv_net,
                              optimizer='adam',
                              learning_rate=0.00038,
                              loss='categorical_crossentropy',
                              name='targets')

        model = tflearn.DNN(conv_net, tensorboard_verbose=tb_verb)

        return model
Exemplo n.º 34
0
 def components_7(self, dim):
     net = input_data(shape=[None, 64, 441, 100])
     net = conv_2d(net, 128, 2, activation='relu', regularizer="L2")
     net = max_pool_2d(net, 2)
     net = conv_2d(net, 128, 2, activation='relu', regularizer="L2")
     net = max_pool_2d(net, 2)
     net = fully_connected(net, 256, activation='sigmoid')
     net = fully_connected(net, 256, activation='sigmoid')
     net = fully_connected(net, 3, activation='sigmoid')
     return net
Exemplo n.º 35
0
def fit(z, X_train, y_train, X_test, y_test):

    # resphape data
    X_train = np.reshape(X_train, (-1, 28, 28))
    X_test = np.reshape(X_test, (-1, 28, 28))

    global k, units, activations, values
    k = 0

    # conv net
    tf.reset_default_graph()
    network = tflearn.input_data(shape=[None, 28, 28, 1], name='input')
    network = tflearn.conv_2d(network,
                              unwrap(units, z),
                              3,
                              activation=unwrap(activations, z),
                              regularizer="L2")
    network = tflearn.max_pool_2d(network, 2)
    network = tflearn.local_response_normalization(network)
    network = tflearn.conv_2d(network,
                              unwrap(units, z),
                              3,
                              activation=unwrap(activations, z),
                              regularizer="L2")
    network = tflearn.max_pool_2d(network, 2)
    network = tflearn.local_response_normalization(network)
    network = tflearn.fully_connected(network,
                                      unwrap(units, z),
                                      activation=unwrap(activations, z))
    network = tflearn.dropout(network, unwrap(values, z))
    network = tflearn.fully_connected(network,
                                      unwrap(units, z),
                                      activation=unwrap(activations, z))
    network = tflearn.dropout(network, unwrap(values, z))
    network = tflearn.fully_connected(network, 10, activation='softmax')
    network = tflearn.regression(network,
                                 optimizer='adam',
                                 learning_rate=0.01,
                                 loss='categorical_crossentropy',
                                 name='target')

    # training
    model = tflearn.DNN(network, tensorboard_verbose=0)
    model.fit({'input': X_train}, {'target': y_train},
              n_epoch=20,
              validation_set=({
                  'input': X_test
              }, {
                  'target': y_test
              }),
              snapshot_step=100,
              show_metric=True)
    score = model.evaluate(testX, testY)
    print("acc = ", score[0])
    return score[0]
Exemplo n.º 36
0
def run():
    net = tflearn.input_data(shape=[None, 224, 224, 3])

    net = tflearn.conv_2d(net, 64, 3, activation='relu')
    net = tflearn.conv_2d(net, 64, 3, activation='relu')
    net = tflearn.max_pool_2d(net, 2)

    net = tflearn.conv_2d(net, 128, 3, activation='relu')
    net = tflearn.conv_2d(net, 128, 3, activation='relu')
    net = tflearn.max_pool_2d(net, 2)

    net = tflearn.conv_2d(net, 256, 3, activation='relu')
    net = tflearn.conv_2d(net, 256, 3, activation='relu')
    net = tflearn.conv_2d(net, 256, 3, activation='relu')
    net = tflearn.max_pool_2d(net, 2)

    net = tflearn.conv_2d(net, 512, 3, activation='relu')
    net = tflearn.conv_2d(net, 512, 3, activation='relu')
    net = tflearn.conv_2d(net, 512, 3, activation='relu')
    net = tflearn.max_pool_2d(net, 2)

    net = tflearn.conv_2d(net, 512, 3, activation='relu')
    net = tflearn.conv_2d(net, 512, 3, activation='relu')
    net = tflearn.conv_2d(net, 512, 3, activation='relu')
    net = tflearn.max_pool_2d(net, 2)

    net = tflearn.fully_connected(net, 4096, activation='relu')
    net = tflearn.dropout(net, 0.5)
    net = tflearn.fully_connected(net, 4096, activation='relu')
    net = tflearn.dropout(net, 0.5)
    net = tflearn.fully_connected(net, 17, activation='softmax')

    net = tflearn.regression(net, optimizer='rmsprop',
                     loss='categorical_crossentropy',
                     learning_rate=0.001)

    m = tflearn.DNN(net, checkpoint_path='models/vgg_net',
                    max_checkpoints=1, tensorboard_verbose=3)
    m.fit(X, Y, n_epoch=500, shuffle=True,
          show_metric=True, batch_size=32, snapshot_step=500,
          snapshot_epoch=False, run_id='vgg_net')
    m.save('models/vgg_net.tfl')
Exemplo n.º 37
0
def vgg16(placeholderX=None, softmax_size=1000, restore_softmax=True,
          data_preprocessing=None, data_augmentation=None):

    x = tflearn.input_data(shape=[None, 224, 224, 3], name='input',
                           placeholder=placeholderX,
                           data_preprocessing=data_preprocessing,
                           data_augmentation=data_augmentation)

    x = tflearn.conv_2d(x, 64, 3, activation='relu', scope='conv1_1')
    x = tflearn.conv_2d(x, 64, 3, activation='relu', scope='conv1_2')
    x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool1')

    x = tflearn.conv_2d(x, 128, 3, activation='relu', scope='conv2_1')
    x = tflearn.conv_2d(x, 128, 3, activation='relu', scope='conv2_2')
    x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool2')

    x = tflearn.conv_2d(x, 256, 3, activation='relu', scope='conv3_1')
    x = tflearn.conv_2d(x, 256, 3, activation='relu', scope='conv3_2')
    x = tflearn.conv_2d(x, 256, 3, activation='relu', scope='conv3_3')
    x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool3')

    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv4_1')
    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv4_2')
    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv4_3')
    x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool4')

    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv5_1')
    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv5_2')
    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv5_3')
    x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool5')

    x = tflearn.fully_connected(x, 4096, activation='relu', scope='fc6')
    x = tflearn.dropout(x, 0.5, name='dropout1')

    x = tflearn.fully_connected(x, 4096, activation='relu', scope='fc7')
    x = tflearn.dropout(x, 0.5, name='dropout2')

    x = tflearn.fully_connected(x, softmax_size, activation='softmax',
                                scope='fc8', restore=restore_softmax)

    return x
Exemplo n.º 38
0
def vgg16(placeholderX=None):

    x = tflearn.input_data(shape=[None, 224, 224, 3], name='input',
                           placeholder=placeholderX)

    x = tflearn.conv_2d(x, 64, 3, activation='relu', scope='conv1_1')
    x = tflearn.conv_2d(x, 64, 3, activation='relu', scope='conv1_2')
    x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool1')

    x = tflearn.conv_2d(x, 128, 3, activation='relu', scope='conv2_1')
    x = tflearn.conv_2d(x, 128, 3, activation='relu', scope='conv2_2')
    x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool2')

    x = tflearn.conv_2d(x, 256, 3, activation='relu', scope='conv3_1')
    x = tflearn.conv_2d(x, 256, 3, activation='relu', scope='conv3_2')
    x = tflearn.conv_2d(x, 256, 3, activation='relu', scope='conv3_3')
    x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool3')

    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv4_1')
    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv4_2')
    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv4_3')
    x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool4')

    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv5_1')
    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv5_2')
    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv5_3')
    x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool5')

    x = tflearn.fully_connected(x, 4096, activation='relu', scope='fc6')
    x = tflearn.dropout(x, 0.5, name='dropout1')

    x = tflearn.fully_connected(x, 4096, activation='relu', scope='fc7')
    x = tflearn.dropout(x, 0.5, name='dropout2')

    x = tflearn.fully_connected(x, 1000, activation='softmax', scope='fc8')

    return x
Exemplo n.º 39
0
def vgg16(input, num_class):

    #in the model, we added trainable=False to make sure the parameter are not updated during training
    x = tflearn.conv_2d(input, 64, 3, activation='relu', scope='conv1_1',trainable=False)
    x = tflearn.conv_2d(x, 64, 3, activation='relu', scope='conv1_2',trainable=False)
    x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool1')

    x = tflearn.conv_2d(x, 128, 3, activation='relu', scope='conv2_1',trainable=False)
    x = tflearn.conv_2d(x, 128, 3, activation='relu', scope='conv2_2',trainable=False)
    x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool2')

    x = tflearn.conv_2d(x, 256, 3, activation='relu', scope='conv3_1',trainable=False)
    x = tflearn.conv_2d(x, 256, 3, activation='relu', scope='conv3_2',trainable=False)
    x = tflearn.conv_2d(x, 256, 3, activation='relu', scope='conv3_3',trainable=False)
    x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool3')

    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv4_1',trainable=False)
    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv4_2',trainable=False)
    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv4_3',trainable=False)
    x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool4')

    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv5_1')
    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv5_2')
    x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv5_3')
    x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool5')

    x = tflearn.fully_connected(x, 4096, activation='relu', scope='fc6')
    x = tflearn.dropout(x, 0.5, name='dropout1')
    #we changed the structure here to let the fc only have 2048, less parameter, enough for our task
    x = tflearn.fully_connected(x, 2048, activation='relu', scope='fc7',restore=False)
    x = tflearn.dropout(x, 0.5, name='dropout2')

    x = tflearn.fully_connected(x, num_class, activation='softmax', scope='fc8',
                                restore=False)

    return x
Exemplo n.º 40
0
    def test_feed_dict_no_None(self):

        X = [[0., 0., 0., 0.], [1., 1., 1., 1.], [0., 0., 1., 0.], [1., 1., 1., 0.]]
        Y = [[1., 0.], [0., 1.], [1., 0.], [0., 1.]]

        with tf.Graph().as_default():
            g = tflearn.input_data(shape=[None, 4], name="X_in")
            g = tflearn.reshape(g, new_shape=[-1, 2, 2, 1])
            g = tflearn.conv_2d(g, 4, 2)
            g = tflearn.conv_2d(g, 4, 1)
            g = tflearn.max_pool_2d(g, 2)
            g = tflearn.fully_connected(g, 2, activation='softmax')
            g = tflearn.regression(g, optimizer='sgd', learning_rate=1.)

            m = tflearn.DNN(g)

            def do_fit():
                m.fit({"X_in": X, 'non_existent': X}, Y, n_epoch=30, snapshot_epoch=False)
            self.assertRaisesRegexp(Exception, "Feed dict asks for variable named 'non_existent' but no such variable is known to exist", do_fit)
Exemplo n.º 41
0
# Real-time data preprocessing
img_prep = ImagePreprocessing()
img_prep.add_featurewise_zero_center()
img_prep.add_featurewise_stdnorm()

# Real-time data augmentation
img_aug = ImageAugmentation()
img_aug.add_random_flip_leftright()
# img_aug.add_random_rotation(max_angle=25.)

# Convolutional network building

# from fractal_block import tensor_shape, fractal_block

network = input_data(shape=[None, 32, 32, 3],
                     data_preprocessing=img_prep,
                     data_augmentation=img_aug)
for block, filters in enumerate([64,128,256,512,512]):
    network = fractal_block(network, filters, 2, 2, joined=True)
    network = tflearn.max_pool_2d(network, 2)

network = fully_connected(network, 10, activation='softmax')
network = regression(network, optimizer='adam',
                     loss='categorical_crossentropy',
                     learning_rate=0.001)

# Train using classifier
model = tflearn.DNN(network, tensorboard_verbose=0)
model.fit(X, Y, n_epoch=500, shuffle=True, validation_set=(X_test, Y_test),
          show_metric=True, batch_size=256, run_id='cifar10')
Exemplo n.º 42
0
# Using MNIST Dataset
import tflearn.datasets.mnist as mnist
mnist_data = mnist.read_data_sets(one_hot=True)

# User defined placeholders
with tf.Graph().as_default():
    # Placeholders for data and labels
    X = tf.placeholder(shape=(None, 784), dtype=tf.float32)
    Y = tf.placeholder(shape=(None, 10), dtype=tf.float32)

    net = tf.reshape(X, [-1, 28, 28, 1])

    # Using TFLearn wrappers for network building
    net = tflearn.conv_2d(net, 32, 3, activation='relu')
    net = tflearn.max_pool_2d(net, 2)
    net = tflearn.local_response_normalization(net)
    net = tflearn.dropout(net, 0.8)
    net = tflearn.conv_2d(net, 64, 3, activation='relu')
    net = tflearn.max_pool_2d(net, 2)
    net = tflearn.local_response_normalization(net)
    net = tflearn.dropout(net, 0.8)
    net = tflearn.fully_connected(net, 128, activation='tanh')
    net = tflearn.dropout(net, 0.8)
    net = tflearn.fully_connected(net, 256, activation='tanh')
    net = tflearn.dropout(net, 0.8)
    net = tflearn.fully_connected(net, 10, activation='softmax')

    # Defining other ops using Tensorflow
    loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(net, Y))
    optimizer = tf.train.AdamOptimizer(learning_rate=0.01).minimize(loss)
Exemplo n.º 43
0
def get_cae():
	# import tensorflow as tf
	# with tf.device('/gpu:1'):
	encoder = tflearn.input_data(shape=[None, 256, 256, 20], name='input')
	# encoder = encoder/255.0
	num_filter = 10*20
	encoder = tflearn.conv_2d(encoder, 20, 7, activation='relu', regularizer='L1')
	# encoder = tflearn.conv_2d(encoder, 20, 3, activation='relu', regularizer='L1')
	

	encoder = tflearn.conv_2d(encoder, num_filter*1, 3, activation='relu', regularizer='L1')
	encoder = tflearn.residual_block(encoder, 2, num_filter*1, batch_norm=False, regularizer='L1')
	scale_0 = encoder
	# encoder = tflearn.layers.normalization.batch_normalization(encoder)
	encoder = tflearn.max_pool_2d(encoder, 2)
	# encoder = tflearn.dropout(encoder, 0.75)


	encoder = tflearn.conv_2d(encoder, num_filter*2, 3, activation='relu', regularizer='L1')
	encoder = tflearn.residual_block(encoder, 2, num_filter*2, batch_norm=False, regularizer='L1')
	scale_1 = encoder
	# encoder = tflearn.layers.normalization.batch_normalization(encoder)
	encoder = tflearn.max_pool_2d(encoder, 2)
	# encoder = tflearn.dropout(encoder, 0.75)


	encoder = tflearn.conv_2d(encoder, num_filter*4, 3, activation='relu', regularizer='L1')
	encoder = tflearn.residual_block(encoder, 2, num_filter*4, batch_norm=False, regularizer='L1')
	scale_2 = encoder
	# encoder = tflearn.layers.normalization.batch_normalization(encoder)
	encoder = tflearn.max_pool_2d(encoder, 2)
	# encoder = tflearn.dropout(encoder, 0.75)
	

	encoder = tflearn.conv_2d(encoder, num_filter*8, 3, activation='relu', regularizer='L1')
	encoder = tflearn.residual_block(encoder, 2, num_filter*8, batch_norm=False, regularizer='L1')
	scale_3 = encoder
	# encoder = tflearn.layers.normalization.batch_normalization(encoder)
	encoder = tflearn.max_pool_2d(encoder, 2)
	# encoder = tflearn.dropout(encoder, 0.75)


	
	encoder = tflearn.conv_2d(encoder, num_filter*12, 3, activation='relu', regularizer='L1')
	encoder = tflearn.residual_block(encoder, 2, num_filter*16, batch_norm=False, regularizer='L1')
	# encoder = tflearn.layers.normalization.batch_normalization(encoder)

	decoder = encoder
	# decoder = tflearn.conv_2d_transpose(decoder, 
	# 								 nb_filter=num_filter*12, 
	# 								 filter_size=3, 
	# 								 activation='relu',
	# 								 regularizer='L1',
	# 								 output_shape=[16, 16])
	



	# decoder = tflearn.upsample_2d(decoder, 2)
	decoder = tflearn.layers.conv.upscore_layer(decoder, 
						 num_classes=256, 
						 kernel_size=3, 
						 shape=[1, 32, 32, num_filter*8]
						 ) 
	decoder = tflearn.conv_2d(decoder, num_filter*8, 3, activation='relu', regularizer='L1')
	# decoder = tflearn.residual_block(decoder, 1, num_filter*8, batch_norm=False, regularizer='L1')
	# decoder = tflearn.conv_2d_transpose(decoder, 
	# 								 nb_filter=num_filter*8, 
	# 								 filter_size=3, 
	# 								 activation='relu', 
	# 								 regularizer='L1',
	# 								 output_shape=[32, 32])
	# decoder = tflearn.layers.normalization.batch_normalization(decoder)
	# decoder = decoder + scale_3
	decoder = merge([decoder, scale_3], mode='elemwise_sum', axis=3)

	
	# decoder = tflearn.dropout(decoder, 0.75)
	# decoder = tflearn.upsample_2d(decoder, 2)
	decoder = tflearn.layers.conv.upscore_layer(decoder, 
							 num_classes=256, 
							 kernel_size=3, 
							 shape=[1, 64, 64, num_filter*4]
							 ) 
	decoder = tflearn.conv_2d(decoder, num_filter*4, 3, activation='relu', regularizer='L1')
	# decoder = tflearn.residual_block(decoder, 1, num_filter*4, batch_norm=False, regularizer='L1')
	# decoder = tflearn.conv_2d_transpose(decoder, 
	# 								 nb_filter=num_filter*4, 
	# 								 filter_size=3, 
	# 								 activation='relu',
	# 								 regularizer='L1',
	# 								 output_shape=[64, 64])
	# decoder = tflearn.layers.normalization.batch_normalization(decoder)
	# decoder = decoder + scale_2
	decoder = merge([decoder, scale_2], mode='elemwise_sum', axis=3)
	# decoder = tflearn.dropout(decoder, 0.75)
	# decoder = tflearn.upsample_2d(decoder, 2)
	decoder = tflearn.layers.conv.upscore_layer(decoder, 
							 num_classes=256, 
							 kernel_size=3, 
							 shape=[1, 128, 128, num_filter*2]
							 ) 
	decoder = tflearn.conv_2d(decoder, num_filter*2, 3, activation='relu', regularizer='L1')
	# decoder = tflearn.residual_block(decoder, 1, num_filter*2, batch_norm=False, regularizer='L1')
	# decoder = tflearn.conv_2d_transpose(decoder, 
	# 								 nb_filter=num_filter*2, 
	# 								 filter_size=3, 
	# 								 activation='relu',
	# 								 regularizer='L1',
	# 								 output_shape=[128, 128])
	# decoder = tflearn.layers.normalization.batch_normalization(decoder)
	# decoder = decoder + scale_1
	decoder = merge([decoder, scale_1], mode='elemwise_sum', axis=3)
	# decoder = tflearn.dropout(decoder, 0.75)
	# decoder = tflearn.upsample_2d(decoder, 2)
	decoder = tflearn.layers.conv.upscore_layer(decoder, 
							 num_classes=256, 
							 kernel_size=3, 
							 shape=[1, 256, 256, num_filter*1]
							 ) 
	decoder = tflearn.conv_2d(decoder, num_filter*1, 3, activation='relu', regularizer='L1')
	# decoder = tflearn.residual_block(decoder, 1, num_filter*1, batch_norm=False, regularizer='L1')
	# decoder = tflearn.conv_2d_transpose(decoder, 
	# 								 nb_filter=num_filter*1, 
	# 								 filter_size=3, 
	# 								 activation='relu',
	# 								 regularizer='L1',
	# 								 output_shape=[256, 256])
	# decoder = tflearn.layers.normalization.batch_normalization(decoder)
	# decoder = decoder + scale_0
	decoder = merge([decoder, scale_0], mode='elemwise_sum', axis=3)
	# decoder = tflearn.dropout(decoder, 0.75) 
	
	decoder = tflearn.conv_2d(decoder, 20, 1, activation='relu', regularizer='L1')
	# decoder = tflearn.conv_2d_transpose(decoder, 
	# 								 nb_filter=20, 
	# 								 filter_size=3, 
	# 								 activation='relu',
	# 								 regularizer='L1',
	# 								 output_shape=[256, 256])
	
	# decoder = tf.round(decoder)
	decoder = tf.clip_by_value(decoder, 0, 255)
	
	return decoder
Exemplo n.º 44
0
'''
Coding Just for Fun
Created by burness on 16/8/31.
'''
import tflearn
from tflearn.layers.estimator import regression

x = tflearn.input_data(shape=[None, 224, 224, 3], name='input',
                       placeholder=None)

x = tflearn.conv_2d(x, 64, 3, activation='relu', scope='conv1_1')
x = tflearn.conv_2d(x, 64, 3, activation='relu', scope='conv1_2')
x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool1')

x = tflearn.conv_2d(x, 128, 3, activation='relu', scope='conv2_1')
x = tflearn.conv_2d(x, 128, 3, activation='relu', scope='conv2_2')
x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool2')

x = tflearn.conv_2d(x, 256, 3, activation='relu', scope='conv3_1')
x = tflearn.conv_2d(x, 256, 3, activation='relu', scope='conv3_2')
x = tflearn.conv_2d(x, 256, 3, activation='relu', scope='conv3_3')
x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool3')

x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv4_1')
x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv4_2')
x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv4_3')
x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool4')

x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv5_1')
x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv5_2')
x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv5_3')
def run():
    X = tf.placeholder(shape=(None, 784), dtype=tf.float32)
    Y = tf.placeholder(shape=(None, 10), dtype=tf.float32)

    net = tf.reshape(X, [-1, 28, 28, 1])  # batch, height, width, chnl

    # 32 filters, each of size 3(x3)
    net = tflearn.conv_2d(net, 32, 3, activation='relu')
    # pool kernel size 2, stride size default kernel soze
    net = tflearn.max_pool_2d(net, 2)
    # for "encourage some kind of inhibition and boost the neurons with
    # relatively larger activations"
    net = tflearn.local_response_normalization(net)
    # The dropout method is introduced to prevent overfitting. At each training stage, individual nodes are either "dropped out" of the net with probability {\displaystyle 1-p} 1-p or kept with probability {\displaystyle p} p, so that a reduced network is left
    # keep_prob=0.8
    net = tflearn.dropout(net, 0.8)

    # 64 filters
    net = tflearn.conv_2d(net, 64, 3, activation='relu')
    net = tflearn.max_pool_2d(net, 2)
    net = tflearn.local_response_normalization(net)
    net = tflearn.dropout(net, 0.8)

    # FC
    net = tflearn.fully_connected(net, 128, activation='tanh')
    net = tflearn.dropout(net, 0.8)
    net = tflearn.fully_connected(net, 256, activation='tanh')
    net = tflearn.dropout(net, 0.8)
    net = tflearn.fully_connected(net, 10, activation='softmax')

    # --------------------------------------
    # really manual tf way
    # # Defining other ops using Tensorflow
    # loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(net, Y))
    # optimizer = tf.train.AdamOptimizer(learning_rate=0.01)
    # optimizer_minop = optimizer.minimize(loss)

    # # start
    # init = tf.initialize_all_variables()

    # with tf.Session() as sess:
    #     sess.run(init)
    #     batch_size = 128
    #     for epoch in range(2):
    #         avg_cost = 0.
    #         total_batch = int(mnist_data.train.num_examples/batch_size)
    #         for i in range(total_batch):
    #             batch_xs, batch_ys = mnist_data.train.next_batch(batch_size)
    #             sess.run(optimizer_minop, feed_dict={X: batch_xs, Y: batch_ys})
    #             cost = sess.run(loss, feed_dict={X: batch_xs, Y: batch_ys})
    #             avg_cost += cost/total_batch
    #             if i % 20 == 0:
    #                 print("Epoch:", '%03d' % (epoch+1), "Step:", '%03d' % i,
    #                       "Loss:", str(cost))

    # --------------------------------------
    # use trainer class
    loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(net, Y))
    optimizer = tf.train.AdamOptimizer(learning_rate=0.01)
    accuracy = tf.reduce_mean(tf.cast(
        tf.equal(tf.argmax(net, 1), tf.argmax(Y, 1)),
        tf.float32), name='acc')

    trainop = tflearn.TrainOp(loss=loss, optimizer=optimizer,
                              metric=accuracy, batch_size=128)

    trainer = tflearn.Trainer(train_ops=trainop, tensorboard_verbose=0)
    trainer.fit({X: trainX, Y: trainY}, val_feed_dicts={
                X: testX, Y: testY}, n_epoch=2, show_metric=True)
    trainer.save('models/mnist_cnn.tfl')