Learning

Machine learning tutorial: Model deployment

Deployment in machine learning is the process of applying a trained model to new data.

Neural Designer can calculate predictions, explain input influence, optimize responses and export models for use in other applications.

Contents

1

Neural network outputs

A neural network produces outputs for every set of inputs.

The input and output formats depend on the model type:

ModelInputOutput
Approximation and classificationVariable valuesPredictions or probabilities
ForecastingTime series valuesFuture values
Image classificationImage filePredicted class and probabilities
Text classificationSentencePredicted class and probabilities

The following table shows the output of a model that estimates a car’s fuel consumption.

CylindersDisplacementHorsepowerWeightAccelerationModel yearFuel consumption
8307130350412198017 mpg
2

Output data

This task applies the model to many new cases and exports their outputs.

ModelSourceResult
Numerical and forecastingData fileFile with predictions
Image classificationImage folderPredictions for every image
Text classificationText filePrediction for every line

For example, a marketing model can export conversion probabilities for every customer in an input file.

RecencyFrequencyMonetaryConversion
2 months5 times125 USD70%
5 months2 times20 USD8%
3 months9 times225 USD85%
3

Directional outputs

Directional outputs show how predictions change when one input varies and all other inputs remain fixed.

They help to understand the model and improve designs or processes.

The following example estimates the residuary resistance of a sailing yacht. The chart varies the Froude number while keeping the other design variables fixed.

Reference inputValue
Center of buoyancy-2.38
Prismatic coefficient0.56
Length displacement4.79
Beam draught ratio3.94
Length beam ratio3.21

Directional output example

The residuary resistance increases rapidly for high Froude numbers, while the remaining inputs stay at the reference point.

4

Sample input importances

Sample input importances explain one prediction by calculating how every output changes with respect to the inputs at a selected sample.

  • Positive values increase the output.
  • Negative values decrease the output.
  • Values close to zero have little local influence.
5

Model input importances

Model input importances measure the overall influence of every input on the model outputs.

Neural Designer perturbs up to 50 data samples, accumulates the changes and normalizes the results for comparison.

6

Response optimization

For approximation models, response optimization searches for input values that minimize or maximize selected outputs while satisfying the imposed conditions.

With one objective, it returns the best feasible solution. With several objectives, it returns a Pareto front and highlights an advised trade-off.

7

Mathematical expression

Numerical models can be written as a mathematical function that maps inputs to outputs.

The expression includes scaling, dense layers, activation functions, unscaling and clamping when those operations are present.

scaled_shear_rate = 2*(shear_rate-50)/(90-50)-1;
scaled_particle_diameter = 2*(particle_diameter-0.72)/(6.596-0.72)-1;
dense_1_1 = tanh(-1.06007 + 0.448487*scaled_shear_rate - 0.861393*scaled_particle_diameter);
dense_1_2 = tanh(0.756922 + 2.00716*scaled_shear_rate + 0.391539*scaled_particle_diameter);
scaled_particles_adhering = -1.30536 - 1.0244*dense_1_1 + 0.56055*dense_1_2;
particles_adhering = 0.5*(scaled_particles_adhering+1.0)*(74.75-13.22)+13.22;

Image and text models do not have a readable closed-form expression. They use a deployment package instead.

8

Programming language expressions

Neural Designer exports numerical model expressions to C, Python, JavaScript and PHP.

The generated code reproduces the complete prediction pipeline and can be embedded in another application.

Python expression

def neural_network(inputs):
    scaled_inputs = scaling_layer(inputs)
    outputs = dense_layer_0(scaled_inputs)
    outputs = dense_layer_1(outputs)
    outputs = unscaling_layer(outputs)
    return clamping_layer(outputs)

C expression

void neural_network(const double inputs[], double outputs[])
{
    double scaled_inputs[2];
    double dense_outputs[3];
    scaling_layer(inputs, scaled_inputs);
    dense_layer_0(scaled_inputs, dense_outputs);
    dense_layer_1(dense_outputs, outputs);
    unscaling_layer(outputs, outputs);
    clamping_layer(outputs, outputs);
}
9

Deployment package

Image and text classification models can be exported as a complete deployment package.

The package contains everything needed by the model:

ItemContents
ModelArchitecture, trained parameters and class labels
EngineNeural Designer Engine and runtime dependencies
WrapperC program or Python script
DocumentationREADME and command-line examples

The exported folder can be copied to another Windows computer and run without installing Neural Designer or a machine learning framework.

Image packages classify an image or a complete folder. Text packages classify a sentence or every line in a file. Both can return the predicted class, probabilities or percentages.

The Python wrapper requires Python 3. The C wrapper must be compiled once with a C compiler.

Inference uses the CPU by default. GPU execution is available when the bundled engine and runtime support CUDA.