Deploying a model

I’m confused as to how a trained model is deployed. I trained a CNN using the LeNetMNISTReLu example class, and stored it on my pc. What’s next? I’d like to feed images into the model and view the output. Any link or insight would be appreciated.



@nacho few terms:
“Deploying” a model is relative to your application. Using a model in a main class isn’t really considered “deploying”. Deployment means putting it within an application, eg: embedding it in a mobile app or setting it up in a web application.

What you seem to want is performing inference. If you want to see the accuracy, it’s already accessible with net.evaluate on a test set that’s created for you.

For loading an image and performing inference, there are basically 4 steps:

  1. Load the model using ModelSerializer.restoreMultiLayerNetwork(“path/to/”);
  2. Use the NativeImageLoader to load target images.
    3 Using that transform your image in to an ndarray.
  3. Normalize the output using the normalizer from before (your data pipeline must always be consistent)

Something like:

      MultiLayerNetwork network = ModelSerializer.restoreMultiLayerNetwork("path/to/model");
       NativeImageLoader loader = new NativeImageLoader();
        INDArray image = loader.asMatrix("path/to/your/img));
        DataNormalization scaler = new ImagePreProcessingScaler();
        INDArray output = network .output(false, image);

For MNIST, it’s just going to print a bunch of probabilities on the output.

Thanks! Exactly what I needed.