Last active
February 3, 2026 20:24
-
-
Save dacr/4214f783f8412c2d654c9c9e05522f08 to your computer and use it in GitHub Desktop.
Playing with Java Deep Learning (DJL), tutorial-01 / published by https://github.com/dacr/code-examples-manager #15d7706b-fdc7-4aab-a788-8a2262c5d189/976d4e4a0ff1bb9d54a769b16990ebed15d99c47
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
| // summary : Playing with Java Deep Learning (DJL), tutorial-01 | |
| // keywords : djl, machine-learning, tutorial, ai, @testable | |
| // publish : gist | |
| // authors : David Crosson | |
| // license : Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt) | |
| // id : 15d7706b-fdc7-4aab-a788-8a2262c5d189 | |
| // created-on : 2021-03-05T09:23:01Z | |
| // managed-by : https://github.com/dacr/code-examples-manager | |
| // run-with : scala-cli $file | |
| // --------------------- | |
| //> using scala "3.7.2" | |
| //> using dep "org.slf4j:slf4j-api:2.0.17" | |
| //> using dep "org.slf4j:slf4j-simple:2.0.17" | |
| //> using dep "ai.djl:api:0.33.0" | |
| // --------------------- | |
| // inspired from https://docs.djl.ai/jupyter/tutorial/01_create_your_first_network.html | |
| import ai.djl._ | |
| import ai.djl.nn._ | |
| import ai.djl.nn.core._ | |
| import ai.djl.training._ | |
| val application = Application.CV.IMAGE_CLASSIFICATION | |
| val inputSize = 28*28 | |
| val outputSize = 10 | |
| val block = new SequentialBlock() | |
| block.add(Blocks.batchFlattenBlock(inputSize)) | |
| block.add(Linear.builder().setUnits(128).build()) | |
| block.add(arr => Activation.relu(arr)) | |
| block.add(Linear.builder().setUnits(64).build()) | |
| block.add(arr => Activation.relu(arr)) | |
| block.add(Linear.builder().setUnits(outputSize).build()) | |
| println(block) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment