How do I use a MNIST model to verify a number image?

Issue Description

  • expected behavior:Mnist model is obtained from DL4J
  • encountered behavior:How do I load the model?

Version Information

  • Deeplearning4j version: 1.0.0 beta7
  • Platform information (OS, etc): deepin20
  • CUDA version, if used: none
  • NVIDIA driver version, if in use: none
    System.out.println("Load model...");
    net = ModelSerializer.restoreComputationGraph(modelFileName);
1 Like

Thank you! :handshake:

Thank you! :handshake:

After loading MNIST model, which should I use function to the “/home/admins/desktop/1.jpg” recognize the file number???

Hi,
you can do this:

NativeImageLoader loader = new NativeImageLoader(28, 28, 1);
ImagePreProcessingScaler imagePreProcessingScaler = new ImagePreProcessingScaler(0, 1);
File imageFile = new File("/home/admins/desktop/1.jpg");
INDArray indArray = loader.asMatrix(imageFile);
imagePreProcessingScaler.transform(indArray);
INDArray results = model.outputSingle(indArray);

and then inspect results and take the index of the highest value.

See here for similar examples:

1 Like

Thanks vincenzo.caselli :handshake::handshake::handshake: