Create a DL model and publish it

This tutorial explains

  1. How to create a DL model using rztdl api's in jupyter notebook and publish the model so that it can be accessed from the model designer in IDE.
  2. How to import a model created through model deisigner into jupyter notebook

1. Create model

1.1 Import required packages from rztdl SDK

from rztdl.dl.model import RZTModel
from rztdl.dl.components.layers import Input, Dense
from rztdl.dl.components.losses import BinaryCrossentropy
from rztdl.dl.optimizers import Adam
Using default configs as no custom logging config was provided

1.2 Create the model by adding layers, loss and optimizer

model = RZTModel(name="binary_classifier")
model.add(Input(shape=[4], name="Input_Image"))
model.add(Dense(units=16, name="dense1"))
model.add(Dense(units=4, name="dense2"))
model.add(Dense(units=1, name="dense3", outputs="dense_out"))
model.add(Input(shape=[1], name="Label"))
model.add(BinaryCrossentropy(name="nll",predictions="dense_out", labels="Label" ))
model.add(Adam(name="adam"))
INFO:rztdl.dl.model:Input Layer 'Input_Image'  validated successfully
INFO:rztdl.dl.model:Dense Layer 'dense1' validated successfully
INFO:rztdl.dl.model:Dense Layer 'dense2' validated successfully
INFO:rztdl.dl.model:Dense Layer 'dense3' validated successfully
INFO:rztdl.dl.model:Input Layer 'Label'  validated successfully
INFO:rztdl.dl.model:BinaryCrossentropy Loss 'nll' validated successfully
INFO:rztdl.dl.model:Adam Optimizer 'adam' validated successfully

1.3 Publish the model to model designer

from razor.api import dlmodels
dlmodels.export_model(model)
{'id': '0db137e1-aa0d-4013-824e-e1bd3b9aa9ef',
 'name': 'binary_classifier',
 'description': '',
 'createdOn': '2020-10-09T10:34:25.573+0530',
 'createdBy': 'Sunil Vengalil V',
 'modifiedBy': 'Sunil Vengalil V',
 'modifiedOn': '2020-10-09T10:34:25.573+0530',
 'validationResponse': {'validModel': True,
  'model': {'warnings': None,
   'error': [],
   'slots': None,
   'parameters': None,
   'iterations': None,
   'sharedComponentDetail': None},
  'blocks': {},
  'groups': {},
  'stacks': {},
  'deletedComponents': None,
  'updatedComponents': None,
  'grayLogSaveId': '8d9e10bd-bec9-46ec-98ae-b3298cc1049c'},
 'version': None,
 'template': None,
 'publishStatus': None,
 'framework': {'frameworkVersion': '3.0',
  'baseInstallationPath': '/bigbrain/python_libs/BBDL_FRAMEWORK/3.0/',
  'tfHubModelsPath': '/bigbrain/python_libs/BBDL_FRAMEWORK/3.0/tf_hub_models/'},
 'daysToResolve': None,
 'libraryDetailList': None,
 'valid': True}

The model with name binary_classifier start appearing in the DL model designer page and can be used like any other model created using model designer

2. Importing a model created through DL model designer into jupyter notebook

imported_model = dlmodels.import_model("binary_classifier")
INFO:root:TF Version 2.1.0
INFO:root:RZTDL Version 3.1.14
INFO:root:Parser Version 3.1.14
INFO:rztdl.dl.model:Input Layer 'Label'  validated successfully
INFO:rztdl.dl.model:Input Layer 'Input_Image'  validated successfully
INFO:rztdl.dl.model:Dense Layer 'dense1' validated successfully
INFO:rztdl.dl.model:Dense Layer 'dense2' validated successfully
INFO:rztdl.dl.model:Dense Layer 'dense3' validated successfully
INFO:rztdl.dl.model:BinaryCrossentropy Loss 'nll' validated successfully
INFO:rztdl.dl.model:Adam Optimizer 'adam' validated successfully





<rztdl.dl.model.RZTModel at 0x7f98c4657dd0>

One can create a pipeline using imported_model and initiate a train/inferene/evaluation flow