This file contains 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
// load vgg16 model from model zoo | |
val model = VGG16().initPretrained(PretrainedType.IMAGENET) as ComputationGraph | |
// restore the new model that was saved to a file | |
val catsdogsModel = ModelSerializer.restoreMultiLayerNetwork(javaClass.getResource("/catdogmodel.dl4j").openStream()) | |
// get vgg16 labels | |
val image = FileInputStream("input.png") | |
val input = NativeImageLoader(224, 224, 3).asMatrix(image).also { VGG16ImagePreProcessor().transform(it) } | |
val vgg16labels = vgg16model.outputSingle(input) |
This file contains 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
// designing the model - mostly the same as shown at https://deeplearning4j.org/mnist-for-beginners | |
val conf = NeuralNetConfiguration.Builder() | |
.seed(ThreadLocalRandom.current().nextLong()) | |
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT) | |
.iterations(1) | |
.learningRate(0.006) | |
.updater(Nesterovs(0.9)) | |
.regularization(true).l2(1e-4) | |
.list() |
This file contains 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
val model = VGG16().initPretrained(PretrainedType.IMAGENET) as ComputationGraph | |
val image = FileInputStream("input.png") | |
val input = NativeImageLoader(224, 224, 3).asMatrix(image).also { VGG16ImagePreProcessor().transform(it) } | |
val output = model.outputSingle(input) |