1 Star 0 Fork 0

Mike_W / daas-client

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README.md 4.42 KB
一键复制 编辑 原始数据 按行查看 历史
scorebot 提交于 2020-07-31 09:25 . support pytorch

DaaS-Client

DaaS-Client is Python client library for DaaS(Deployment-as-a-Service)

Features

DaaS-Client helps to publish your AI/ML models in Python, test and deploy them easily.

It supports the following models by default, more types will be added in the list.

  • Scikit-learn
  • XGBoost
  • LightGBM
  • Keras and Tensorflow(tf.keras)
  • PySpark
  • PMML
  • ONNX
  • PyTorch
  • Custom models

Prerequisites

  • Python 2.7 or >= 3.5

Dependencies

  • requests
  • numpy
  • pandas
  • pypmml
  • onnx
  • onnxruntime

Installation

Install the latest version from github:

pip install --upgrade git+https://github.com/autodeployai/daas-client.git

Usage

  1. Initiate a client with URL of DaaS server, username, password, and optional project, e.g.

    from daas_client import DaasClient
    
    client = DaasClient('https://192.168.64.3:31753', 'admin', 'password')
  2. Call publish to publish models into DaaS server. There are two methods to call this function, one is for PySpark, the other is for others. For the PMML model, you can use either.

    Load the iris data from sklearn datasets

    iris = datasets.load_iris()
    iris_target_name = 'Species'
    iris_feature_names = iris.feature_names
    iris_df = pd.DataFrame(iris.data, columns=iris_feature_names)
    iris_df[iris_target_name] = iris.target

    Train and publish a Random Forest model of PySpark. NOTE: the spark model must be a Pipeline model

    df = spark.createDataFrame(iris_df)
    df_train, df_test = df.randomSplit([0.7, 0.3])
    assembler = VectorAssembler(inputCols=iris_feature_names, outputCol='features')
    rf = RandomForestClassifier().setLabelCol(iris_target_name)
    pipe = Pipeline(stages=[assembler, rf])
    model = pipe.fit(df_train)
    
    publish_resp = client.publish(model, name='spark-cls', mining_function='classification', data_test=df_test, description='A Spark classification model')

    Train and publish a XGBoost model

    X, y = iris_df[iris_feature_names], iris_df[iris_target_name]
    x_train, x_test, y_train, y_test = train_test_split(X, y, test_size=0.3)
    model = XGBClassifier(max_depth=3, objective='multi:softprob')
    model.fit(x_train, y_train)
    
    publish_resp = client.publish(model, name='xgboost-cls', mining_function='classification', x_test=x_test, y_test=y_test, description='A XGBoost classification model')

    The result is a dict with published model name and version if success, e.g.

    {'model_name': 'xgboost-cls', 'model_version': '1'}
  3. Call test to test the published model in the development mode.

    test_resp = client.test('xgboost-cls', model_version=publish_resp['model_version'])

    The result is a dict with all info of the REST service of testing a published model with its version, e.g.

    {'access_token': 'A-LONG-STRING-OF-BEARER-TOKEN-USED-IN-HTTP-HEADER-AUTHORIZATION',
     'endpoint_url': 'https://192.168.64.3:31753/api/v1/test/examples/daas-python37-faas/test',
     'payload': {'args': {'X': [{'petal length (cm)': 1.5,
                                 'petal width (cm)': 0.4,
                                 'sepal length (cm)': 5.7,
                                 'sepal width (cm)': 4.4}],
                          'model_name': 'xgboost-cls',
                          'model_version': '1'}}}
        
  4. Call deploy to deploy the published model in the product mode.

    deploy_resp = client.deploy('xgboost-cls', deployment_name='xgboost-cls-svc', model_version=publish_resp['model_version'])

    The result is a dict with all info of the REST service of deploying a published model with its version, e.g.

    {'access_token': 'A-LONG-STRING-OF-BEARER-TOKEN-USED-IN-HTTP-HEADER-AUTHORIZATION',
     'endpoint_url': 'https://192.168.64.3:31753/api/v1/svc/examples/xgboost-cls-svc/predict',
     'payload': {'args': {'X': [{'petal length (cm)': 1.5,
                                 'petal width (cm)': 0.4,
                                 'sepal length (cm)': 5.7,
                                 'sepal width (cm)': 4.4}]}}}

You can refer to the example Jupyter notebooks for more details.

Support

If you have any questions about the DaaS-Client library, please open issues on this repository.

License

DaaS-Client is licensed under APL 2.0.

1
https://gitee.com/Mike_W/daas-client.git
git@gitee.com:Mike_W/daas-client.git
Mike_W
daas-client
daas-client
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891