Icon

Python_​Efficient_​Repeat_​Use_​of_​Model

Python Efficient Repeat Use of Model

After creating a model (especially a DL Python Model), that model will be used to make predictions given new input data. Sometimes the need to make such predictions can occur much later in a Workflow and in different Python nodes. Loading and reloading these models to make a prediction can become costly.

This Workflow introduces a pattern for preserving a DL Python Model in memory such that it can be used to make predictions on-demand without needing to reload it each time. It consists of three reusable Components:
1. a Component to preserve the model in memory and make it possible to call the model's predict() method, on-demand;
2. a Component to call the model's predict() method; and
3. a Component to release the model from memory, once it is no longer needed anywhere in the Workflow.

As a practical demo, this Workflow employs Keras+TensorFlow2's definition of resnet50 to recognize common objects depicted in one or more input images.

Resnet50Pretend we do work addinglayers, taking some away,do some training, etc.Read, normalize and resizethe input imagesTest imagesSimulate needingto make calls tomodel.predict()several distinct timesin the WorkflowBecause the model isstill in memory, we canavoid the expense ofneeding to reload itevery time we want touse it to make apredictionDL PythonNetwork Creator Load and preprocessimages (Local Files) List Files Chunk Loop Start Loop End Preserve DL PythonModel in Memory Call Predict from DLPython Model in Memory Table View Release DL PythonModel in Memory Resnet50Pretend we do work addinglayers, taking some away,do some training, etc.Read, normalize and resizethe input imagesTest imagesSimulate needingto make calls tomodel.predict()several distinct timesin the WorkflowBecause the model isstill in memory, we canavoid the expense ofneeding to reload itevery time we want touse it to make apredictionDL PythonNetwork Creator Load and preprocessimages (Local Files) List Files Chunk Loop Start Loop End Preserve DL PythonModel in Memory Call Predict from DLPython Model in Memory Table View Release DL PythonModel in Memory

Nodes

Extensions

Links