A Simple CNN Training Function with Backpropagation

Backpropagation, Training & Optimization DS practice problem on Onlearn.

Difficulty: hard.

Topics: Understanding Implement a Simple CNN Training Function with Backpropagation, Chain Rule, ReLU Activation, Softmax Normalization, Cross-Entropy Loss, Weight Initialization, Calculus, Linear Algebra, Optimization Theory, Computer Vision, Neural Network Architectures, Automatic Differentiation, Tensor Operations, Gradient Descent Variants, Convolutional Operations, Loss Function Formulation.

Create a function that trains a basic Convolutional Neural Network (CNN) using backpropagation. The network should include one convolutional layer with ReLU activation, followed by flattening and a dense layer with softmax output, and a cross entropy loss. You need to handle the forward pass, compute the loss gradients, and update the weights and biases using stochastic gradient descent. Ensure the function processes input data as grayscale images and one hot encoded labels, and returns the trained weights and biases for the convolutional and dense layers.