Conv2D(1,8,5,5) -> ReLU -> Flatten -> Linear(4608,10), trained via CrossEntropyLoss + Adam, one real MNIST image at a time (this library has no batch dimension anywhere, same constraint XorNetwork already works under).
More...
#include <mnist_classifier_example.hpp>
|
| | MnistConvNet (DeviceBackend *backend, unsigned seed=42) |
| | Constructs the network with randomly initialized weights.
|
| |
| Tensor | forward (const Tensor &image) |
| | Runs the network forward.
|
| |
| int64_t | predict (const Tensor &image) |
| | forward() plus argmax – the predicted class index.
|
| |
| float | train_step (const Tensor &image, int64_t target_class, AdamOptimizer &optimizer, MetricsSink &sink, int step) |
| | Runs one training step: forward, cross-entropy loss, backward through every layer, one Adam update per layer's parameters, and logs the loss.
|
| |
| const Tensor & | classifier_weight () const |
| | Test/inspection accessor.
|
| |
| std::vector< Module * > | modules () |
| | The network's layers in forward order (Conv2D, ReLU, Flatten, Linear), for building an ExplainerContext over the trained model – so every explainer (Saliency, IntegratedGradients, GradCAM, LRP, ...) and build_circuit_graph() can run on exactly the weights train_step() learned. The pointers alias this object's members: they stay valid only while this MnistConvNet is alive.
|
| |
Conv2D(1,8,5,5) -> ReLU -> Flatten -> Linear(4608,10), trained via CrossEntropyLoss + Adam, one real MNIST image at a time (this library has no batch dimension anywhere, same constraint XorNetwork already works under).
- Note
- Reuses grad_cam_mnist_demo.cpp's exact network shape (kernel size 5, 8 output channels) deliberately – once this network is trained on real data, a Grad-CAM call against it produces a meaningful heatmap for the first time in this project, not just pipeline mechanics on random weights.
-
Random (not hand-picked) initial weights – unlike XorNetwork's 12-weight network, hand-picking ~4600+ asymmetric values isn't practical. A fixed RNG seed keeps this reproducible; see mission Recon for why zero-init specifically doesn't work (identical rationale to XorNetwork's own note).
◆ MnistConvNet()
| pulsatrix::MnistConvNet::MnistConvNet |
( |
DeviceBackend * |
backend, |
|
|
unsigned |
seed = 42 |
|
) |
| |
|
explicit |
Constructs the network with randomly initialized weights.
- Parameters
-
| backend | Backend to compute through. Not owned; must outlive this network. |
| seed | RNG seed for weight initialization. |
◆ classifier_weight()
| const Tensor & pulsatrix::MnistConvNet::classifier_weight |
( |
| ) |
const |
|
inline |
Test/inspection accessor.
◆ forward()
| Tensor pulsatrix::MnistConvNet::forward |
( |
const Tensor & |
image | ) |
|
Runs the network forward.
- Parameters
-
| image | Shape (1, 28, 28), pixel values normalized to [0,1]. |
- Returns
- Shape (10,) raw logits (pre-softmax).
◆ modules()
| std::vector< Module * > pulsatrix::MnistConvNet::modules |
( |
| ) |
|
|
inline |
◆ predict()
| int64_t pulsatrix::MnistConvNet::predict |
( |
const Tensor & |
image | ) |
|
forward() plus argmax – the predicted class index.
- Parameters
-
- Returns
- Predicted class, 0-9.
◆ train_step()
Runs one training step: forward, cross-entropy loss, backward through every layer, one Adam update per layer's parameters, and logs the loss.
- Parameters
-
| image | Shape (1, 28, 28). |
| target_class | Ground-truth class, 0-9. |
| optimizer | Optimizer to update this network's parameters with. |
| sink | Where the loss value is logged (tag "loss"). |
| step | Training step number, passed through to sink. |
- Returns
- The loss value for this example, before the update.
The documentation for this class was generated from the following file: