diff --git a/chapter-09-kubeflow/test-plain.py b/chapter-09-kubeflow/test-plain.py new file mode 100644 index 0000000..f49d03c --- /dev/null +++ b/chapter-09-kubeflow/test-plain.py @@ -0,0 +1,35 @@ +import requests +from keras_image_helper import create_preprocessor + +preprocessor = create_preprocessor('xception', target_size=(299, 299)) + + +url = 'https://clothing-model.default.kubeflow.mlbookcamp.com/v1/models/clothing-model:predict' + +image_url = "http://bit.ly/mlbookcamp-pants" +X = preprocessor.from_url(image_url) + +data = { + "instances": X.tolist() +} + +resp = requests.post(url, json=data) + +results = resp.json() +pred = results['predictions'][0] + +labels = [ + 'dress', + 'hat', + 'longsleeve', + 'outwear', + 'pants', + 'shirt', + 'shoes', + 'shorts', + 'skirt', + 't-shirt' +] + +result = {c: p for c, p in zip(labels, pred)} +print(result) diff --git a/chapter-09-kubeflow/test-transformer.py b/chapter-09-kubeflow/test-transformer.py new file mode 100644 index 0000000..8f7fe26 --- /dev/null +++ b/chapter-09-kubeflow/test-transformer.py @@ -0,0 +1,15 @@ +import requests + +data = { + "instances": [ + {"url": "http://bit.ly/mlbookcamp-pants"}, + ] +} + +# url = 'http://localhost:8080/v1/models/clothing-model:predict' + +url = 'https://clothing-model.default.kubeflow.mlbookcamp.com/v1/models/clothing-model:predict' + +result = requests.post(url, json=data).json() + +print(result) diff --git a/chapter-09-kubeflow/tf-clothes-plain.yaml b/chapter-09-kubeflow/tf-clothes-plain.yaml new file mode 100644 index 0000000..b958b5f --- /dev/null +++ b/chapter-09-kubeflow/tf-clothes-plain.yaml @@ -0,0 +1,10 @@ +apiVersion: "serving.kubeflow.org/v1beta1" +kind: "InferenceService" +metadata: + name: "clothing-model" +spec: + default: + predictor: + serviceAccountName: sa + tensorflow: + storageUri: "s3://mlbookcamp-models-alexey/clothing-model" diff --git a/chapter-09-kubeflow/tf-clothes.yaml b/chapter-09-kubeflow/tf-clothes.yaml new file mode 100644 index 0000000..aed2195 --- /dev/null +++ b/chapter-09-kubeflow/tf-clothes.yaml @@ -0,0 +1,22 @@ +apiVersion: "serving.kubeflow.org/v1alpha2" +kind: "InferenceService" +metadata: + name: "clothing-model" +spec: + default: + predictor: + serviceAccountName: sa + tensorflow: + storageUri: "s3://mlbookcamp-models-alexey/clothing-model" + transformer: + custom: + container: + image: "agrigorev/kfserving-keras-transformer:0.0.1" + name: user-container + env: + - name: MODEL_INPUT_SIZE + value: "299,299" + - name: KERAS_MODEL_NAME + value: "xception" + - name: MODEL_LABELS + value: "dress,hat,longsleeve,outwear,pants,shirt,shoes,shorts,skirt,t-shirt"