Openscoring为PMML Model提供REST web service。

openscoring支持PMML 3.0版本,兼容4.3,evalution通过JPMML-Evaluator库实现。

克隆项目

git clone https://github.com/openscoring/openscoring.git

该项目是maven项目,且分为若干子项目,子项目之间可能存在依赖,因此可以使用如下编译

mvn clean install

服务器端

构建会生成openscoring-server/target/server-executable-1.3-SNAPSHOT.jar ,进入openscoring-server 目录,执行

java -jar target/server-executable-1.3-SNAPSHOT.jar

默认,REST Web Service的访问路径是http://localhost:8080/openscoring

主类org.openscoring.server.Main 可以对URI进行设置。

查看帮助

java -jar target/server-executable-1.3-SNAPSHOT.jar --help

日志设置

java -Djava.util.logging.config.file=logging.properties -jar target/server-executable-1.3-SNAPSHOT.jar

配置设置

java -Dconfig.file=application.conf -jar target/server-executable-1.3-SNAPSHOT.jar

配置文件application.conf内容如下:

modelRegistry {
    visitorClasses = [
        "org.jpmml.model.visitors.LocatorNullifier" // Erases SAX Locator information from the PMML class model object, which will considerably reduce the memory consumption of deployed models
    ]
}

web应用

mvn jetty:run-war

客户端

客户端的jar位于openscoring-client/target/client-executable-1.3-SNAPSHOT.jar

java -cp target/client-executable-1.3-SNAPSHOT.jar org.openscoring.client.Deployer --model http://localhost:8080/openscoring/model/DecisionTreeIris --file DecisionTreeIris.pmml

java -cp target/client-executable-1.3-SNAPSHOT.jar org.openscoring.client.Evaluator --model http://localhost:8080/openscoring/model/DecisionTreeIris -XSepal_Length=5.1 -XSepal_Width=3.5 -XPetal_Length=1.4 -XPetal_Width=0.2

java -cp target/client-executable-1.3-SNAPSHOT.jar org.openscoring.client.CsvEvaluator --model http://localhost:8080/openscoring/model/DecisionTreeIris --input input.csv --output output.csv

java -cp target/client-executable-1.3-SNAPSHOT.jar org.openscoring.client.Undeployer --model http://localhost:8080/openscoring/model/DecisionTreeIris

这里使用tensorflow模型生成的PMML用于部署

java -cp target/client-executable-1.3-SNAPSHOT.jar org.openscoring.client.Deployer --model http://192.168.73.133:9080/openscoring/model/LinearClassificationIris --file LinearClassificationIris.pmml

查看模型部署的API

curl -X GET http://192.168.73.133:9080/openscoring/model/LinearClassificationIris

对数据集进行预测

curl -X POST -H "Content-type: application/json" http://192.168.73.133:9080/openscoring/model/LinearClassificationIris--data \
{
    "id" : "record-001",
    "arguments" : {
        "Petal.Length" : 5.1,
        "Petal.Width" : 3.5,
        "Sepal.Length" : 1.4,
        "Sepal.Width" : 0.2
    }
}

results matching ""

    No results matching ""