Skip to content

Commit

Permalink
added doppelganger sample from antje
Browse files Browse the repository at this point in the history
  • Loading branch information
cfregly committed Oct 21, 2019
1 parent fbd010f commit 689a0e7
Show file tree
Hide file tree
Showing 23 changed files with 1,514 additions and 0 deletions.
1,015 changes: 1,015 additions & 0 deletions kubeflow/notebooks/doppelganger/Doppelganger_A.ipynb

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions kubeflow/notebooks/doppelganger/code/inference/Dockerfile-v1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM python:3.6-slim

COPY ./requirements.txt /app/requirements.txt
WORKDIR /app
RUN pip install -r requirements.txt
COPY DoppelgangerModel.py /app
COPY pairwise_top_25_v1.json pairwise_top_25.json

ENV MODEL_NAME DoppelgangerModel
ENV API_TYPE REST
ENV SERVICE_TYPE MODEL
ENV PERSISTENCE 0

EXPOSE 5000

CMD exec seldon-core-microservice $MODEL_NAME $API_TYPE --service-type $SERVICE_TYPE --persistence $PERSISTENCE
16 changes: 16 additions & 0 deletions kubeflow/notebooks/doppelganger/code/inference/Dockerfile-v2
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM python:3.6-slim

COPY ./requirements.txt /app/requirements.txt
WORKDIR /app
RUN pip install -r requirements.txt
COPY DoppelgangerModel.py /app
COPY pairwise_top_25_v2.json pairwise_top_25.json

ENV MODEL_NAME DoppelgangerModel
ENV API_TYPE REST
ENV SERVICE_TYPE MODEL
ENV PERSISTENCE 0

EXPOSE 5000

CMD exec seldon-core-microservice $MODEL_NAME $API_TYPE --service-type $SERVICE_TYPE --persistence $PERSISTENCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import keras
import sys
import numpy as np
import json

class DoppelgangerModel(object):
def __init__(self):
print("\n** LOADING MODEL from pairwise_top_25.json **")
with open('pairwise_top_25.json') as fp:
self.model = json.load(fp)
print("\n** LOADED MODEL from pairwise_top_25.json **")

def predict(self, X, feature_names):
similar_image_arr = self.model[str(int(X[0]))]
return similar_image_arr

if __name__== "__main__":
model = DoppelgangerModel()
print(model.predict([0], ['image_id']))
6 changes: 6 additions & 0 deletions kubeflow/notebooks/doppelganger/code/inference/build-v1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash -e

docker build -t antjebarth/doppelganger-predict:1.0.0 -f Dockerfile-v1 .
docker push antjebarth/doppelganger-predict:1.0.0

#kubectl create -f doppelganger-predict-deploy.yaml
6 changes: 6 additions & 0 deletions kubeflow/notebooks/doppelganger/code/inference/build-v2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash -e

docker build -t antjebarth/doppelganger-predict:2.0.0 -f Dockerfile-v2 .
docker push antjebarth/doppelganger-predict:2.0.0

#kubectl create -f doppelganger-predict-deploy-ab-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
apiVersion: machinelearning.seldon.io/v1alpha2
kind: SeldonDeployment
metadata:
generation: 1
labels:
app: seldon
name: abtest-model
namespace: deployment
spec:
name: abtest-model
predictors:
- componentSpecs:
- spec:
containers:
- env:
- name: PREDICTIVE_UNIT_SERVICE_PORT
value: "9000"
- name: PREDICTIVE_UNIT_ID
value: classifier-1
- name: PREDICTOR_ID
value: abtest
- name: SELDON_DEPLOYMENT_ID
value: abtest-model
image: antjebarth/doppelganger-predict:1.0.0
imagePullPolicy: Always
lifecycle:
preStop:
exec:
command:
- /bin/sh
- -c
- /bin/sleep 10
livenessProbe:
failureThreshold: 3
initialDelaySeconds: 60
periodSeconds: 5
successThreshold: 1
tcpSocket:
port: http
timeoutSeconds: 1
name: classifier-1
ports:
- containerPort: 9000
name: http
protocol: TCP
readinessProbe:
failureThreshold: 3
initialDelaySeconds: 20
periodSeconds: 5
successThreshold: 1
tcpSocket:
port: http
timeoutSeconds: 1
resources:
requests:
memory: 1Mi
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /etc/podinfo
name: podinfo
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 20
volumes:
- downwardAPI:
defaultMode: 420
items:
- fieldRef:
apiVersion: v1
fieldPath: metadata.annotations
path: annotations
name: podinfo
- metadata:
labels:
version: v2
spec:
containers:
- env:
- name: PREDICTIVE_UNIT_SERVICE_PORT
value: "9000"
- name: PREDICTIVE_UNIT_ID
value: classifier-2
- name: PREDICTOR_ID
value: abtest
- name: SELDON_DEPLOYMENT_ID
value: abtest-model
image: antjebarth/doppelganger-predict:2.0.0
imagePullPolicy: Always
lifecycle:
preStop:
exec:
command:
- /bin/sh
- -c
- /bin/sleep 10
livenessProbe:
failureThreshold: 3
initialDelaySeconds: 60
periodSeconds: 5
successThreshold: 1
tcpSocket:
port: http
timeoutSeconds: 1
name: classifier-2
ports:
- containerPort: 9000
name: http
protocol: TCP
readinessProbe:
failureThreshold: 3
initialDelaySeconds: 20
periodSeconds: 5
successThreshold: 1
tcpSocket:
port: http
timeoutSeconds: 1
resources:
requests:
memory: 1Mi
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /etc/podinfo
name: podinfo
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 20
volumes:
- downwardAPI:
defaultMode: 420
items:
- fieldRef:
apiVersion: v1
fieldPath: metadata.annotations
path: annotations
name: podinfo
graph:
children:
- children: []
endpoint:
service_host: localhost
service_port: 9000
type: REST
implementation: UNKNOWN_IMPLEMENTATION
name: classifier-1
type: MODEL
- children: []
endpoint:
service_host: localhost
service_port: 9000
type: REST
implementation: UNKNOWN_IMPLEMENTATION
name: classifier-2
type: MODEL
endpoint: {}
implementation: RANDOM_ABTEST
name: abtest-model
parameters:
- name: ratioA
type: FLOAT
value: "0.5"
type: UNKNOWN_TYPE
name: abtest
replicas: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
apiVersion: machinelearning.seldon.io/v1alpha2
kind: SeldonDeployment
metadata:
generation: 1
labels:
app: seldon
name: doppelganger-model
namespace: deployment
spec:
annotations:
seldon.io/engine-log-message-type: seldon.message.pair
seldon.io/engine-log-messages-externally: "false"
seldon.io/engine-log-requests: "false"
seldon.io/engine-log-responses: "false"
seldon.io/headless-svc: "false"
name: doppelganger-model
predictors:
- componentSpecs:
- spec:
containers:
- env:
- name: LOG_LEVEL
value: INFO
- name: PREDICTIVE_UNIT_SERVICE_PORT
value: "5000"
- name: PREDICTIVE_UNIT_ID
value: recommender
- name: PREDICTOR_ID
value: doppelganger-model
- name: SELDON_DEPLOYMENT_ID
value: doppelganger-model
image: antjebarth/doppelganger-predict:1.0.0
imagePullPolicy: Always
lifecycle:
preStop:
exec:
command:
- /bin/sh
- -c
- /bin/sleep 10
livenessProbe:
failureThreshold: 3
initialDelaySeconds: 60
periodSeconds: 5
successThreshold: 1
tcpSocket:
port: http
timeoutSeconds: 1
name: recommender
ports:
- containerPort: 5000
name: http
protocol: TCP
readinessProbe:
failureThreshold: 3
initialDelaySeconds: 20
periodSeconds: 5
successThreshold: 1
tcpSocket:
port: http
timeoutSeconds: 1
resources:
requests:
memory: 1Mi
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /etc/podinfo
name: podinfo
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 20
volumes:
- downwardAPI:
defaultMode: 420
items:
- fieldRef:
apiVersion: v1
fieldPath: metadata.annotations
path: annotations
name: podinfo
graph:
children: []
endpoint:
service_host: localhost
service_port: 5000
type: REST
implementation: UNKNOWN_IMPLEMENTATION
name: recommender
type: MODEL
labels:
fluentd: "true"
version: v1
name: doppelganger-model
replicas: 1
svcOrchSpec:
env: []
resources:
requests:
cpu: "0.1"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"0": ["http://c0198e9d-istiosystem-istio-2af2-1928351968.eu-central-1.elb.amazonaws.com/notebook/doppelganger/doppelganger/view/doppelganger/code/training/images/n02085620-Chihuahua/n02085620_10976.jpg", "http://c0198e9d-istiosystem-istio-2af2-1928351968.eu-central-1.elb.amazonaws.com/notebook/doppelganger/doppelganger/view/doppelganger/code/training/images/n02087046-toy_terrier/n02087046_3211.jpg", "http://c0198e9d-istiosystem-istio-2af2-1928351968.eu-central-1.elb.amazonaws.com/notebook/doppelganger/doppelganger/view/doppelganger/code/training/images/n02089973-English_foxhound/n02089973_2484.jpg", "http://c0198e9d-istiosystem-istio-2af2-1928351968.eu-central-1.elb.amazonaws.com/notebook/doppelganger/doppelganger/view/doppelganger/code/training/images/n02109047-Great_Dane/n02109047_9604.jpg", "http://c0198e9d-istiosystem-istio-2af2-1928351968.eu-central-1.elb.amazonaws.com/notebook/doppelganger/doppelganger/view/doppelganger/code/training/images/n02110185-Siberian_husky/n02110185_3406.jpg"]}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"0": ["http://c0198e9d-istiosystem-istio-2af2-1928351968.eu-central-1.elb.amazonaws.com/notebook/doppelganger/doppelganger/view/doppelganger/code/training/images/n02110185-Siberian_husky/n02110185_3406.jpg", "http://c0198e9d-istiosystem-istio-2af2-1928351968.eu-central-1.elb.amazonaws.com/notebook/doppelganger/doppelganger/view/doppelganger/code/training/images/n02109047-Great_Dane/n02109047_9604.jpg", "http://c0198e9d-istiosystem-istio-2af2-1928351968.eu-central-1.elb.amazonaws.com/notebook/doppelganger/doppelganger/view/doppelganger/code/training/images/n02085620-Chihuahua/n02085620_10976.jpg", "http://c0198e9d-istiosystem-istio-2af2-1928351968.eu-central-1.elb.amazonaws.com/notebook/doppelganger/doppelganger/view/doppelganger/code/training/images/n02089973-English_foxhound/n02089973_2484.jpg", "http://c0198e9d-istiosystem-istio-2af2-1928351968.eu-central-1.elb.amazonaws.com/notebook/doppelganger/doppelganger/view/doppelganger/code/training/images/n02087046-toy_terrier/n02087046_3211.jpg"]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
tensorflow==1.13.1
keras==2.2.4
scikit-learn
numpy
pandas
pillow
flask
seldon-core==0.4.1
2 changes: 2 additions & 0 deletions kubeflow/notebooks/doppelganger/code/inference/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash -e
docker run -p 4444:5000 antjebarth/doppelganger-predict:1.0.0
3 changes: 3 additions & 0 deletions kubeflow/notebooks/doppelganger/code/inference/test-local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash -e

curl -d 'json={"data":{"ndarray":[[0]]}}' http://0.0.0.0:4444/predict
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
curl http://c0198e9d-istiosystem-istio-2af2-1928351968.eu-central-1.elb.amazonaws.com/seldon/deployment/abtest-model/api/v0.1/predictions -d '{"data":{"ndarray":[[0]]}}' -H "Content-Type: application/json"

# curl http://c0198e9d-istiosystem-istio-2af2-1928351968.eu-central-1.elb.amazonaws.com/seldon/deployment/abtest-model/api/v0.1/predictions -d '{"data":{"names":["image_id"],"tensor":{"shape":[1,1],"values":[0]}}}' -H "Content-Type: application/json"
3 changes: 3 additions & 0 deletions kubeflow/notebooks/doppelganger/code/inference/test-prod.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
curl http://c0198e9d-istiosystem-istio-2af2-1928351968.eu-central-1.elb.amazonaws.com/seldon/deployment/doppelganger-model/api/v0.1/predictions -d '{"data":{"ndarray":[[0]]}}' -H "Content-Type: application/json"

# curl http://c0198e9d-istiosystem-istio-2af2-1928351968.eu-central-1.elb.amazonaws.com/seldon/deployment/doppelganger-model/api/v0.1/predictions -d '{"data":{"names":["id"],"tensor":{"shape":[1,1],"values":[0]}}}' -H "Content-Type: application/json"
3 changes: 3 additions & 0 deletions kubeflow/notebooks/doppelganger/code/inference/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash -e

curl -d 'json={"data":{"ndarray":[[0]]}}' http://0.0.0.0:4444/predict
2 changes: 2 additions & 0 deletions kubeflow/notebooks/doppelganger/code/training/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
images/
Images/
10 changes: 10 additions & 0 deletions kubeflow/notebooks/doppelganger/code/training/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM python:3.6-slim

COPY images/ images/

COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt

COPY doppelganger-train.py doppelganger-train.py
CMD [ "python", "doppelganger-train.py" ]

Loading

0 comments on commit 689a0e7

Please sign in to comment.