|
10 | 10 | simple_sigmoid, \
|
11 | 11 | DenseAutoMlStructuralComponent, DenseLateralConnectivity
|
12 | 12 |
|
13 |
| -class TernaryDenseLayer(tf.keras.layers.Layer): |
14 |
| - def __init__(self, units, input_dim, **kwargs): |
15 |
| - super(TernaryDenseLayer, self).__init__(**kwargs) |
16 |
| - self.units = units |
17 |
| - self.input_dim = input_dim |
18 |
| - self.ternary_weights = self.add_weight(name='ternary_weights', |
19 |
| - shape=(input_dim, units), |
20 |
| - initializer='glorot_uniform', |
21 |
| - trainable=True) |
22 |
| - |
23 |
| - def build(self, input_shape): |
24 |
| - # Create a trainable weight variable for the bias |
25 |
| - self.bias = self.add_weight(name='bias', |
26 |
| - shape=(self.units,), |
27 |
| - initializer='zeros', |
28 |
| - trainable=True) |
29 |
| - |
30 |
| - def call(self, inputs): |
31 |
| - # Apply ternary weights to the input vector |
32 |
| - ternary_inputs = tf.cast(tf.sign(inputs), tf.float32) * tf.abs(inputs) |
33 |
| - output = tf.matmul(ternary_inputs, self.ternary_weights) |
34 |
| - # Add bias and apply activation function |
35 |
| - output = tf.nn.bias_add(output, self.bias) |
36 |
| - output = tf.nn.relu(output) |
37 |
| - return output |
| 13 | +from custom.custom import TernaryDenseLayer |
38 | 14 |
|
39 | 15 | class Unit(NeuralNetworkFutureComponent):
|
40 | 16 | def __init__(self,
|
|
0 commit comments