コード例 #1
0
ファイル: utils.py プロジェクト: mt0803/seldon-core
def grpc_datadef_to_array(datadef: prediction_pb2.DefaultData) -> np.ndarray:
    """
    Convert a SeldonMessage DefaultData to a numpy array.
    Parameters
    ----------
    datadef
       SeldonMessage DefaultData

    Returns
    -------
       A numpy array

    """
    data_type = datadef.WhichOneof("data_oneof")
    if data_type == "tensor":
        if sys.version_info >= (3, 0):
            sz = np.prod(datadef.tensor.shape)  # get number of float64 entries
            c = datadef.tensor.SerializeToString()  # get bytes
            # create array from packed entries which are at end of bytes - assumes same endianness
            features = np.frombuffer(memoryview(
                c[-(sz * 8):]), dtype=np.float64, count=sz, offset=0)
            features = features.reshape(datadef.tensor.shape)
        else:
            # Python 2 version which is slower
            features = np.array(datadef.tensor.values).reshape(
                datadef.tensor.shape)
    elif data_type == "ndarray":
        features = np.array(datadef.ndarray)
    elif data_type == "tftensor":
        features = tf.make_ndarray(datadef.tftensor)
    else:
        features = np.array([])
    return features
コード例 #2
0
def generate_test_requests() -> List[SeldonMessage]:
    max_value = 9999
    requests = []

    inputs = max_value * np.random.rand(1024)
    requests.append(
        SeldonMessage(data=DefaultData(
            tensor=Tensor(shape=inputs.shape, values=inputs))))
    return requests
コード例 #3
0
ファイル: main.py プロジェクト: adriangonz/java-wrapper-v2
def main():
    model = NoJava()
    #  model = Baseline()
    #  model = ProtobufEncoding()
    model = PayloadPassthrough()

    model.load()

    #  payload = np.array([0.0, 1.1, 2.2, 3.3])
    #  prediction = model.predict(payload)

    #  message = SeldonMessage(
    #  data=DefaultData(tensor=Tensor(shape=[1], values=[0.0, 1.1, 2.2, 3.3]))
    #  )
    #  prediction = model.predict_raw(message)

    for n in range(100000):
        message = SeldonMessage(data=DefaultData(
            tensor=Tensor(shape=[1], values=[0.0, 1.1, 2.2, 3.3])))
        prediction = model.predict_raw(MessageToJson(message))

        print(f"[PYTHON] Prediction was {prediction}")