Repository navigation
fix(mnistdemo): declare the CNN input shape (CNN weights could not load) - #49
Merged
Merged
Conversation
…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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the pre-existing MNISTDemo bug noted in #39 and #47:
createMNISTCNN()opened withconv2dand no input declaration, so the DSL had no per-sample shape to carry through the conv and pool layers, andflatten()handeddense(10, "out")zero input features. The output layer came out as[10 x 0], loadingmnist_cnn.ggufthrewArrayIndexOutOfBoundsException, 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 throughconv2d/maxPool2dand infers32 * 7 * 7 = 1568atflatten(), so the output layer is[10 x 1568], matching the GGUF.Verified locally on engine 0.62.1:
:cli:testall 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.