【发布时间】:2022-01-04 12:51:18
【问题描述】:
我们目前正在将我们的模型从单一模型终端节点转移到 AWS SageMaker 中的多模型终端节点。使用预构建的 TensorFlow 容器部署多模型端点后,我在调用 predict() 方法时收到以下错误:
{"error": "JSON Parse error: The document root must not be followed by other value at offset: 17"}
我这样调用端点:
data = np.random.rand(n_samples, n_features)
predictor = Predictor(endpoint_name=endpoint_name)
prediction = predictor.predict(data=serializer.serialize(data), target_model=model_name)
我处理输入的函数如下:
def _process_input(data, context):
data = data.read().decode('utf-8')
data = [float(x) for x in data.split(',')]
return json.dumps({'instances': [data]})
对于培训,我将容器配置如下:
tensorflow_container = TensorFlow(
entry_point=path_script,
framework_version='2.4',
py_version='py37',
instance_type='ml.m4.2xlarge',
instance_count=1,
role=EXECUTION_ROLE,
sagemaker_session=sagemaker_session,
hyperparameters=hyperparameters)
tensorflow_container.fit()
为了部署端点,我首先从给定的 Estimator 初始化一个模型,然后是一个 MultiDataModel:
model = estimator.create_model(
role=EXECUTION_ROLE,
image_uri=estimator.training_image_uri(),
entry_point=path_serving)
mdm = MultiDataModel(
name=endpoint_name,
model_data_prefix=dir_model_data,
model=model,
sagemaker_session=sagemaker.Session())
mdm.deploy(
initial_instance_count=1,
instance_type=instance_type,
endpoint_name=endpoint_name)
然后使用以下方法添加单个模型:
mdm.add_model(
model_data_source=source_path,
model_data_path=model_name)
感谢您的任何提示和帮助。
【问题讨论】:
标签: python tensorflow amazon-sagemaker