SoftwareAG/nyoka

Support for Regression Neural Networks

hancelpv opened this issue · 8 comments

Hello,

Currently, I see that nyoka can only handle CNNs (MobileNet), which is also given in the example.
Can nyoka support other kind of Neural Networks, specifically the ones used for regression ?

Hi, Yes Nyoka does support DNN based models for regression. We will add a few examples of regression problems in the example section.

For now, below is an example:

Import libraries

import keras
from keras.models import Sequential
from keras.layers import *
import sys
from nyoka import KerasToPmml

Define model

model = Sequential()
model.add(Dense(13, input_dim=13, kernel_initializer='normal', activation='relu'))
model.add(Dense(23))
model.add(Dense(1, kernel_initializer='normal'))

Compile model

model.compile(loss='mean_squared_error', optimizer='adam')

pmmlObj=KerasToPmml(model)
pmmlObj.export(open('RegPMML.pmml','w'),0)

Thanks!

Thank you so much @sharmasw for your prompt reply ! But my issue, is not resolved yet.
I'm attaching my reproducible code and the pmml output file here.
PMML file still shows the attributes of MobileNet model.
Kindly run it and check. Thanks.

from sklearn.datasets import load_boston
from sklearn.model_selection import train_test_split
import pandas as pd
boston = load_boston()
import keras
from keras.models import Sequential
from keras.layers import *
import sys
from nyoka import KerasToPmml

data = pd.DataFrame(boston.data)
features = list(boston.feature_names)
target = 'PRICE'
data.columns = features
data['PRICE'] = boston.target

x_train, x_test, y_train, y_test = train_test_split(data[features], data[target], test_size=0.20, random_state=42)

model = Sequential()
model.add(Dense(13, input_dim=13, kernel_initializer='normal', activation='relu'))
model.add(Dense(23))
model.add(Dense(1, kernel_initializer='normal'))

model.summary()
model.compile(loss='mean_squared_error', optimizer='adam')
model.fit(x_train, y_train, epochs=1000, verbose=0)

model_name = 'Keras_Neural_Net'

model_save_dir = '../Results/'
model_file_path = model_save_dir + str(model_name) + '.pmml'

pmmlObj=KerasToPmml(model)
pmmlObj.export(open(model_file_path,'w'),0)

Could you please share your PMML file. There might be some version issue.

I'm not able to send the file, since the PMML format is not supported for attachments here.

Could you please install the nyoka from GitHub once, might be the issue is with the version of Nyoka installed.
If the problem still persists, I will push a new updated version, and that will solve the problem for sure.

I git cloned the repository, installed the package using the command 'python setup.py install' and re ran the code.
Still, the issue persists. Kindly push an updated version @sharmasw , if you think that'll solve the issue.
Thanks a lot !

Hi @hancelpv. Support for Sequential model is added with Nyoka Build 2.0.0. Please try with the latest build. Also available in PyPI.

Find the example notebook here.
Thanks!