How to use the tensorflow.nn function in tensorflow

To help you get started, we’ve selected a few tensorflow examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github BII-wushuang / Lie-Group-Motion-Prediction / src / models.py View on Github external
else:
        seq_length_out = config.test_output_window

    # Inputs
    enc_in = tf.transpose(input, [1, 0, 2])
    dec_in = tf.transpose(dec_in, [1, 0, 2])

    enc_in = tf.reshape(enc_in, [-1, config.input_size])
    dec_in = tf.reshape(dec_in, [-1, config.input_size])

    enc_in = tf.split(enc_in, seq_length_in-1, axis=0)
    dec_in = tf.split(dec_in, seq_length_out, axis=0)

    if config.model == 'ERD':
        # Encoder
        fc = [tf.layers.dense(enc_in[i], 500,activation= tf.nn.relu,reuse=tf.AUTO_REUSE, name="fc") for i in range(config.input_window_size-1)]
        config.hidden_size = 1000
        hidden_size = [config.hidden_size, config.hidden_size]
        number_of_layers = len(hidden_size)

        def lstm_cell(size):
            cell = tf.contrib.rnn.LSTMCell(size)
            cell = tf.nn.rnn_cell.DropoutWrapper(cell, output_keep_prob=config.keep_prob)
            return cell

        enc_cells = [lstm_cell(hidden_size[i]) for i in range(number_of_layers)]
        enc_cell = tf.contrib.rnn.MultiRNNCell(enc_cells)
        output, final_state = tf.contrib.rnn.static_rnn(enc_cell, fc, dtype=tf.float32)
        enc_state = [(final_state[i][0], final_state[i][1]) for i in range(number_of_layers)]

        # Decoder
        dec_cell = [tf.nn.rnn_cell.LSTMCell(hidden_size[i]) for i in range(number_of_layers)]
github selcouthlyBlue / Tensorflow-OCR-Trainer / main / tfutils.py View on Github external
def _bidirectional_rnn_scan(cell_fw, cell_bw, inputs):
    with tf.variable_scope("BidirectionalRNN", [inputs, cell_fw, cell_bw]):
        height = inputs.get_shape().as_list()[1]
        inputs = images_to_sequence(inputs)
        outputs, output_states = tf.nn.bidirectional_dynamic_rnn(cell_fw, cell_bw, inputs, dtype=inputs.dtype)
        output_sequence = tf.concat(outputs, 2)
        output = sequence_to_images(output_sequence, height)
        return output
github psychopa4 / PFNL / model / frvsr.py View on Github external
for q in range(2):
                    x0=tf.layers.conv2d(x0, 32*(2**p), dk, padding='same', activation=activate,name='conv0_{}_{}'.format(p,q))
                x0=tf.layers.max_pooling2d(x0,pool_size=2,strides=2)

            n1,h1,w1,c1=x0.get_shape().as_list()
            for p in range(3):
                for q in range(2):
                    x0=tf.layers.conv2d(x0, 256*(0.5**p), dk, padding='same', activation=activate,name='conv1_{}_{}'.format(p,q))
                x0=tf.image.resize_images(x0,[h1*(2**(p+1)),w1*(2**(p+1))],method=0)
            
            n2,h2,w2,c2=x0.get_shape().as_list()
            if not (h==h2 and w==w2):
                x0=tf.image.resize_images(x0,[h,w],method=0)

            x0=tf.layers.conv2d(x0, 32, dk, padding='same', activation=activate,name='conv2')
            uv=tf.layers.conv2d(x0, 2, dk, padding='same', activation=tf.nn.tanh,name='conv3')

        return uv
github tau-yihouxiang / WS_DAN / train_sample.py View on Github external
def calculate_pooling_center_loss(features, label, alfa, nrof_classes, weights, name):
            features = tf.reshape(features, [features.shape[0], -1])
            label = tf.argmax(label, 1)

            nrof_features = features.get_shape()[1]
            centers = tf.get_variable(name, [nrof_classes, nrof_features], dtype=tf.float32,
                                      initializer=tf.constant_initializer(0), trainable=False)
            label = tf.reshape(label, [-1])
            centers_batch = tf.gather(centers, label)
            centers_batch = tf.nn.l2_normalize(centers_batch, axis=-1)

            diff = (1 - alfa) * (centers_batch - features)
            centers = tf.scatter_sub(centers, label, diff)

            with tf.control_dependencies([centers]):
                distance = tf.square(features - centers_batch)
                distance = tf.reduce_sum(distance, axis=-1)
                center_loss = tf.reduce_mean(distance)

            center_loss = tf.identity(center_loss * weights, name=name + '_loss')
            return center_loss
github wubinzzu / NeuRec / model / general_recommender / ConvNCF.py View on Github external
def _conv_layer(self, x, P):
        conv = tf.nn.conv2d(x, P[0], strides=[1, 2, 2, 1], padding='SAME')
        return tf.nn.tanh(conv + P[1])
github SpaceML / GalaxyGAN_python / model.py View on Github external
d1 = tf.concat([tf.nn.dropout(batch_norm(d1, "d1"), 0.5), e7], 3)
            d2 = deconv2d(tf.nn.relu(d1), [1,num[2],num[2],feature*8], name="d2")
            d2 = tf.concat([tf.nn.dropout(batch_norm(d2, "d2"), 0.5), e6], 3)
            d3 = deconv2d(tf.nn.relu(d2), [1,num[3],num[3],feature*8], name="d3")
            d3 = tf.concat([tf.nn.dropout(batch_norm(d3, "d3"), 0.5), e5], 3) 
            d4 = deconv2d(tf.nn.relu(d3), [1,num[4],num[4],feature*8], name="d4")
            d4 = tf.concat([batch_norm(d4, "d4"), e4], 3)
            d5 = deconv2d(tf.nn.relu(d4), [1,num[5],num[5],feature*4], name="d5")
            d5 = tf.concat([batch_norm(d5, "d5"), e3], 3) 
            d6 = deconv2d(tf.nn.relu(d5), [1,num[6],num[6],feature*2], name="d6")
            d6 = tf.concat([batch_norm(d6, "d6"), e2], 3)
            d7 = deconv2d(tf.nn.relu(d6), [1,num[7],num[7],feature], name="d7")
            d7 = tf.concat([batch_norm(d7, "d7"), e1], 3) 
            d8 = deconv2d(tf.nn.relu(d7), [1,num[8],num[8],conf.img_channel], name="d8")

            return tf.nn.tanh(d8)
github guillaume-chevalier / HAR-stacked-residual-bidir-LSTMs / lstm_architecture.py View on Github external
mean=0.0,
            stddev=float(config.weights_stddev)
        )
    )
    b = tf.get_variable(
        "relu_fc_biases_noreg",
        initializer=tf.random_normal(
            [new_features_len],
            mean=float(config.bias_mean),
            stddev=float(config.weights_stddev)
        )
    )

    # intra-timestep multiplication:
    output_2D_tensor_list = [
        tf.nn.relu(tf.matmul(input_2D_tensor, W) + b)
            for input_2D_tensor in input_2D_tensor_list
    ]

    return output_2D_tensor_list
github tensorlayer / tensorlayer / tensorlayer / models / squeezenetv1.py View on Github external
def fire_block(n, n_filter, max_pool=False, name='fire_block'):
    n = Conv2d(n_filter, (1, 1), (1, 1), tf.nn.relu, 'SAME', name=name + '.squeeze1x1')(n)
    n1 = Conv2d(n_filter * 4, (1, 1), (1, 1), tf.nn.relu, 'SAME', name=name + '.expand1x1')(n)
    n2 = Conv2d(n_filter * 4, (3, 3), (1, 1), tf.nn.relu, 'SAME', name=name + '.expand3x3')(n)
    n = Concat(-1, name=name + '.concat')([n1, n2])
    if max_pool:
        n = MaxPool2d((3, 3), (2, 2), 'VALID', name=name + '.max')(n)
    return n
github MicrobeLab / DeepMicrobes / DeepMicrobes.py View on Github external
def model_fn(features, labels, mode, params):
    model = config(flags.FLAGS.model_name, params)
    logits = model(features)

    predictions = {
        'classes': tf.argmax(logits, axis=1),
        'probabilities': tf.nn.softmax(logits)
    }

    if mode == tf.estimator.ModeKeys.PREDICT:
        # Return the predictions and the specification for serving a SavedModel
        return tf.estimator.EstimatorSpec(
            mode=mode,
            predictions=predictions,
            export_outputs={
                'predict': tf.estimator.export.PredictOutput(predictions)
            })

    loss = tf.losses.sparse_softmax_cross_entropy(
        logits=logits, labels=labels)

    # Create a tensor named cross_entropy for logging purposes.
    tf.identity(loss, name='cross_entropy')