Last active
June 12, 2020 00:53
-
-
Save roywei/fd274c292ea46fd25f497c9132e9993a to your computer and use it in GitHub Desktop.
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
private static final class MyTranslator implements Translator<BufferedImage, Classifications> { | |
private static final List<String> CLASSES = Arrays.asList("Normal", "Pneumonia"); | |
@Override | |
public NDList processInput(TranslatorContext ctx, BufferedImage input) { | |
NDArray array = | |
BufferedImageUtils.toNDArray( | |
ctx.getNDManager(), input, NDImageUtils.Flag.COLOR); | |
array = NDImageUtils.resize(array, 224).div(255.0f); | |
return new NDList(array); | |
} | |
@Override | |
public Classifications processOutput(TranslatorContext ctx, NDList list) { | |
NDArray probabilities = list.singletonOrThrow(); | |
return new Classifications(CLASSES, probabilities); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment