Open CloudaYolla opened 3 years ago
This notebook is also using APIs from the Python SDK <2 . Namely, create_image_uri
Solved the above issue by removing NEO_IMAGE_ACCOUNT and using the new name create_image_uri
-> image_uris
:
from sagemaker import image_uris
model_name = name_from_base('TorchVision-ResNet18-Neo')
image_uri = image_uris.retrieve(region=region,
framework='neo-' + framework.lower(),
instance_type=target_device.replace('_', '.'),
py_version='py3')
response = sm_client.create_model(
ModelName=model_name,
PrimaryContainer={
'Image': image_uri,
'ModelDataUrl': compiled_model_path,
'Environment': { 'SAGEMAKER_SUBMIT_DIRECTORY': source_path }
},
ExecutionRoleArn=role
)
print(response)
However, running:
response = sm_runtime.invoke_endpoint(EndpointName=endpoint_name,
ContentType='application/x-image',
Body=payload)
breaks. Returns:
---------------------------------------------------------------------------
ModelError Traceback (most recent call last)
<ipython-input-32-c36a6ba27f54> in <module>
9 response = sm_runtime.invoke_endpoint(EndpointName=endpoint_name,
10 ContentType='application/x-image',
---> 11 Body=payload)
12 print(response)
13 result = json.loads(response['Body'].read().decode())
/opt/conda/lib/python3.6/site-packages/botocore/client.py in _api_call(self, *args, **kwargs)
355 "%s() only accepts keyword arguments." % py_operation_name)
356 # The "self" in this scope is referring to the BaseClient.
--> 357 return self._make_api_call(operation_name, kwargs)
358
359 _api_call.__name__ = str(py_operation_name)
/opt/conda/lib/python3.6/site-packages/botocore/client.py in _make_api_call(self, operation_name, api_params)
674 error_code = parsed_response.get("Error", {}).get("Code")
675 error_class = self.exceptions.from_code(error_code)
--> 676 raise error_class(parsed_response, operation_name)
677 else:
678 return parsed_response
ModelError: An error occurred (ModelError) when calling the InvokeEndpoint operation: Received server error (500) from model with message "Content type application/x-image is not supported by this framework.
Please implement input_fn to to deserialize the request data or an output_fn to
serialize the response. For more information, see the SageMaker Python SDK README.
Traceback (most recent call last):
File "/opt/conda/lib/python3.6/site-packages/sagemaker_inference/decoder.py", line 106, in decode
decoder = _decoder_map[content_type]
KeyError: 'application/x-image'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/conda/lib/python3.6/site-packages/sagemaker_inference/transformer.py", line 126, in transform
result = self._transform_fn(self._model, input_data, content_type, accept)
File "/opt/conda/lib/python3.6/site-packages/sagemaker_inference/transformer.py", line 215, in _default_transform_fn
data = self._input_fn(input_data, content_type)
File "/opt/conda/lib/python3.6/site-packages/sagemaker_pytorch_serving_container/default_inference_handler.py", line 97, in default_input_fn
np_array = decoder.decode(input_data, content_type)
File "/opt/conda/lib/python3.6/site-packages/sagemaker_inference/decoder.py", line 109, in decode
raise errors.UnsupportedFormatError(content_type)
sagemaker_inference.errors.UnsupportedFormatError: Content type application/x-image is not supported by this framework.
Please implement input_fn to to deserialize the request data or an output_fn to
serialize the response. For more information, see the SageMaker Python SDK README.
". See https://us-west-2.console.aws.amazon.com/cloudwatch/home?region=us-west-2#logEventViewer:group=/aws/sagemaker/Endpoints/TorchVision-ResNet18-Neo-2020-12-23-23-12-12-235-Endpoint in account 688520471316 for more information.
Looking into this.
botocore.errorfactory.ModelError: An error occurred (ModelError) when calling the InvokeEndpoint operation: Received server error (500) from model with message "Content type application/x-image is not supported by this framework.
I got the same problem, any help here?
@ngluna I got the same issue
I tested the NB using SM Studio:
Src: https://github.com/aws/amazon-sagemaker-examples/blob/master/aws_sagemaker_studio/sagemaker_neo_compilation_jobs/pytorch_torchvision/pytorch_torchvision_neo_studio.ipynb
Issue
How to Resolve
Seems like following are depreciated: Quote: https://sagemaker.readthedocs.io/en/stable/v2.html
But couldn't find info about the NEO_IMAGE_ACCOUNT.