<jupyter_start><jupyter_text>MNIST Outlier Detection (WIP)Skaffolding for MNIST Outlier Detection demo.Create Minikube:```minikube start --vm-driver kvm2 --memory 4096 --feature-gates=CustomResourceValidation=true --extra-config=apiserver.Authorization.Mode=RBAC```  Setup<jupyter_code>%matplotlib inline
import requests
from random import randint,random
import json
from matplotlib import pyplot as plt
import numpy as np
from tensorflow.examples.tutorials.mnist import input_data
import sys
sys.path.append("../../../notebooks")
from visualizer import get_graph
def gen_image(arr):
    two_d = (np.reshape(arr, (28, 28)) * 255).astype(np.uint8)
    plt.imshow(two_d,cmap=plt.cm.gray_r, interpolation='nearest')
    return plt

def download_mnist():
    return input_data.read_data_sets("MNIST_data/", one_hot = True)

def rest_predict_request(endpoint,data):
    request = {"data":{"ndarray":data.tolist()}}
    response = requests.post(
                "http://"+endpoint+"/predict",
                data={"json":json.dumps(request),"isDefault":True})
    return response.json()   

def rest_transform_input_request(endpoint,data):
    request = {"data":{"ndarray":data.tolist()}}
    response = requests.post(
                "http://"+endpoint+"/transform-input",
                data={"json":json.dumps(request),"isDefault":True})
    return response.json()   

def rest_transform_output_request(endpoint,data):
    request = {"data":{"ndarray":data.tolist()}}
    response = requests.post(
                "http://"+endpoint+"/transform-output",
                data={"json":json.dumps(request),"isDefault":True})
    return response.json()   

def rest_request_ambassador(deploymentName,endpoint="localhost:8003",arr=None):
    payload = {"data":{"names":["a","b"],"tensor":{"shape":[1,784],"values":arr.tolist()}}}
    response = requests.post(
                "http://"+endpoint+"/seldon/"+deploymentName+"/api/v0.1/predictions",
                json=payload)
    print(response.status_code)
    print(response.text)


def gen_mnist_data(mnist):
    batch_xs, batch_ys = mnist.train.next_batch(1)
    chosen=0
    gen_image(batch_xs[chosen]).show()
    data = batch_xs[chosen].reshape((1,784))
    return data

mnist = download_mnist()<jupyter_output><empty_output><jupyter_text>Test<jupyter_code>!kubectl create clusterrolebinding kube-system-cluster-admin --clusterrole=cluster-admin --serviceaccount=kube-system:default
!kubectl create namespace seldon
!kubectl config set-context $(kubectl config current-context) --namespace=seldon
!kubectl -n kube-system create sa tiller
!kubectl create clusterrolebinding tiller --clusterrole cluster-admin --serviceaccount=kube-system:tiller
!helm init --service-account tiller
!kubectl rollout status deploy/tiller-deploy -n kube-system
!helm install ../../../helm-charts/seldon-core-crd --name seldon-core-crd \
    --set usage_metrics.enabled=true
!helm install ../../../helm-charts/seldon-core --name seldon-core \
        --namespace seldon \
        --set ambassador.enabled=true
!kubectl rollout status deploy/seldon-core-seldon-cluster-manager -n seldon
!kubectl rollout status deploy/seldon-core-seldon-apiserver -n seldon
!helm install ../../../helm-charts/seldon-single-model \
    --set outlier_detection.enabled=true \
    --set outlier_detection.image.name=seldonio/outlier_mahalanobis:0.3 \
    --set outlier_detection.n_components=3 \
    --name seldon-model --set oauth.key=oauth-key \
    --set oauth.secret=oauth-secret \
    --set model.image.name=seldonio/sk-mnist:0.1 \
    --namespace=seldon<jupyter_output><empty_output><jupyter_text>**Port forward Ambassador**```kubectl port-forward $(kubectl get pods -n seldon -l service=ambassador -o jsonpath='{.items[0].metadata.name}') -n seldon 8003:8080```  Test with Real Data<jupyter_code>data = gen_mnist_data(mnist)
data = data.reshape((784))
rest_request_ambassador("seldon-model",endpoint="localhost:8003",arr=data)<jupyter_output><empty_output><jupyter_text>Test with Random Data<jupyter_code>def create_random_data(data_size,rows=1):
    shape = [rows,data_size]
    arr = np.random.rand(rows*data_size)
    return (shape,arr)

shape,data = create_random_data(784)
rest_request_ambassador("seldon-model",endpoint="localhost:8003",arr=data)<jupyter_output><empty_output><jupyter_text>Analytics and Load Test<jupyter_code>!helm install ../../../helm-charts/seldon-core-analytics --name seldon-core-analytics \
    --set grafana_prom_admin_password=password \
    --set persistence.enabled=false \
    --namespace seldon
!kubectl label nodes $(kubectl get nodes -o jsonpath='{.items[0].metadata.name}') role=locust
!helm install seldon-core-loadtesting --name loadtest  \
    --namespace seldon \
    --repo https://storage.googleapis.com/seldon-charts \
    --set locust.script=mnist_rest_locust.py \
    --set locust.host=http://test-deployment:8000 \
    --set oauth.enabled=false \
    --set locust.hatchRate=1 \
    --set locust.clients=1 \
    --set loadtest.sendFeedback=1 \
    --set locust.minWait=0 \
    --set locust.maxWait=0 \
    --set replicaCount=1 \
    --set data.size=784<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14677293934681182, 'fraction_numerical': 0.013996889580093312, 'mean_word_length': 4.129611166500498, 'pattern_counts': {'":': 17, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '662475', 'license': 'Apache-2.0', 'n_tokens_mistral': 1808, 'n_tokens_neox': 1711, 'n_words': 290, 'path': 'examples/transformers/mnist_outlier/mnist_outlier.ipynb', 'repo_name': 'masroorhasan/seldon-core', 'size': '5144'}