Python tflearn.conv_2d() Examples

The following are 30 code examples of tflearn.conv_2d(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module tflearn , or try the search function .
Example #1
Source File: models.py    From pygta5 with GNU General Public License v3.0 8 votes vote down vote up
def resnext(width, height, frame_count, lr, output=9, model_name = 'sentnet_color.model'):
    net = input_data(shape=[None, width, height, 3], name='input')
    net = tflearn.conv_2d(net, 16, 3, regularizer='L2', weight_decay=0.0001)
    net = tflearn.layers.conv.resnext_block(net, n, 16, 32)
    net = tflearn.resnext_block(net, 1, 32, 32, downsample=True)
    net = tflearn.resnext_block(net, n-1, 32, 32)
    net = tflearn.resnext_block(net, 1, 64, 32, downsample=True)
    net = tflearn.resnext_block(net, n-1, 64, 32)
    net = tflearn.batch_normalization(net)
    net = tflearn.activation(net, 'relu')
    net = tflearn.global_avg_pool(net)
    # Regression
    net = tflearn.fully_connected(net, output, activation='softmax')
    opt = tflearn.Momentum(0.1, lr_decay=0.1, decay_step=32000, staircase=True)
    net = tflearn.regression(net, optimizer=opt,
                             loss='categorical_crossentropy')

    model = tflearn.DNN(net,
                        max_checkpoints=0, tensorboard_verbose=0, tensorboard_dir='log')

    return model 
Example #2
Source File: cnn.py    From QARC with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def CNN_Core(x, reuse=False):
    with tf.variable_scope('cnn_core', reuse=reuse):
        network = tflearn.conv_2d(
            x, KERNEL, 5, activation='relu', regularizer="L2", weight_decay=0.0001)
        network = tflearn.max_pool_2d(network, 2)
        network = tflearn.conv_2d(
            network, KERNEL, 3, activation='relu', regularizer="L2", weight_decay=0.0001)
        network = tflearn.max_pool_2d(network, 2)
        network = tflearn.conv_2d(
            network, KERNEL, 3, activation='relu', regularizer="L2", weight_decay=0.0001)
        network = tflearn.max_pool_2d(network, 2)
        network = tflearn.conv_2d(
            network, KERNEL // 2, 3, activation='relu', regularizer="L2", weight_decay=0.0001)
        # network = tflearn.fully_connected(
        #   network, DENSE_SIZE, activation='relu')
        split_flat = tflearn.flatten(network)
        return split_flat 
Example #3
Source File: cnn.py    From QARC with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def vgg16(input, num_class):
    network = tflearn.conv_2d(
        input, KERNEL, 3, activation='relu', regularizer="L2", weight_decay=0.0001)
    network = tflearn.avg_pool_2d(network, 2)
    network = tflearn.conv_2d(
        network, KERNEL, 3, activation='relu', regularizer="L2", weight_decay=0.0001)
    network = tflearn.avg_pool_2d(network, 2)
    network = tflearn.conv_2d(
        network, KERNEL, 3, activation='relu', regularizer="L2", weight_decay=0.0001)
    network = tflearn.avg_pool_2d(network, 2)
    network = tflearn.conv_2d(
        network, KERNEL, 3, activation='relu', regularizer="L2", weight_decay=0.0001)
    network = tflearn.avg_pool_2d(network, 2)

    x = tflearn.fully_connected(
        network, num_class, activation='sigmoid', scope='fc8')
    return x 
Example #4
Source File: atari_1step_qlearning.py    From FRU with MIT License 6 votes vote down vote up
def build_dqn(num_actions, action_repeat):
    """
    Building a DQN.
    """
    inputs = tf.placeholder(tf.float32, [None, action_repeat, 84, 84])
    # Inputs shape: [batch, channel, height, width] need to be changed into
    # shape [batch, height, width, channel]
    net = tf.transpose(inputs, [0, 2, 3, 1])
    net = tflearn.conv_2d(net, 32, 8, strides=4, activation='relu')
    net = tflearn.conv_2d(net, 64, 4, strides=2, activation='relu')
    net = tflearn.fully_connected(net, 256, activation='relu')
    q_values = tflearn.fully_connected(net, num_actions)
    return inputs, q_values


# =============================
#   ATARI Environment Wrapper
# ============================= 
Example #5
Source File: models.py    From pygta5 with GNU General Public License v3.0 6 votes vote down vote up
def resnext(width, height, frame_count, lr, output=9, model_name = 'sentnet_color.model'):
    net = input_data(shape=[None, width, height, 3], name='input')
    net = tflearn.conv_2d(net, 16, 3, regularizer='L2', weight_decay=0.0001)
    net = tflearn.layers.conv.resnext_block(net, n, 16, 32)
    net = tflearn.resnext_block(net, 1, 32, 32, downsample=True)
    net = tflearn.resnext_block(net, n-1, 32, 32)
    net = tflearn.resnext_block(net, 1, 64, 32, downsample=True)
    net = tflearn.resnext_block(net, n-1, 64, 32)
    net = tflearn.batch_normalization(net)
    net = tflearn.activation(net, 'relu')
    net = tflearn.global_avg_pool(net)
    # Regression
    net = tflearn.fully_connected(net, output, activation='softmax')
    opt = tflearn.Momentum(0.1, lr_decay=0.1, decay_step=32000, staircase=True)
    net = tflearn.regression(net, optimizer=opt,
                             loss='categorical_crossentropy')

    model = tflearn.DNN(net,
                        max_checkpoints=0, tensorboard_verbose=0, tensorboard_dir='log')

    return model 
Example #6
Source File: a3c.py    From QARC with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def create_critic_network(self):
        with tf.variable_scope('critic'):
            inputs = tflearn.input_data(
                shape=[None, self.s_dim[0], self.s_dim[1]])
            _input = tf.expand_dims(inputs, -1)

            merge_net = tflearn.conv_2d(
                _input, FEATURE_NUM, KERNEL, activation='relu')
            merge_net = tflearn.conv_2d(
                merge_net, FEATURE_NUM, KERNEL, activation='relu')

            avg_net = tflearn.global_avg_pool(merge_net)
            # dense_net_0 = tflearn.fully_connected(
            #    merge_net, 64, activation='relu')
            #dense_net_0 = tflearn.dropout(dense_net_0, 0.8)
            out = tflearn.fully_connected(avg_net, 1, activation='linear')

            return inputs, out 
Example #7
Source File: models.py    From pygta5 with GNU General Public License v3.0 6 votes vote down vote up
def resnext(width, height, frame_count, lr, output=9, model_name = 'sentnet_color.model'):
    net = input_data(shape=[None, width, height, 3], name='input')
    net = tflearn.conv_2d(net, 16, 3, regularizer='L2', weight_decay=0.0001)
    net = tflearn.layers.conv.resnext_block(net, n, 16, 32)
    net = tflearn.resnext_block(net, 1, 32, 32, downsample=True)
    net = tflearn.resnext_block(net, n-1, 32, 32)
    net = tflearn.resnext_block(net, 1, 64, 32, downsample=True)
    net = tflearn.resnext_block(net, n-1, 64, 32)
    net = tflearn.batch_normalization(net)
    net = tflearn.activation(net, 'relu')
    net = tflearn.global_avg_pool(net)
    # Regression
    net = tflearn.fully_connected(net, output, activation='softmax')
    opt = tflearn.Momentum(0.1, lr_decay=0.1, decay_step=32000, staircase=True)
    net = tflearn.regression(net, optimizer=opt,
                             loss='categorical_crossentropy')

    model = tflearn.DNN(net,
                        max_checkpoints=0, tensorboard_verbose=0, tensorboard_dir='log')

    return model 
Example #8
Source File: cnn.py    From QARC with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def vgg16(input, num_class):
    network = tflearn.conv_2d(
        input, KERNEL, 3, activation='relu', regularizer="L2", weight_decay=0.0001)
    network = tflearn.avg_pool_2d(network, 2)
    network = tflearn.conv_2d(
        network, KERNEL, 3, activation='relu', regularizer="L2", weight_decay=0.0001)
    network = tflearn.avg_pool_2d(network, 2)
    network = tflearn.conv_2d(
        network, KERNEL, 3, activation='relu', regularizer="L2", weight_decay=0.0001)
    network = tflearn.avg_pool_2d(network, 2)
    network = tflearn.conv_2d(
        network, KERNEL, 3, activation='relu', regularizer="L2", weight_decay=0.0001)
    network = tflearn.avg_pool_2d(network, 2)

    x = tflearn.fully_connected(
        network, num_class, activation='sigmoid', scope='fc8')
    return x 
Example #9
Source File: cnn.py    From QARC with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def CNN_Core(x, reuse=False):
    with tf.variable_scope('cnn_core', reuse=reuse):
        network = tflearn.conv_2d(
            x, KERNEL, 5, activation='relu', regularizer="L2", weight_decay=0.0001)
        network = tflearn.max_pool_2d(network, 2)
        network = tflearn.conv_2d(
            network, KERNEL, 3, activation='relu', regularizer="L2", weight_decay=0.0001)
        network = tflearn.max_pool_2d(network, 2)
        network = tflearn.conv_2d(
            network, KERNEL, 3, activation='relu', regularizer="L2", weight_decay=0.0001)
        network = tflearn.max_pool_2d(network, 2)
        network = tflearn.conv_2d(
            network, KERNEL // 2, 3, activation='relu', regularizer="L2", weight_decay=0.0001)
        # network = tflearn.fully_connected(
        #   network, DENSE_SIZE, activation='relu')
        split_flat = tflearn.flatten(network)
        return split_flat 
Example #10
Source File: models.py    From pygta5 with GNU General Public License v3.0 6 votes vote down vote up
def resnext(width, height, frame_count, lr, output=9, model_name = 'sentnet_color.model'):
    net = input_data(shape=[None, width, height, 3], name='input')
    net = tflearn.conv_2d(net, 16, 3, regularizer='L2', weight_decay=0.0001)
    net = tflearn.layers.conv.resnext_block(net, n, 16, 32)
    net = tflearn.resnext_block(net, 1, 32, 32, downsample=True)
    net = tflearn.resnext_block(net, n-1, 32, 32)
    net = tflearn.resnext_block(net, 1, 64, 32, downsample=True)
    net = tflearn.resnext_block(net, n-1, 64, 32)
    net = tflearn.batch_normalization(net)
    net = tflearn.activation(net, 'relu')
    net = tflearn.global_avg_pool(net)
    # Regression
    net = tflearn.fully_connected(net, output, activation='softmax')
    opt = tflearn.Momentum(0.1, lr_decay=0.1, decay_step=32000, staircase=True)
    net = tflearn.regression(net, optimizer=opt,
                             loss='categorical_crossentropy')

    model = tflearn.DNN(net,
                        max_checkpoints=0, tensorboard_verbose=0, tensorboard_dir='log')

    return model 
Example #11
Source File: a3c.py    From QARC with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def create_critic_network(self):
        with tf.variable_scope('critic'):
            inputs = tflearn.input_data(
                shape=[None, self.s_dim[0], self.s_dim[1]])
            _input = tf.expand_dims(inputs, -1)

            merge_net = tflearn.conv_2d(
                _input, FEATURE_NUM, KERNEL, activation='relu')
            merge_net = tflearn.conv_2d(
                merge_net, FEATURE_NUM, KERNEL, activation='relu')

            avg_net = tflearn.global_avg_pool(merge_net)
            # dense_net_0 = tflearn.fully_connected(
            #    merge_net, 64, activation='relu')
            #dense_net_0 = tflearn.dropout(dense_net_0, 0.8)
            out = tflearn.fully_connected(avg_net, 1, activation='linear')

            return inputs, out 
Example #12
Source File: a3c.py    From QARC with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def create_actor_network(self):
        with tf.variable_scope('actor'):
            inputs = tflearn.input_data(
                shape=[None, self.s_dim[0], self.s_dim[1]])
            _input = tf.expand_dims(inputs, -1)

            merge_net = tflearn.conv_2d(
                _input, FEATURE_NUM, KERNEL, activation='relu')
            merge_net = tflearn.conv_2d(
                merge_net, FEATURE_NUM, KERNEL, activation='relu')

            avg_net = tflearn.global_avg_pool(merge_net)
            out = tflearn.fully_connected(
                avg_net, self.a_dim, activation='softmax')

            return inputs, out 
Example #13
Source File: vgg16.py    From models with MIT License 5 votes vote down vote up
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 
Example #14
Source File: vqn.py    From QARC with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def CNN_Core(x,reuse=False):
    with tf.variable_scope('cnn_core',reuse=reuse):
        network = tflearn.conv_2d(
            x, KERNEL, 5, activation='relu', regularizer="L2",weight_decay=0.0001)
        network = tflearn.max_pool_2d(network, 2)
        network = tflearn.conv_2d(
        network, KERNEL, 3, activation='relu', regularizer="L2",weight_decay=0.0001)
        network = tflearn.max_pool_2d(network, 2)
        #network = tflearn.fully_connected(
        #   network, DENSE_SIZE, activation='relu')
        split_flat = tflearn.flatten(network)
        return split_flat 
Example #15
Source File: vqpn.py    From QARC with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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.avg_pool_2d(network, 3)
        network = tflearn.conv_2d(
        network, KERNEL, 3, activation='relu', regularizer="L2",weight_decay=0.0001)
        network = tflearn.avg_pool_2d(network, 2)
        network = tflearn.fully_connected(
           network, DENSE_SIZE, activation='relu')
        split_flat = tflearn.flatten(network)
        return split_flat 
Example #16
Source File: convert_VQPN.py    From QARC with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def CNN_Core(self, x, reuse=False):
        with tf.variable_scope('cnn_core', reuse=reuse):
            network = tflearn.conv_2d(
                x, KERNEL, 5, activation='relu', regularizer="L2", weight_decay=0.0001)
            network = tflearn.avg_pool_2d(network, 3)
            network = tflearn.conv_2d(
                network, KERNEL, 3, activation='relu', regularizer="L2", weight_decay=0.0001)
            network = tflearn.avg_pool_2d(network, 2)
            network = tflearn.fully_connected(
                network, DENSE_SIZE, activation='relu')
            split_flat = tflearn.flatten(network)
            return split_flat 
Example #17
Source File: vqn-cnn.py    From QARC with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def CNN_Core(x, reuse=False):
    with tf.variable_scope('cnn_core', reuse=reuse):
        network = tflearn.conv_2d(
            x, KERNEL, 5, activation='relu', regularizer="L2", weight_decay=0.0001)
        network = tflearn.avg_pool_2d(network, 3)
        network = tflearn.conv_2d(
            network, KERNEL, 3, activation='relu', regularizer="L2", weight_decay=0.0001)
        network = tflearn.avg_pool_2d(network, 2)
        network = tflearn.fully_connected(
            network, DENSE_SIZE, activation='relu')
        split_flat = tflearn.flatten(network)
        return split_flat 
Example #18
Source File: innovation_env.py    From QARC with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def CNN_Core(self, x, reuse=False):
        with tf.variable_scope('cnn_core', reuse=reuse):
            network = tflearn.conv_2d(
                x, KERNEL, 5, activation='relu', regularizer="L2", weight_decay=0.0001)
            network = tflearn.avg_pool_2d(network, 3)
            network = tflearn.conv_2d(
                network, KERNEL, 3, activation='relu', regularizer="L2", weight_decay=0.0001)
            network = tflearn.avg_pool_2d(network, 2)
            network = tflearn.fully_connected(
                network, DENSE_SIZE, activation='relu')
            split_flat = tflearn.flatten(network)
            return split_flat 
Example #19
Source File: johnson.py    From TensorFlowBook with Apache License 2.0 5 votes vote down vote up
def generator(input_image):
    relu = tf.nn.relu
    conv2d = tflearn.conv_2d

    def batch_norm(x):
        mean, var = tf.nn.moments(x, axes=[1, 2, 3])
        return tf.nn.batch_normalization(x, mean, var, 0, 1, 1e-5)

    def deconv2d(x, n_filter, ksize, strides=1):
        _, h, w, _ = x.get_shape().as_list()
        output_shape = [strides * h, strides * w]
        return tflearn.conv_2d_transpose(x, n_filter, ksize, output_shape,
                                         strides)

    def res_block(x):
        net = relu(batch_norm(conv2d(x, 128, 3)))
        net = batch_norm(conv2d(net, 128, 3))
        return x + net

    net = relu(batch_norm(conv2d(input_image, 32, 9)))
    net = relu(batch_norm(conv2d(net, 64, 4, strides=2)))
    net = relu(batch_norm(conv2d(net, 128, 4, strides=2)))
    for i in range(5):
        net = res_block(net)
    net = relu(batch_norm(deconv2d(net, 64, 4, strides=2)))
    net = relu(batch_norm(deconv2d(net, 32, 4, strides=2)))
    net = deconv2d(net, 3, 9)
    return net 
Example #20
Source File: manager.py    From Fruit-API with GNU General Public License v3.0 5 votes vote down vote up
def create_conv_layer(self, input_data, num_of_filters, filter_size, strides,
                          activation_fn='relu', padding='valid', permutation=None, scope=None):
        if permutation is not None:
            input_data = tf.transpose(input_data, permutation)
        conv = tflearn.conv_2d(input_data, nb_filter=num_of_filters, filter_size=filter_size, strides=strides,
                               activation=activation_fn, padding=padding, scope=scope)
        self.hiddens.append(conv)
        self.num_of_hidden_layers += 1
        return conv 
Example #21
Source File: vgg_network_finetuning.py    From FRU with MIT License 5 votes vote down vote up
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 
Example #22
Source File: dcgan.py    From FRU with MIT License 5 votes vote down vote up
def generator(x, reuse=False):
    with tf.variable_scope('Generator', reuse=reuse):
        x = tflearn.fully_connected(x, n_units=7 * 7 * 128)
        x = tflearn.batch_normalization(x)
        x = tf.nn.tanh(x)
        x = tf.reshape(x, shape=[-1, 7, 7, 128])
        x = tflearn.upsample_2d(x, 2)
        x = tflearn.conv_2d(x, 64, 5, activation='tanh')
        x = tflearn.upsample_2d(x, 2)
        x = tflearn.conv_2d(x, 1, 5, activation='sigmoid')
        return x


# Discriminator 
Example #23
Source File: dcgan.py    From FRU with MIT License 5 votes vote down vote up
def discriminator(x, reuse=False):
    with tf.variable_scope('Discriminator', reuse=reuse):
        x = tflearn.conv_2d(x, 64, 5, activation='tanh')
        x = tflearn.avg_pool_2d(x, 2)
        x = tflearn.conv_2d(x, 128, 5, activation='tanh')
        x = tflearn.avg_pool_2d(x, 2)
        x = tflearn.fully_connected(x, 1024, activation='tanh')
        x = tflearn.fully_connected(x, 2)
        x = tf.nn.softmax(x)
        return x


# Input Data 
Example #24
Source File: test_layers.py    From FRU with MIT License 5 votes vote down vote up
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) 
Example #25
Source File: texture_net.py    From TensorFlowBook with Apache License 2.0 5 votes vote down vote up
def generator(input_image):
    conv2d = tflearn.conv_2d
    batch_norm = tflearn.batch_normalization
    relu = tf.nn.relu

    ratios = [16, 8, 4, 2, 1]
    n_filter = 8
    net = []

    for i in range(len(ratios)):
        net.append(tflearn.max_pool_2d(input_image, ratios[i], ratios[i]))
        # block_i_0, block_i_1, block_i_2
        for block in range(3):
            ksize = 1 if (block + 1) % 3 == 0 else 3
            net[i] = relu(batch_norm(conv2d(net[i], n_filter, ksize)))
        if i != 0:
            # concat with net[i-1]
            upnet = batch_norm(net[i - 1])
            downnet = batch_norm(net[i])
            net[i] = tf.concat(3, [upnet, downnet])
            # block_i_3, block_i_4, block_i_5
            for block in range(3, 6):
                ksize = 1 if (block + 1) % 3 == 0 else 3
                net[i] = conv2d(net[i], n_filter * (i + 1), ksize)
                net[i] = relu(batch_norm(net[i]))

        if i != len(ratios) - 1:
            # upsample for concat
            net[i] = tflearn.upsample_2d(net[i], 2)

    nn = len(ratios) - 1
    output = conv2d(net[nn], 3, 1)
    return output 
Example #26
Source File: model.py    From tensorflow2caffe with MIT License 5 votes vote down vote up
def vgg_net_19(width, height):
    network = input_data(shape=[None, height, width, 3], name='input')
    network = conv_2d(network, 64, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4)
    network = conv_2d(network, 64, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4)
    network = max_pool_2d(network, 2, strides=2)
    network = conv_2d(network, 128, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4)
    network = conv_2d(network, 128, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4)
    network = max_pool_2d(network, 2, strides=2)
    network = conv_2d(network, 256, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4)
    network = conv_2d(network, 256, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4)
    network = conv_2d(network, 256, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4)
    network = conv_2d(network, 256, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4)
    network = max_pool_2d(network, 2, strides=2)
    network = conv_2d(network, 512, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4)
    network = conv_2d(network, 512, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4)
    network = conv_2d(network, 512, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4)
    network = conv_2d(network, 512, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4)
    network = max_pool_2d(network, 2, strides=2)
    network = conv_2d(network, 512, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4)
    network = conv_2d(network, 512, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4)
    network = conv_2d(network, 512, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4)
    network = conv_2d(network, 512, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4)
    network = max_pool_2d(network, 2, strides=2)
    network = fully_connected(network, 4096, activation='relu', weight_decay=5e-4)
    network = dropout(network, keep_prob=0.5)
    network = fully_connected(network, 4096, activation='relu', weight_decay=5e-4)
    network = dropout(network, keep_prob=0.5)
    network = fully_connected(network, 1000, activation='softmax', weight_decay=5e-4)
    
    opt = Momentum(learning_rate=0, momentum = 0.9)
    network = regression(network, optimizer=opt, loss='categorical_crossentropy', name='targets')
    
    model = DNN(network, checkpoint_path='', max_checkpoints=1, tensorboard_verbose=2, tensorboard_dir='')
    
    return model

#model of vgg-19 for testing of the activations 
#rename the output you want to test, connect it to the next layer and change the output layer at the bottom (model = DNN(...))
#make sure to use the correct test function (depending if your output is a tensor or a vector) 
Example #27
Source File: models.py    From pygta5 with GNU General Public License v3.0 5 votes vote down vote up
def sentnet_color_2d(width, height, frame_count, lr, output=9, model_name = 'sentnet_color.model'):
    network = input_data(shape=[None, width, height, 3], name='input')
    network = conv_2d(network, 96, 11, strides=4, activation='relu')
    network = max_pool_2d(network, 3, strides=2)
    network = local_response_normalization(network)
    network = conv_2d(network, 256, 5, activation='relu')
    network = max_pool_2d(network, 3, strides=2)
    network = local_response_normalization(network)
    network = conv_2d(network, 384, 3, activation='relu')
    network = conv_2d(network, 384, 3, activation='relu')
    network = conv_2d(network, 256, 3, activation='relu')
    network = max_pool_2d(network, 3, strides=2)
    network = conv_2d(network, 256, 5, activation='relu')
    network = max_pool_2d(network, 3, strides=2)
    network = local_response_normalization(network)
    network = conv_2d(network, 384, 3, activation='relu')
    network = conv_2d(network, 384, 3, activation='relu')
    network = conv_2d(network, 256, 3, activation='relu')
    network = max_pool_2d(network, 3, strides=2)
    network = local_response_normalization(network)
    network = fully_connected(network, 4096, activation='tanh')
    network = dropout(network, 0.5)
    network = fully_connected(network, 4096, activation='tanh')
    network = dropout(network, 0.5)
    network = fully_connected(network, 4096, activation='tanh')
    network = dropout(network, 0.5)
    network = fully_connected(network, 4096, activation='tanh')
    network = dropout(network, 0.5)
    network = fully_connected(network, output, activation='softmax')
    network = regression(network, optimizer='momentum',
                         loss='categorical_crossentropy',
                         learning_rate=lr, name='targets')

    model = tflearn.DNN(network,
                        max_checkpoints=0, tensorboard_verbose=0, tensorboard_dir='log')

    return model 
Example #28
Source File: model.py    From tensorflow2caffe with MIT License 5 votes vote down vote up
def vgg_net_19_activations(width, height):
    network = input_data(shape=[None, height, width, 3], name='input')
    network1 = conv_2d(network, 64, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4)
    network2 = conv_2d(network1, 64, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4)
    network = max_pool_2d(network2, 2, strides=2)
    network = conv_2d(network, 128, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4)
    network = conv_2d(network, 128, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4)
    network = max_pool_2d(network, 2, strides=2)
    network = conv_2d(network, 256, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4)
    network = conv_2d(network, 256, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4)
    network = conv_2d(network, 256, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4)
    network = conv_2d(network, 256, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4)
    network = max_pool_2d(network, 2, strides=2)
    network = conv_2d(network, 512, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4)
    network = conv_2d(network, 512, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4)
    network = conv_2d(network, 512, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4)
    network = conv_2d(network, 512, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4)
    network = max_pool_2d(network, 2, strides=2)
    network = conv_2d(network, 512, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4)
    network = conv_2d(network, 512, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4)
    network = conv_2d(network, 512, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4)
    network = conv_2d(network, 512, 3, activation = 'relu', regularizer='L2', weight_decay=5e-4)
    network = max_pool_2d(network, 2, strides=2)
    network = fully_connected(network, 4096, activation='relu', weight_decay=5e-4)
    network = dropout(network, keep_prob=0.5)
    network = fully_connected(network, 4096, activation='relu', weight_decay=5e-4)
    network = dropout(network, keep_prob=0.5)
    network = fully_connected(network, 1000, activation='softmax', weight_decay=5e-4)
    
    opt = Momentum(learning_rate=0, momentum = 0.9)
    network = regression(network, optimizer=opt, loss='categorical_crossentropy', name='targets')
    
    model = DNN(network1, checkpoint_path='', max_checkpoints=1, tensorboard_verbose=2, tensorboard_dir='')
    
    return model 
Example #29
Source File: models.py    From pygta5 with GNU General Public License v3.0 5 votes vote down vote up
def sentnet_color_2d(width, height, frame_count, lr, output=9, model_name = 'sentnet_color.model'):
    network = input_data(shape=[None, width, height, 3], name='input')
    network = conv_2d(network, 96, 11, strides=4, activation='relu')
    network = max_pool_2d(network, 3, strides=2)
    network = local_response_normalization(network)
    network = conv_2d(network, 256, 5, activation='relu')
    network = max_pool_2d(network, 3, strides=2)
    network = local_response_normalization(network)
    network = conv_2d(network, 384, 3, activation='relu')
    network = conv_2d(network, 384, 3, activation='relu')
    network = conv_2d(network, 256, 3, activation='relu')
    network = max_pool_2d(network, 3, strides=2)
    network = conv_2d(network, 256, 5, activation='relu')
    network = max_pool_2d(network, 3, strides=2)
    network = local_response_normalization(network)
    network = conv_2d(network, 384, 3, activation='relu')
    network = conv_2d(network, 384, 3, activation='relu')
    network = conv_2d(network, 256, 3, activation='relu')
    network = max_pool_2d(network, 3, strides=2)
    network = local_response_normalization(network)
    network = fully_connected(network, 4096, activation='tanh')
    network = dropout(network, 0.5)
    network = fully_connected(network, 4096, activation='tanh')
    network = dropout(network, 0.5)
    network = fully_connected(network, 4096, activation='tanh')
    network = dropout(network, 0.5)
    network = fully_connected(network, 4096, activation='tanh')
    network = dropout(network, 0.5)
    network = fully_connected(network, output, activation='softmax')
    network = regression(network, optimizer='momentum',
                         loss='categorical_crossentropy',
                         learning_rate=lr, name='targets')

    model = tflearn.DNN(network,
                        max_checkpoints=0, tensorboard_verbose=0, tensorboard_dir='log')

    return model 
Example #30
Source File: models.py    From pygta5 with GNU General Public License v3.0 5 votes vote down vote up
def alexnet2(width, height, lr, output=3):
    network = input_data(shape=[None, width, height, 1], name='input')
    network = conv_2d(network, 96, 11, strides=4, activation='relu')
    network = max_pool_2d(network, 3, strides=2)
    network = local_response_normalization(network)
    network = conv_2d(network, 256, 5, activation='relu')
    network = max_pool_2d(network, 3, strides=2)
    network = local_response_normalization(network)
    network = conv_2d(network, 384, 3, activation='relu')
    network = conv_2d(network, 384, 3, activation='relu')
    network = conv_2d(network, 256, 3, activation='relu')
    network = max_pool_2d(network, 3, strides=2)
    network = conv_2d(network, 256, 5, activation='relu')
    network = max_pool_2d(network, 3, strides=2)
    network = local_response_normalization(network)
    network = conv_2d(network, 384, 3, activation='relu')
    network = conv_2d(network, 384, 3, activation='relu')
    network = conv_2d(network, 256, 3, activation='relu')
    network = max_pool_2d(network, 3, strides=2)
    network = local_response_normalization(network)
    network = fully_connected(network, 4096, activation='tanh')
    network = dropout(network, 0.5)
    network = fully_connected(network, 4096, activation='tanh')
    network = dropout(network, 0.5)
    network = fully_connected(network, 4096, activation='tanh')
    network = dropout(network, 0.5)
    network = fully_connected(network, 4096, activation='tanh')
    network = dropout(network, 0.5)
    network = fully_connected(network, output, activation='softmax')
    network = regression(network, optimizer='momentum',
                         loss='categorical_crossentropy',
                         learning_rate=lr, name='targets')

    model = tflearn.DNN(network, checkpoint_path='model_alexnet',
                        max_checkpoints=1, tensorboard_verbose=0, tensorboard_dir='log')

    return model