Inference
Inference is the process of giving an input to your network and getting a classification or prediction. When the neural network has been trained and deployed in production, we use it, for example, to classify images or to decide how to drive in a road, and this process is called inference.
The first step is to load the model:
model = load_model(os.path.join(dir_save, model_name))
Then you simply call predict()
, which is the method for inference in Keras. Let's try with the first test sample of MNIST:
x_pred = model.predict(x_test[0:1, :, :, :])print("Expected:", np.argmax(y_test))print("First prediction probabilities:", x_pred)print("First prediction:", np.argmax(x_pred))
This is the result for my MNIST network:
Expected: 7 First prediction probabilities: [[6.3424804e-14 6.1755254e-06 2.5011676e-08 2.2640785e-07 9.0170204e-08 7.4626680e-11 5.6195684e-13 9.9999273e-01 1.9735349e-09 7.3219508e-07]] First prediction: 7...