问题描述
我使用 conda_python3
内核启动了Sagemaker笔记本,并遵循示例 随机砍伐森林.
I spin up a Sagemaker notebook using the conda_python3
kernel, and follow the example Notebook for Random Cut Forest.
在撰写本文时, Sagemaker SDK > conda_python3 是1.72.0版,但是我想使用新功能,所以我更新了笔记本以使用最新的
As of this writing, the Sagemaker SDK that comes with conda_python3
is version 1.72.0, but I want to use new features, so I update my notebook to use the latest
%%bash
pip install -U sagemaker
我看到它正在更新.
print(sagemaker.__version__)
# 2.4.1
以前(在1.72.0版中),我将更新预测变量以使用正确的序列化器/反序列化器,并可以对模型进行推断
Previously (in version 1.72.0) I'd update my predictor to use the proper serializer/deserializer, and could run inference on my model
from sagemaker.predictor import csv_serializer, json_deserializer
rcf_inference = rcf.deploy(
initial_instance_count=1,
instance_type='ml.m4.xlarge',
)
rcf_inference.content_type = 'text/csv'
rcf_inference.serializer = csv_serializer
rcf_inference.accept = 'application/json'
rcf_inference.deserializer = json_deserializer
results = rcf_inference.predict(some_numpy_array)
(请注意,所有这些均来自例子
(Note this all comes from the example
我尝试像这样使用sagemaker 2.4.1复制此
I try and replicate this using sagemaker 2.4.1 like so
from sagemaker.deserializers import JSONDeserializer
from sagemaker.serializers import CSVSerializer
rcf_inference = rcf.deploy(
initial_instance_count=1,
instance_type='ml.m5.xlarge',
serializer=CSVSerializer,
deserializer=JSONDeserializer
)
results = rcf_inference.predict(some_numpy_array)
我收到一个错误
TypeError: serialize() missing 1 required positional argument: 'data'
我知道我没有正确使用serliaizer/deserializer,但是找不到有关如何使用它的良好文档
I know I'm using the serliaizer/deserializer incorrectly, but can't find good documentation on how this should be used
推荐答案
为了使用新的序列化器/反序列化器,您需要将其初始化,例如:
in order to use the new serializers/deserializers, you will need to init them, for example:
from sagemaker.deserializers import JSONDeserializer
from sagemaker.serializers import CSVSerializer
rcf_inference = rcf.deploy(
initial_instance_count=1,
instance_type='ml.m5.xlarge',
serializer=CSVSerializer(),
deserializer=JSONDeserializer()
)
这篇关于如何在Sagemaker 2中使用序列化器和反序列化器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!