sklearn onnx - expected 2 outputs but got 1
Distortedlogic opened this issue · 1 comments
Distortedlogic commented
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from skl2onnx import convert_sklearn, to_onnx
from skl2onnx.common.data_types import FloatTensorType
import ml2rt, redisai
import numpy as np
rai = redisai.Client(host='127.0.0.1', port='9736')
device = 'CPU'
def make_model():
iris = load_iris()
X, y = iris.data, iris.target
X_train, X_test, y_train, y_test = train_test_split(X, y)
clf = RandomForestClassifier()
clf.fit(X_train, y_train)
return clf, X_train[:1]
def to_onnx_save(clf, sample):
initial_type = [('float_input', FloatTensorType([None, 4]))]
onx = convert_sklearn(clf, initial_types=initial_type)
# onx = to_onnx(clf, sample)
with open("rf_iris.onnx", "wb") as f:
f.write(onx.SerializeToString())
def load_to_redisai():
clf= ml2rt.load_model("rf_iris.onnx")
rai.modelset(
'rf_iris',
'ONNX',
device,
clf
)
if __name__ == "__main__":
clf, sample = make_model()
# returns [one_output]
print(clf.predict(sample))
to_onnx_save(clf, sample)
load_to_redisai()
rai.tensorset("input", sample.astype(np.float32), dtype='float32', shape=sample.shape)
# but requires two outputs here, otherwise throws expected 2 outputs but got 1
rai.modelrun("rf_iris", ["input"], ["output1", "output2"])
outtensor = rai.tensorget("output1")
print(outtensor)
# output2 key is empty but required in modelrun
outtensor = rai.tensorget("output2")
print(outtensor)
hhsecond commented
Hi @Distortedlogic, Thanks a lot for raising the issue. This is an issue with RedisAI itself and is being tracked here. Currently, the workaround for this is to provide dummy output to your modelrun
(like output2
in your example) but ignore them since that wouldn't be set. Feel free to reopen the issue if you have more questions.