Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question]: How to use regularizer ? #1237

Open
AdrienDeverin opened this issue Feb 28, 2024 · 0 comments
Open

[Question]: How to use regularizer ? #1237

AdrienDeverin opened this issue Feb 28, 2024 · 0 comments

Comments

@AdrienDeverin
Copy link

Description

In order to create pruning in my Model, I need to use a regularizer (typically L1 norm).
I create my own Layer (named LineGain) and build my kernel like this :

// call in the build function
kernel = add_weight("kernel", kernelshape, initializer: kernel_initializer, regularizer: kernel_regularizer, dtype: base.DType, trainable: true);

During the cnn construction it looks like that :

 // Add it in the cnn
output = new LineGain(
    new LineGainArgs 
    {
        DataFormat = linegainLayer.DataFormat,
        KernelRegularizer = new L1(lambdaLineGain),
        Activation = KerasApi.keras.activations.GetActivationFromName(linegainLayer.activation)
    }
).Apply(input);

My model compile and learn ! (It's one things)

Problem : it doesn't seem to apply the regularization during learning (weights are not put to zero, the change of lambdaLineGain doesn't seem to change anything even with aberrants values)

Is someone have already use Regularization and can provide me a exemple which work ?

Additionally it's seem to not working either in the Dense layer.
During my check I found that nowhere the regularizer is given to the kernel (see Tensorflow.Keras.Layers.Dense, build function) :

inputSpec = new InputSpec(TF_DataType.DtInvalid, null, min_ndim, null, axes);
kernel = add_weight("kernel", new Shape(num, args.Units), initializer: args.KernelInitializer, dtype: base.DType);
if (args.UseBias)
{
    bias = add_weight("bias", new Shape(args.Units), initializer: args.BiasInitializer, dtype: base.DType);
}

Alternatives

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant