Building Image Classification AI with Interplay

This time we to see making a Classification Model to segregate Samples of Pneumonia

Written By Chetan Iterate ()

Updated at January 15th, 2021

So, now we have quite a good idea about the interplay platform for building our APIs and services, but in interplay, you can even train your AI and deploy as you desire, Here in this example, we created a simple classification model for detecting pneumonia patients and classify them as a Pneumonia patient or Normal one.

Training Specimens :

Output : 


1 ) search for 'inject' node which looks like this: Drop this node in editor.

 Search for the 'function' node which looks like this :

also, drop this node in the editor.

The 'console' node is optional and can be used for viewing console output when development is needed, search and drop in the editor. This node looks like this:

2) Connect these nodes to create flow as shown in figure (for this example, we named: [X-RAY ] Image Classification) to host our main flow, Here We renamed "Python function" to "Dir-maker" which can be done by double-clicking and giving it name using "Name":3) Prior to train a model (In this case of the classification model), we need to create a directory structure for the project which is as:

Inject the code where function generates the structure of folder as given above.

Simplifying the process by a python script.


 //# root path path = './public/private/Image_Classification/' project_name = path + "pneumonia" try:     os.mkdir(path)     os.mkdir(project_name) except:    os.mkdir(project_name) required_dir_struct = ['Dataset', 'Temp', 'Executed_NB', 'Models', 'Results', 'QueryImages'] for folder in required_dir_struct: try:     os.mkdir(project_name+'/'+folder) except OSError as error: print(error) status = 'Dir struct has been created !' msg['payload'] = status return status

This will create Directories as a script for viewing directory click on:

We can see the directory structure Generated as:

5) Create a new node with the same 'inject', 'Python 3', 'HTTP output', 'console' and connect them as shown in the figure :

The Fastai framework is used for training a model for this project as the Fastai background works on Jupyter notebook.

Code in: Trainer

import subprocess
import papermill as pm
import os
from os import path
def execute(): result_json =         pm.execute_notebook("/interplay_v2/public/private/Image_Classification/pneumonia/I    mg-classification-base-v1.ipynb","/interplay_v2/public/private/Image_Classification/pneumonia/Executed_NB/executed-img-class-v1.ipynb") return result_json final_execute = execute() msg['payload'] = final_execute 
return msg

8) Click on the Trigger point of the inject node (Highlighted) :

9) After triggering the second node initiates the Jupyter notebook consisting of Training AI with predefined parameters, we can see the console parameter output similar to this :

The final part is to segregate images based on trained output from the model.

6) Here comes the classification part, beneath our created route let's create a new route by dropping the same 'inject', 'Python 3 Fastai ', 'console', 'HTTP output' and connect them as shown: Code in Predictor

def execute():     PROJECT_NAME_ = "pneumonia"     MODEL_Ver_ = "v2"     USER_QUERY_FOLDER_PATH_ = "/interplay_v2/public/private/Image_Classification/pneumonia/Dataset/test/PNEUMONIA/"     result_json = pm.execute_notebook("/interplay_v2/public/private/Image_Classification/pneumonia/(prediction-interplay)img-predictor-v2-(bunch-predict).ipynb","/interplay_v2/public/private/Image_Classification/pneumonia/Executed_NB/(=>)File_v1.ipynb",     parameters =dict(PROJECT_NAME=PROJECT_NAME_,MODEL_Ver=MODEL_Ver_,USER_QUERY_FOLDER_PATH=USER_QUERY_FOLDER_PATH_))     return result_json final_execute = execute() msg['payload'] = final_execute return msg

7) Click on "Deploy", after Successful deployment notification, we can trigger nodes as we desire,

8) Click on the Trigger point of the inject node (Highlighted) :

after triggering the third flow (Predictor) wait for some time for classification output and segregated as Pneumonia and Normal one are stored in our working directory in the 'Results' folder.

Was this article helpful?