You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Issue described: Try using a Ternary operation layer instead of a Dense layer, e.g. Replace each occurrence of tf.keras.layers.Dense with a custom layer like this:
importtensorflowastfclassTernaryDenseLayer(tf.keras.layers.Layer):
def__init__(self, units, input_dim, **kwargs):
super(TernaryDenseLayer, self).__init__(**kwargs)
self.units=unitsself.input_dim=input_dimself.ternary_weights=self.add_weight(name='ternary_weights',
shape=(input_dim, units),
initializer='glorot_uniform',
trainable=True)
defbuild(self, input_shape):
# Create a trainable weight variable for the biasself.bias=self.add_weight(name='bias',
shape=(self.units,),
initializer='zeros',
trainable=True)
defcall(self, inputs):
# Apply ternary weights to the input vectorternary_inputs=tf.cast(tf.sign(inputs), tf.float32) *tf.abs(inputs)
output=tf.matmul(ternary_inputs, self.ternary_weights)
# Add bias and apply activation functionoutput=tf.nn.bias_add(output, self.bias)
output=tf.nn.relu(output)
returnoutput
Kind of issue: enhancement
Issue described: Try using a Ternary operation layer instead of a Dense layer, e.g. Replace each occurrence of tf.keras.layers.Dense with a custom layer like this:
Ultimately, it may be worth integrating this with what was done here: https://arxiv.org/pdf/2406.02528
The text was updated successfully, but these errors were encountered: