SciSharp / TensorFlow.NET

.NET Standard bindings for Google's TensorFlow for developing, training and deploying Machine Learning models in C# and F#.
https://scisharp.github.io/tensorflow-net-docs
Apache License 2.0
3.23k stars 517 forks source link

[BUG Report]: LayerNormalization BUG #1214

Closed JustDooooIt closed 10 months ago

JustDooooIt commented 10 months ago

Description

Writing keras.layers.LayerNormalization inside the Model class will report an error

Reproduction Steps

[TestMethod]
public void Model1Test()
{
    var model = new TestModel1();
    var tensor = np.random.random((7, 7, 8, 13));
    model.Apply(tensor);
}
public class TestModel1 : Model
{
    ILayer conv2d;
    ILayer norm;

    public TestModel1() : base(new())
    {
        conv2d = tf.keras.layers.Conv2D(16, 3, 1, "same");
        norm = tf.keras.layers.LayerNormalization(-1);
    }

    protected override Tensors Call(Tensors inputs, Tensors state = null, bool? training = null, IOptionalArgs optional_args = null)
    {
        var x = conv2d.Apply(inputs);
        x = norm.Apply(x);
        return x;
    }
}

Known Workarounds

No response

Configuration and Other Information

No response

Wanglongzhi2001 commented 10 months ago

TestModel1 should inherit Layer