Ejemplo n.º 1
0
def test_linear():
    '''
    This function does no input validation, it just returns the thing
    that was passed in.
    '''
    xs = [1, 5, True, None, 'foo']
    for x in xs:
        assert(x == activations.linear(x))
Ejemplo n.º 2
0
def test_linear():
    '''
    This function does no input validation, it just returns the thing
    that was passed in.
    '''
    xs = [1, 5, True, None, 'foo']
    for x in xs:
        assert (x == activations.linear(x))
Ejemplo n.º 3
0
 def compute_similarity(self, repeated_context_vectors,
                        repeated_query_vectors):
     element_wise_multiply = repeated_context_vectors * repeated_query_vectors
     concatenated_tensor = K.concatenate([
         repeated_context_vectors, repeated_query_vectors,
         element_wise_multiply
     ],
                                         axis=-1)
     dot_product = K.squeeze(K.dot(concatenated_tensor, self.kernel),
                             axis=-1)
     return linear(dot_product + self.bias)
Ejemplo n.º 4
0
def build_model():
    model = models.Sequential()
    model.add(
        LSTM(100, activation=activations.relu(), input_shape=(timeSteps, 1)))
    model.add(Dropout(1))
    #model.add(layers.Dense(20, activation='relu'))
    model.add(layers.Dense(1, activation=activations.linear()))
    print("made it2")
    model.compile(optimizer=tf.keras.optimizers.SGD(learning_rate=0.001),
                  loss=tf.keras.losses.mse,
                  metrics=['acc'])
    return model
Ejemplo n.º 5
0
def InvertedRes(input, expansion):
    '''
    Args:
        input: input tensor
        expansion: expand filters size
    Output:
        output: output tensor
    '''
    #Pointwise Convolution
    x = Conv2D(expansion*3,(1,1), padding='same')(input)
    x = BatchNormalization()(x)
    x = ReLU()(x) 
    #Depthwise Convolution
    x = DepthwiseConv2D((3,3), padding='same')(x)
    x = BatchNormalization()(x)
    x = ReLU()(x)
    #Pointwise Convolution
    x = Conv2D(3,(1,1))(x)
    x = BatchNormalization()(x)
    x = linear(x)

    x = Add()([x, input])
    
    return x
Ejemplo n.º 6
0
 def test_linear(self):
     x = np.random.random((10, 5))
     self.assertAllClose(x, activations.linear(x))
Ejemplo n.º 7
0
    sns.set()
    plt.plot(net, act)
    plt.ylabel('act', fontsize=20)
    plt.xlabel('net', fontsize=20)
    plt.title(title, fontsize=20)
    plt.savefig('./{0}.jpg'.format(title), dpi=300)
    plt.close()


# create a numpy array - TensorFlow defaults to single precision floating point
netnp = np.linspace(-5.0, 5.0, 1000, dtype='float32')
# convert to a TensorFlow tensor
nettf = tf.convert_to_tensor(netnp)

# linear activation function
acttf = kact.linear(nettf)
# need to convert from TensorFlow tensors to numpy arrays before plotting
# eval() is called because TensorFlow tensors have no values until they are "run"
plt_act(nettf.eval(), acttf.eval(), 'linear activation function')

# relu activation function
acttf = kact.relu(nettf)
plt_act(nettf.eval(), acttf.eval(), 'rectified linear (relu)')

# sigmoid activation function
acttf = kact.sigmoid(nettf)
plt_act(nettf.eval(), acttf.eval(), 'sigmoid')

# hard sigmoid activation function
acttf = kact.hard_sigmoid(nettf)
plt_act(nettf.eval(), acttf.eval(), 'hard sigmoid')
Ejemplo n.º 8
0
def test_linear():
    xs = [1, 5, True, None]
    for x in xs:
        assert (x == activations.linear(x))
Ejemplo n.º 9
0
def test_linear():
    xs = [1, 5, True, None]
    for x in xs:
        assert(x == activations.linear(x))
Ejemplo n.º 10
0
def testLinearity():
    testValues = [1, 5, True, None]
    for x in testValues:
        assert (x == activations.linear(x))
Ejemplo n.º 11
0
 def call(self, inputs, training=False, mask=None):
     x = nn.relu(self.fc1(inputs))
     x = nn.relu(self.fc2(x))
     x = linear(self.fc3(x))
     return x