Running predictions

Running predictions is as simple as calling the mx.predict function. Additional work is involved in merging the predictions with synset. Refer to the following code:

@time pred = mx.predict(mx_model, mx.ArrayDataProvider(:data => mx_data));
# Main> INFO: TempSpace: Total 13 MB allocated on CPU0
# Main> 0.422658 seconds (51.29 k allocations: 5.016 MiB)

I have also included the @time macro so that we have an approximate time of how long it takes to run the prediction.

Now, it is time to verify the most probable class for our image:

mxval, mxindx = findmax(pred[:, 1]);
println(mxval, " ", mxindx, " ", synset[mxindx])

We got the following output at 0.48447394 426 n02007558 flamingo, which means that with 48.5% probability, the most probable class of the image is a flamingo:

You can try changing the path and validating the result on other images.