Skip to content

Commit

Permalink
Merge pull request #2626 from cliveseldon/2551_knative_upgrade
Browse files Browse the repository at this point in the history
Update Alibi-Detect wrapper and drift and outlier examples
  • Loading branch information
axsaucedo committed Nov 13, 2020
2 parents 0765b3b + f57e2db commit 125373b
Show file tree
Hide file tree
Showing 17 changed files with 936 additions and 355 deletions.
4 changes: 2 additions & 2 deletions components/alibi-detect-server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ RUN pip install -e .
RUN pip install pip-licenses
RUN mkdir ./licenses && pip-licenses --from=mixed --format=csv --output-file=./licenses/license_info.csv && \
pip-licenses --from=mixed --format=plain-vertical --with-license-file --no-license-path --output-file=./licenses/license.txt
USER root


RUN yum install -y mesa-libGL
RUN mv ./licenses /licenses
USER default

ENTRYPOINT ["python", "-m", "adserver"]
4 changes: 2 additions & 2 deletions components/alibi-detect-server/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ docker-run-drift-detector:
#

curl-detector:
curl -v localhost:8080/ -d @./input.json -H "ce-namespace: default" -H "ce-modelid: cifar10"
curl -v localhost:8080/ -d @./input.json -H "ce-namespace: default" -H "ce-modelid: cifar10" -H "ce-type: io.seldon.serving.inference.request" -H "ce-id: 1234" -H "ce-source: localhost" -H "ce-specversion: 1.0"

curl-outlier-detector-scores:
curl -v localhost:8080/ -d @./input.json -H "Alibi-Detect-Return-Feature-Score: true" -H "Alibi-Detect-Return-Instance-Score: true"
Expand All @@ -67,7 +67,7 @@ curl-metrics-server-metrics:
curl http://localhost:8080/v1/metrics

docker-build:
docker build -f Dockerfile -t seldonio/${IMAGE}:${VERSION} .
docker build --pull -f Dockerfile -t seldonio/${IMAGE}:${VERSION} .

docker-push:
docker push seldonio/${IMAGE}:${VERSION}
Expand Down
7 changes: 6 additions & 1 deletion components/alibi-detect-server/adserver/od_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def process_event(self, inputs: Union[List, Dict], headers: Dict) -> Dict:
and headers[HEADER_RETURN_FEATURE_SCORE] == "true"
):
ret_feature_score = True
op_preds = {}
od_preds = {}
name = self.model.meta["name"]
if (
name == "IForest"
Expand All @@ -105,5 +105,10 @@ def process_event(self, inputs: Union[List, Dict], headers: Dict) -> Dict:
# scores used to determine outliers
return_instance_score=ret_instance_score,
)
# clean result
if "data" in od_preds and "instance_score" in od_preds["data"] and od_preds["data"]["instance_score"] is None:
del od_preds["data"]["instance_score"]
if "data" in od_preds and "feature_score" in od_preds["data"] and od_preds["data"]["feature_score"] is None:
del od_preds["data"]["feature_score"]

return json.loads(json.dumps(od_preds, cls=NumpyEncoder))
14 changes: 7 additions & 7 deletions components/alibi-detect-server/adserver/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from adserver.protocols.tensorflow_http import TensorflowRequestHandler
from cloudevents.sdk import converters
from cloudevents.sdk import marshaller
from cloudevents.sdk.event import v02
from cloudevents.sdk.event import v1
from adserver.protocols import Protocol
from seldon_core.flask_utils import SeldonMicroserviceException
from seldon_core.user_model import SeldonResponse
Expand Down Expand Up @@ -136,7 +136,7 @@ def get_request_handler(protocol, request: Dict) -> RequestHandler:
return SeldonFeedbackRequestHandler(request)


def sendCloudEvent(event: v02.Event, url: str):
def sendCloudEvent(event: v1.Event, url: str):
"""
Send CloudEvent
Expand All @@ -153,10 +153,10 @@ def sendCloudEvent(event: v02.Event, url: str):
event, converters.TypeBinary, json.dumps
)

print("binary CloudEvent")
logging.info("binary CloudEvent")
for k, v in binary_headers.items():
print("{0}: {1}\r\n".format(k, v))
print(binary_data)
logging.info("{0}: {1}\r\n".format(k, v))
logging.info(binary_data)

response = requests.post(url, headers=binary_headers, data=binary_data)
response.raise_for_status()
Expand Down Expand Up @@ -217,7 +217,7 @@ def post(self):
request = request_handler.extract_request()

# Create event from request body
event = v02.Event()
event = v1.Event()
http_marshaller = marshaller.NewDefaultHTTPMarshaller()
event = http_marshaller.FromRequest(
event, self.request.headers, self.request.body, json.loads
Expand Down Expand Up @@ -250,7 +250,7 @@ def post(self):
else:
resp_event_id = event.EventID()
revent = (
v02.Event()
v1.Event()
.SetContentType("application/json")
.SetData(responseStr)
.SetEventID(resp_event_id)
Expand Down
2 changes: 1 addition & 1 deletion components/alibi-detect-server/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"kfserving>=0.2.0",
"argparse >= 1.4.0",
"numpy >= 1.8.2",
"cloudevents",
"cloudevents == 1.2.0",
"elasticsearch==7.9.1",
# Fixes #2533
"google-cloud-core==1.4.1",
Expand Down
5 changes: 5 additions & 0 deletions components/drift-detection/cifar10/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
event-display.yaml
broker.yaml
trigger.yaml
cifar10cd.yaml
cifar10.yaml
30 changes: 0 additions & 30 deletions components/drift-detection/cifar10/cifar10.yaml

This file was deleted.

Loading

0 comments on commit 125373b

Please sign in to comment.