Last active
May 25, 2024 10:19
-
-
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/e04f21877e2c9f4627a94b3d14de186db3f9c4a7
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 NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2) | |
// 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.4.2" | |
//> using dep "org.slf4j:slf4j-api:2.0.13" | |
//> using dep "org.slf4j:slf4j-simple:2.0.13" | |
//> using dep "ai.djl:api:0.28.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