Skip to content

fix(mnistdemo): declare the CNN input shape (CNN weights could not load) - #49

Merged
michalharakal merged 1 commit into
developfrom
fix/mnistdemo-cnn-input-shape
Oct 22, 2026
Merged

michalharakal merged 1 commit into
developfrom
fix/mnistdemo-cnn-input-shape

Conversation

@michalharakal

Copy link
Copy Markdown
Contributor

Fixes the pre-existing MNISTDemo bug noted in #39 and #47: createMNISTCNN() opened with conv2d and no input declaration, so the DSL had no per-sample shape to carry through the conv and pool layers, and flatten() handed dense(10, "out") zero input features. The output layer came out as [10 x 0], loading mnist_cnn.gguf threw ArrayIndexOutOfBoundsException, and the two CNN accuracy tests failed on every engine version. The CNN mode of the app was affected the same way.

The fix is one line: input(intArrayOf(1, 28, 28)) at the top of the network. The engine's DSL (since the CNN shape-inference work) propagates that shape through conv2d / maxPool2d and infers 32 * 7 * 7 = 1568 at flatten(), so the output layer is [10 x 1568], matching the GGUF.

Verified locally on engine 0.62.1:

  • :cli:test all green, including the two CNN tests: 99.2 % on 500 MNIST test images, 100 % on the 100-image sample; parameter shapes now [16x1x5x5], [32x16x5x5], [10x1568].
  • :shared:jvmTest, :shared:compileKotlinWasmJs, :composeApp:compileKotlinDesktop, :composeApp:compileKotlinWasmJs.

…its 1568 features

createMNISTCNN() opened with conv2d straight away, so the DSL had no per-sample
shape to carry through the conv and pool layers and flatten() handed dense(10, "out")
zero input features. The layer was built as [10 x 0], loading mnist_cnn.gguf threw
ArrayIndexOutOfBoundsException, and the two CNN accuracy tests failed on every
engine version since the sample was written (noted in #39 and #47).

input(intArrayOf(1, 28, 28)) at the top lets the DSL infer 32*7*7 = 1568 for the
output layer; the GGUF loads and the CNN scores 99.2 % on 500 MNIST test images
(100 % on the 100-image sample).
@michalharakal
michalharakal merged commit 35c85c0 into develop Oct 22, 2026
@michalharakal
michalharakal deleted the fix/mnistdemo-cnn-input-shape branch October 22, 2026 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant