Support for data science with Python
In this article we introduce Nyoka, a new Python-based library that exports predictive models from popular machine learning/deep learning frameworks to PMML. Using Nyoka, data scientists can standardize and accelerate the deployment process for predictive models.
By Alexander Lemm, Sr. Product Manager, Predictive Analytics, Software AG and Dr. Rainer Burkhardt, Sr. Director, AI Analytics, Software AG
Issue 4, 2018 | Download PDF |
---|
Introduction
In August, Software AG released Nyoka on GitHub®, a Python library for data scientists. But what is Nyoka exactly and what does it stand for? Using Nyoka, a data scientist can export predictive models created with popular Python-based machine learning or deep learning frameworks into PMML (see figure 1 below). "Nyoka" originates from Zulu and means "snake," hence the close connection to its Python cousin.
Fig 1: Supported Machine Learning and Deep Learning Frameworks
PMML is an XML-based predictive model interchange format and the leading standard for statistical and machine learning models. The Data Mining Group (DMG) is an independent, vendor-led consortium that supports and drives the development of PMML for nearly 20 years now.
Nyoka underscores Software AG's Artificial Intelligence (AI) strategy and vision of open industry standards: PMML as the unifying standard for machine learning AND deep learning models.
Nyoka in action
Let us check out a simple example on how you can use Nyoka to export a pre-trained MobileNet model for image recognition from Keras to PMML. Here we assume that you already loaded all necessary libraries into memory.
# load pretrained keras mobilenet model model = mobilenet.MobileNet(input\_shape=(224, 224, 3), alpha=1.0, depth\_multiplier=1, dropout=1e-3, include\_top=True, weights='imagenet', input\_tensor=None, pooling=None, classes=1000) # convert mobilnet model to PMML cnn\_pmml = KerasToPmml(model, model\_name="KerasMobileNet", dataSet="ImageNet") # Save mobilenet PMML to disk cnn\_pmml.export(open("mobilenet\_demo.pmml, "w"),0)
Constructing an object named cnn_pmml as an instance of the Nyoka class KerasToPMML() is all you need to do to convert the MobileNet model into its PMML representation. Saving it to disk is done by calling the method export().
But what is a PMML file good for when you don't leverage it for predicting new and unseen values – which are in our case unclassified images?
To do just this, we use one execution engine for PMML files, the Zementis Server, Software AG's flagship product in the AI domain. Therefore, deploying the created PMML file from the example above to a Zementis Server instance is next. We assume again that you already loaded all necessary libraries into memory.
pmml\_file = open(mobilenet\_demo.pmml,"r") pmml = {'file': pmml\_file} pmml\_upload = requests.post(adapaRS + "model/", files=pmml, auth=auth, verify=False, params = {"applyCleanser": "FALSE"})
The model is now deployed to a Zementis Server instance and can be executed to classify any unseen image. We will send the following picture to the server showing a great white shark.
Fig 2: Image we are going to Classify
f = open("shark\_224\_224.png", "rb") files ={'file':f.read()} resp = requests.post(adapaRS+'apply/KerasMobileNet' , auth=auth, files=files,headers={},verify=False)
Curious what the classification result from the Zementis Server is? Let's check it out!
Print(resp.text) { "model" : "KerasMobileNet", "outputs" : [{ "top1\_prob" : 0.9951145648956299, "predictedValue\_predictions" : "great\_white\_shark", "top5\_prob" : "great\_white\_shark:0.9951145648956299,tiger\_shark:0.0029412976000458,sturgeon:0.0012288052821531892,dugong:3.0053118825890124E-4,killer\_whale:2.2845140483696014E-4" }] }
As you can see, the deployed MobileNet model classifies the image as a great white shark with an probability of 99.5%.
Examining the output you see that Zementis Server not just gives you the best classification result and the respective probability but in fact the five best results.
Conclusion
In this article we just scratched the surface of Nyoka's capabilities. With Nyoka you can even create your own exporters for specialized/individual model types.
You would like to learn more about Nyoka and make a deep dive yourself? Please check out the following links:
- Nyoka is available on GitHub including Docs and comes with Jupyter notebook based tutorials. And if you have feedback and questions about Nyoka - just open a GitHub issue and we'll get back to you!
- If you would like to go one step further and put your generated PMML files into action, get a free trial license for Zementis Server, our PMML execution engine.
Learn more about Zementis and download your free trial today.
Top comments (0)