Skip to content

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

Closed

Description

@Shportaluk

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

Activity

  1. SanftMonster commented on Feb 8, 2023

    @SanftMonster
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions