// A native CNN in NCHW format. Use --dev reports/cnn to inspect its architecture.
import aner.nn
import aner.tensor
import aner.dev

let model = nn.cnn(channels: 1, height: 8, width: 8, seed: 42)
    .conv2d(outputs: 4, padding: 1).batch_norm().relu()
    .max_pool2d().head(classes: 2)
    .on(device: "auto", precision: "Float32")
dev.capture("CNN architecture", model)
print(model.summary())

// Synthetic tensors demonstrate API mechanics; use held-out real images for evaluation.
let images = tensor.reshape(nn.random(8, 64, seed: 2026, scale: 1.0), List(8, 1, 8, 8))
let targets = nn.zeros(8, 1)
let fitted = model.fit(images, targets, epochs: 3, batch: 4, rate: 0.001)
print(fitted.last_loss())
print(fitted.predict(images).rows())
// Save into a new file, then continue later with optimizer and shuffle state retained:
// fitted.save("cnn.anercnn")
// let resumed = nn.load_cnn("cnn.anercnn").on("auto").fit(images, targets, epochs: 3)
