in src/sagemaker_xgboost_container/algorithm_mode/serve_utils.py [0:0]
def parse_content_data(input_data, input_content_type):
dtest = None
content_type = get_content_type(input_content_type)
payload = input_data
if content_type == CSV:
try:
decoded_payload = payload.strip().decode("utf-8")
dtest = encoder.csv_to_dmatrix(decoded_payload, dtype=float)
except Exception as e:
raise RuntimeError(
"Loading csv data failed with Exception, "
"please ensure data is in csv format:\n {}\n {}".format(type(e), e)
)
elif content_type == LIBSVM:
try:
decoded_payload = payload.strip().decode("utf-8")
dtest = xgb.DMatrix(_get_sparse_matrix_from_libsvm(decoded_payload))
except Exception as e:
raise RuntimeError(
"Loading libsvm data failed with Exception, "
"please ensure data is in libsvm format:\n {}\n {}".format(type(e), e)
)
elif content_type == RECORDIO_PROTOBUF:
try:
dtest = encoder.recordio_protobuf_to_dmatrix(payload)
except Exception as e:
raise RuntimeError(
"Loading recordio-protobuf data failed with "
"Exception, please ensure data is in "
"recordio-protobuf format: {} {}".format(type(e), e)
)
else:
raise RuntimeError("Content-type {} is not supported.".format(input_content_type))
return dtest, content_type