import pickle as pkl import json import numpy as np import xgboost as xgb from sagemaker_containers.beta.framework import content_types from sagemaker_xgboost_container import encoder as xgb_encoders 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 model_fn(model_dir): model_file = model_dir + "/model.bin" model = pkl.load(open(model_file, "rb")) return model