Exemplo n.º 1
0
    def Predict(self,request,context):
        features = get_data_from_proto(request)
        datadef = request.data
        data_type = request.WhichOneof("data_oneof")
        predictions = predict(self.user_model,features,datadef.names)

        # Construct meta data
        meta = prediction_pb2.Meta()
        metaJson = {}
        tags = get_custom_tags(self.user_model)
        if tags:
            metaJson["tags"] = tags
        metrics = get_custom_metrics(self.user_model)
        if metrics:
            metaJson["metrics"] = metrics
        json_format.ParseDict(metaJson,meta)

        
        if isinstance(predictions, np.ndarray) or data_type == "data":
            predictions = np.array(predictions)
            if len(predictions.shape)>1:
                class_names = get_class_names(self.user_model, predictions.shape[1])
            else:
                class_names = []

            if data_type == "data":
                default_data_type = request.data.WhichOneof("data_oneof")
            else:
                default_data_type = "tensor"
            data = array_to_grpc_datadef(predictions, class_names, default_data_type)
            return prediction_pb2.SeldonMessage(data=data,meta=meta)
        else:
            return prediction_pb2.SeldonMessage(binData=predictions,meta=meta)        
Exemplo n.º 2
0
    def Predict():
        request = extract_message()
        sanity_check_request(request)

        features = get_data_from_json(request)
        names = request.get("data",{}).get("names")
        
        predictions = predict(user_model,features,names)

        # If predictions is an numpy array or we used the default data then return as numpy array
        if isinstance(predictions, np.ndarray) or "data" in request:
            predictions = np.array(predictions)
            if len(predictions.shape)>1:
                class_names = get_class_names(user_model, predictions.shape[1])
            else:
                class_names = []
            data = array_to_rest_datadef(predictions, class_names, request.get("data",{}))
            response = {"data":data,"meta":{}}
        else:
            response = {"binData":predictions,"meta":{}}
            
        tags = get_custom_tags(user_model)
        if tags:
            response["meta"]["tags"] = tags
        metrics = get_custom_metrics(user_model)
        if metrics:
            response["meta"]["metrics"] = metrics
        return jsonify(response)
Exemplo n.º 3
0
    def Predict(self, request, context):
        datadef = request.data
        features = grpc_datadef_to_array(datadef)

        predictions = np.array(
            predict(self.user_model, features, datadef.names))
        if len(predictions.shape) > 1:
            class_names = get_class_names(self.user_model,
                                          predictions.shape[1])
        else:
            class_names = []

        data = array_to_grpc_datadef(predictions, class_names,
                                     request.data.WhichOneof("data_oneof"))

        # Construct meta data
        meta = prediction_pb2.Meta()
        metaJson = {}
        tags = get_custom_tags(self.user_model)
        if tags:
            metaJson["tags"] = tags
        metrics = get_custom_metrics(self.user_model)
        if metrics:
            metaJson["metrics"] = metrics
        json_format.ParseDict(metaJson, meta)

        return prediction_pb2.SeldonMessage(data=data, meta=meta)
Exemplo n.º 4
0
    def Route():

        request = extract_message()

        if debug:
            print("SELDON DEBUGGING")
            print("Request received: ")
            print(request)

        sanity_check_request(request)

        datadef = request.get("data")
        features = rest_datadef_to_array(datadef)

        routing = np.array(
            [[route(user_router, features, datadef.get("names"))]])
        # TODO: check that predictions is 2 dimensional
        class_names = []

        data = array_to_rest_datadef(routing, class_names, datadef)

        response = {"data": data, "meta": {}}
        tags = get_custom_tags(user_router)
        if tags:
            response["meta"]["tags"] = tags
        metrics = get_custom_metrics(user_router)
        if metrics:
            response["meta"]["metrics"] = metrics
        return jsonify(response)
    def TransformInput():
        request = extract_message()
        sanity_check_request(request)

        features = get_data_from_json(request)
        names = request.get("data", {}).get("names")

        transformed = transform_input(user_model, features, names)

        # If predictions is an numpy array or we used the default data then return as numpy array
        if isinstance(transformed, np.ndarray) or "data" in request:
            new_feature_names = get_feature_names(user_model, names)
            transformed = np.array(transformed)
            data = array_to_rest_datadef(transformed, new_feature_names,
                                         request.get("data", {}))
            response = {"data": data, "meta": {}}
        else:
            response = {"binData": transformed, "meta": {}}

        tags = get_custom_tags(user_model)
        if tags:
            response["meta"]["tags"] = tags
        metrics = get_custom_metrics(user_model)
        if metrics:
            response["meta"]["metrics"] = metrics
        return jsonify(response)
    def TransformOutput(self, request, context):
        features = get_data_from_proto(request)
        datadef = request.data
        data_type = request.WhichOneof("data_oneof")

        # Construct meta data
        meta = prediction_pb2.Meta()
        metaJson = {}
        tags = get_custom_tags(self.user_model)
        if tags:
            metaJson["tags"] = tags
        metrics = get_custom_metrics(self.user_model)
        if metrics:
            metaJson["metrics"] = metrics
        json_format.ParseDict(metaJson, meta)

        transformed = transform_output(self.user_model, features,
                                       datadef.names)

        if isinstance(transformed, np.ndarray) or data_type == "data":
            transformed = np.array(transformed)
            class_names = get_class_names(self.user_model, datadef.names)
            if data_type == "data":
                default_data_type = request.data.WhichOneof("data_oneof")
            else:
                default_data_type = "tensor"
            data = array_to_grpc_datadef(transformed, class_names,
                                         default_data_type)
            return prediction_pb2.SeldonMessage(data=data, meta=meta)
        else:
            return prediction_pb2.SeldonMessage(binData=transformed, meta=meta)
Exemplo n.º 7
0
    def Route(self,request,context):
        datadef = request.data
        features = grpc_datadef_to_array(datadef)

        routing = np.array([[route(self.user_model,features,datadef.names)]])
        #TODO: check that predictions is 2 dimensional
        class_names = []

        data = array_to_grpc_datadef(routing, class_names, request.data.WhichOneof("data_oneof"))

        # Construct meta data
        meta = prediction_pb2.Meta()
        metaJson = {}
        tags = get_custom_tags(self.user_model)
        if tags:
            metaJson["tags"] = tags
        metrics = get_custom_metrics(self.user_model)
        if metrics:
            metaJson["metrics"] = metrics
        json_format.ParseDict(metaJson,meta)

        return prediction_pb2.SeldonMessage(data=data,meta=meta)        
Exemplo n.º 8
0
    def Predict():
        request = extract_message()
        sanity_check_request(request)

        datadef = request.get("data")
        features = rest_datadef_to_array(datadef)

        predictions = np.array(predict(user_model,features,datadef.get("names")))
        if len(predictions.shape)>1:
            class_names = get_class_names(user_model, predictions.shape[1])
        else:
            class_names = []

        data = array_to_rest_datadef(predictions, class_names, datadef)

        response = {"data":data,"meta":{}}
        tags = get_custom_tags(user_model)
        if tags:
            response["meta"]["tags"] = tags
        metrics = get_custom_metrics(user_model)
        if metrics:
            response["meta"]["metrics"] = metrics
        return jsonify(response)
    def TransformOutput():
        request = extract_message()
        sanity_check_request(request)

        features = get_data_from_json(request)
        names = request.get("data", {}).get("names")

        transformed = transform_output(user_model, features, names)

        if isinstance(transformed, np.ndarray) or "data" in request:
            new_class_names = get_class_names(user_model, names)
            data = array_to_rest_datadef(transformed, new_class_names,
                                         request.get("data", {}))
            response = {"data": data, "meta": {}}
        else:
            response = {"binData": transformed, "meta": {}}

        tags = get_custom_tags(user_model)
        if tags:
            response["meta"]["tags"] = tags
        metrics = get_custom_metrics(user_model)
        if metrics:
            response["meta"]["metrics"] = metrics
        return jsonify(response)