Skip to content

'Conv2DBackpropInput' returned too few gradients. Expected 3 but received 2 #974

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

Closed
Shportaluk opened this issue Feb 1, 2023 · 1 comment · Fixed by #980
Closed

'Conv2DBackpropInput' returned too few gradients. Expected 3 but received 2 #974

Shportaluk opened this issue Feb 1, 2023 · 1 comment · Fixed by #980

Comments

@Shportaluk
Copy link

After added "Conv2DTranspose" to Generator i have exception in gradient
image

But if delete "Conv2DTranspose" i have not exception. Google not know how to fix this
image

@AsakusaRinne
Copy link
Collaborator

The problem is resolved by #980. Since the complete code is not given here, I use the following code to test it:

    [TestMethod]
    public void Test()
    {
        var model = keras.Sequential(name: "GENERATOR", layers:new List<ILayer>()
        {
            keras.layers.InputLayer(20),
            keras.layers.Dense(7 * 7 * 256),
            keras.layers.BatchNormalization(),
            keras.layers.LeakyReLU(),
            keras.layers.Reshape((7, 7, 256)),
            keras.layers.Conv2DTranspose(128, (5, 5), strides: (1, 1), output_padding: "same", use_bias: false, activation: "relu"),
            keras.layers.BatchNormalization(),
            keras.layers.LeakyReLU(),
            keras.layers.Conv2DTranspose(64, (5, 5), strides: (2, 2), output_padding: "same", use_bias: false, activation: "relu"),
            keras.layers.BatchNormalization(),
            keras.layers.LeakyReLU(),
            keras.layers.Conv2DTranspose(1, (5, 5), strides: (2, 2), output_padding: "same", use_bias: false, activation: "tanh"), // 28 28 1
        });
        
        model.summary();

        model.compile(new Adam(0.001f), new LossesApi().SparseCategoricalCrossentropy(), new string[] { "accuracy" });

        var num_epochs = 1;
        var batch_size = 8;

        var dataset = new RandomDataSet(new Shape(16, 20), 16);

        model.fit(dataset.Data, dataset.Labels, batch_size, num_epochs);
    }

    public class RandomDataSet : DataSetBase
    {
        private Shape _shape;

        public RandomDataSet(Shape shape, int count)
        {
            Data = np.random.normal(0, 2, shape);
            Labels = np.random.uniform(0, 1, (count, 28, 28, 1));
        }
    }

The PR has not been reviewed and merged. If time is limited for your project, please clone the branch of #980 and have a try.

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

Successfully merging a pull request may close this issue.

2 participants