Skip to content

Instantly share code, notes, and snippets.

@dswah
dswah / orthonormal_constraint.py
Last active July 24, 2023 16:00
Orthonormal Weight Constraint (tensorflow / keras)
import tensorflow as tf
class Orthonormal(tf.keras.constraints.Constraint):
"""approximate Orthonormal weight constraint.
Constrains the weights incident to each hidden unit
to be approximately orthonormal
# Arguments
beta: the strength of the constraint
@dswah
dswah / layers_tied.py
Last active September 17, 2021 22:45
Tied Convolutional Weights with Keras for CNN Auto-encoders
from keras import backend as K
from keras import activations, initializations, regularizers, constraints
from keras.engine import Layer, InputSpec
from keras.utils.np_utils import conv_output_length
from keras.layers import Convolution1D, Convolution2D
import tensorflow as tf
class Convolution1D_tied(Layer):
'''Convolution operator for filtering neighborhoods of one-dimensional inputs.
When using this layer as the first layer in a model,