Example #1
0
def test_decode(content_type):
    decoder = Mock()
    with patch.dict(encoder._dmatrix_decoders_map, {content_type: decoder},
                    clear=True):
        encoder.decode(42, content_type)

    decoder.assert_called_once_with(42)
Example #2
0
def input_fn(input_data, content_type):
    if content_type == content_types.JSON:
        obj = json.loads(input_data)
        features = obj['instances'][0]['features']
        array = np.array(features).reshape((1, -1))
        return xgb.DMatrix(array)
    else:
        return xgb_encoders.decode(input_data, content_type)
def input_fn(input_data, content_type):
    if content_type == content_types.JSON:
        print("Recieved content type is json")
        print("input_data is", input_data)
        obj = json.loads(input_data)
        print("obj", obj)
        array = np.array(obj)
        return xgb.DMatrix(array)
    else:
        print("content type is not json")
        return xgb_encoders.decode(input_data, content_type)
def default_input_fn(input_data, content_type):
    """Take request data and de-serializes the data into an object for prediction.
        When an InvokeEndpoint operation is made against an Endpoint running SageMaker model server,
        the model server receives two pieces of information:
            - The request Content-Type, for example "application/json"
            - The request data, which is at most 5 MB (5 * 1024 * 1024 bytes) in size.
        The input_fn is responsible to take the request data and pre-process it before prediction.
    Args:
        input_data (obj): the request data.
        content_type (str): the request Content-Type.
    Returns:
        (obj): data ready for prediction. For XGBoost, this defaults to DMatrix.
    """
    return xgb_encoders.decode(input_data, content_type)
Example #5
0
def test_decode_error():
    with pytest.raises(_errors.UnsupportedFormatError):
        encoder.decode(42, _content_types.OCTET_STREAM)
def test_decode_with_complex_csv_content_type(content_type):
    dmatrix_result = encoder.decode("42.0,6.0,9.0\n42.0,6.0,9.0", content_type)
    assert type(dmatrix_result) is xgb.DMatrix