Created
June 12, 2018 22:18
-
-
Save roywei/5ae5184158cbe7d8856b073f54166fa5 to your computer and use it in GitHub Desktop.
Code Snippet for Image Classifier Example
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
def runInferenceOnSingleImage(modelPathPrefix: String, inputImagePath: String, | |
context: Array[Context]): | |
IndexedSeq[IndexedSeq[(String, Float)]] = { | |
val dType = DType.Float32 | |
val inputShape = Shape(1, 3, 32, 32) | |
val inputDescriptor = IndexedSeq(DataDesc("/input_11", inputShape, dType, "NCHW")) | |
// Create object of ImageClassifier class | |
val imgClassifier: ImageClassifier = new | |
ImageClassifier(modelPathPrefix, inputDescriptor, context) | |
// Loading single image from file and getting BufferedImage | |
val img = ImageClassifier.loadImageFromFile(inputImagePath) | |
// Running inference on single image | |
val output = imgClassifier.classifyImage(img, Some(5)) | |
output | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment