Tracking gradients in different layers, and serializing some MNIST images to JSON