Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
List<Context> context = new ArrayList<>();
context.add(Context.cpu()); 
String modelPathPrefix = "my_model";


# Load the model along with the transformations.
Predictor predictor = new Predictor(modelPathPrefix, context, load_transforms=True);

# Inference
List<NDArray> result = predictor.predictWithNDArray(inputNDArray);

Performance Consideration

During inference, initial benchmarks shows a noticeable performance gain with End to end models i.e., a model with data transformations and neural network all fused as a single model graph.

  • ResNet-18 model pre-trained with ImageNet. https://s3.us-east-2.amazonaws.com/mxnet-public/end_to_end_models
  • Pre-processing - Resize(224, 224), ToTensor, Normalize(mean=(0.4850.4560.406), std=(0.2290.2240.225))
  • We take average of 500 runs
  • Single Request Inference - Input Data - Synthetic (random.uniform(0, 255, shape=(1, 300, 300, 3))
  • Batch Inference - Input Data - Synthetic (random.uniform(0, 255, shape=(25, 300, 300, 3))
  • Below time gives - Average Prediction Time Per Sample


ABCNon End to End Models (ms)End to End Models (ms)Boost %
CPU 
(C5.2X)
Single Request InferencePython (Module API)171417.65%
Java Inference APIs17.0914.1617.14%
Scala Inference APIs17.9313.1926.44%





Batch Inference (Batch size = 25)Python (Module API)15.1812.5717.19%
Java Inference APIs18.541329.88%
Scala Inference APIs1713.2622.00%






GPU 
(P3.16X)
Single Request InferencePython (Module API)5.783.1445.67%
Java Inference APIs8.954.2652.40%
Scala Inference APIs9.144.4251.64%





Batch Inference (Batch size = 25)Python (Module API)2.611.3149.81%
Java Inference APIs8.035.5331.13%
Scala Inference APIs7.865.5229.77%

Backward compatibility

  1. All APIs changes are backward compatible.
  2. Old MXNet model should still load without breakage with new MXNet version.
  3. New MXNet model will not work on old MXNet versions. If a user tries to load new MXNet model with older MXNet version, they get errors such as - "unknown field 'inputs', 'outputs' in the model" because, MXNet's model JSON parser schema in old MXNet do not understand new fields introduced as part of this work.

...