-
Notifications
You must be signed in to change notification settings - Fork 834
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add minimal example of deploying pachyderm-trained model
- Loading branch information
1 parent
401aead
commit ef43d9e
Showing
11 changed files
with
1,100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
data.csv | ||
model.joblib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
apiVersion: machinelearning.seldon.io/v1 | ||
kind: SeldonDeployment | ||
metadata: | ||
name: pachyderm-sklearn | ||
spec: | ||
annotations: | ||
seldon.io/executor: "true" | ||
name: iris | ||
predictors: | ||
- componentSpecs: | ||
graph: | ||
children: [] | ||
implementation: SKLEARN_SERVER | ||
modelUri: s3://pachyderm-iris | ||
envSecretRefName: seldon-init-container-secret | ||
name: classifier | ||
name: default | ||
replicas: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from sklearn import datasets | ||
import pandas as pd | ||
import numpy as np | ||
|
||
|
||
def main(): | ||
print("Getting Iris Dataset") | ||
iris = datasets.load_iris() | ||
X, y = iris.data, iris.target | ||
|
||
data = pd.DataFrame( | ||
data=np.c_[iris["data"], iris["target"]], | ||
columns=iris["feature_names"] + ["target"], | ||
) | ||
|
||
data.to_csv("data.csv", index=False) | ||
print("Iris dataset saved to 'data.csv' file") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
FROM python:3.7 | ||
|
||
ADD requirements.txt . | ||
RUN pip install -r requirements.txt | ||
|
||
ADD train_iris.py . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
VERSION=0.1 | ||
IMAGE_BASE=seldonio/pachyderm-iris-trainer | ||
|
||
KIND_NAME ?= kind | ||
|
||
|
||
build: | ||
docker build . -t ${IMAGE_BASE}:${VERSION} | ||
|
||
push: | ||
docker push ${IMAGE_BASE}:${VERSION} | ||
|
||
kind_load: | ||
kind load -v 3 docker-image ${IMAGE_BASE}:${VERSION} --name ${KIND_NAME} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
scikit-learn == 0.20.3 | ||
numpy >= 1.8.2 | ||
joblib >= 0.13.0 | ||
pandas >= 1.0.1 | ||
pyaml >= 5.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import os | ||
import yaml | ||
import joblib | ||
import pandas as pd | ||
from sklearn.pipeline import Pipeline | ||
from sklearn.linear_model import LogisticRegression | ||
|
||
|
||
# /pfs/iris-data and /pfs/outs are special directories mounted by Pachyderm | ||
INPUT_FILE = os.path.join("/pfs/iris-data", "data.csv") | ||
OUTPUT_FILE = os.path.join("/pfs/out", "model.joblib") | ||
|
||
|
||
def main(): | ||
clf = LogisticRegression(solver="liblinear", multi_class="ovr") | ||
p = Pipeline([("clf", clf)]) | ||
print("Training model...") | ||
p.fit(X, y) | ||
print("Model trained!") | ||
|
||
print(f"Saving model in {OUTPUT_FILE}") | ||
joblib.dump(p, OUTPUT_FILE) | ||
print("Model saved!") | ||
|
||
|
||
if __name__ == "__main__": | ||
print(f"Loading iris data set from {INPUT_FILE}") | ||
data = pd.read_csv(INPUT_FILE) | ||
y = data["target"] | ||
X = data[(x for x in data.columns if x != "target")] | ||
print("Dataset loaded!") | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
name: iris | ||
versions: [iris/pachyderm:789a6e406b90450185b4280ab16b7f14] | ||
platform: sklearn | ||
inputs: | ||
- datatype: BYTES | ||
name: input | ||
shape: [ 1, 4 ] | ||
outputs: | ||
- datatype: BYTES | ||
name: output | ||
shape: [ 3 ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: seldon-init-container-secret | ||
type: Opaque | ||
stringData: | ||
AWS_ACCESS_KEY_ID: minioadmin | ||
AWS_SECRET_ACCESS_KEY: minioadmin | ||
AWS_ENDPOINT_URL: http://minio.minio-system.svc.cluster.local:9000 | ||
USE_SSL: "false" |
Oops, something went wrong.