Comments (6)
input_fn is the correct function to override, so you're on the right track. Here's a simpler example from our tests which uses it in this way:
When you define an input_fn, the raw request is passed in as the first argument, so you should have full control over the deserialization logic. Your function can do anything, but it just needs to return a dict of tensor name: tensor of the same shape as defined in your serving_input_fn.
From just the part of the stacktrace you provided, it's hard to tell whether the exception is occurring in your input_fn, or after. I'd recommend adding some debugging print statements inside your input_fn to determine that. If you're still having the problem after verifying you're deserializing correctly, can you provide the full stacktrace, and any debugging info you've obtained from you print statement, such as what you're returning from your input_fn?
from sagemaker-python-sdk.
I did some debugging and it looks like the issue is coming from the deserialization. First, I tested the model without the input_fn and preprocessed the data before sending it in:
data = ["blah blah blah"]
data = np.array(list(vocab_processor.transform(data)))
predictor.predict(data)
This works fine and I get back predictions.
The second time, I added back the input_fn and removed all of the preprocessing that was present before in my post (so I can test the unpickling) and preprocessed the data beforehand like above. Here's my modified input_fn:
def input_fn(serialized_input, content_type):
deserialized_input = pickle.loads(serialized_input)
return deserialized_input
This didn't work and I get the same error. Here's the entire stacktrace:
Traceback (most recent call last):
File "/opt/amazon/lib/python2.7/site-packages/container_support/serving.py", line 165, in _invoke
self.transformer.transform(content, input_content_type, requested_output_content_type)
File "/opt/amazon/lib/python2.7/site-packages/tf_container/serve.py", line 255, in transform
return self.transform_fn(data, content_type, accepts), accepts
File "/opt/amazon/lib/python2.7/site-packages/tf_container/serve.py", line 179, in f
input = input_fn(serialized_data, content_type)
File "/opt/ml/code/text_classification_cnn.py", line 156, in input_fn
deserialized_input = pickle.loads(serialized_input)
File "/usr/lib/python2.7/pickle.py", line 1388, in loads
return Unpickler(file).load()
File "/usr/lib/python2.7/pickle.py", line 864, in load
dispatchkey
KeyError: '['
[2018-03-16 18:11:25,795] ERROR in serving: '['
2018-03-16 18:11:25,795 ERROR - model server - '['
from sagemaker-python-sdk.
After further debugging, I found out I wasn't pickling correctly. Once I get that resolved, this method should work. Thanks for your help!
from sagemaker-python-sdk.
Hello @mihi-r, I am having the exact same key error message and I also think it's a deserialization issue. I followed the pickling shown in the aws documentation but it isn't working. Have you had any luck?
from sagemaker-python-sdk.
@Brunods1001 Yes, for me, simply pickling and and deserializing how it states in the documentation worked for me. When I first tried using input_fn, I was thinking the model would serialize it for you but in fact, you'll need to serialize it and deserialize it manually.
from sagemaker-python-sdk.
This issue has been closed due to inactivity. If you still have questions, please re-open it.
from sagemaker-python-sdk.
Related Issues (20)
- SageMaker Processing Job doesn't support FastFile Input Mode
- "AttributeError: 'NoneType' object has no attribute 'len'" when deploying inference component
- Cant see evaluation metrics in new SageMaker Studio UI after doing model.register HOT 9
- Incorrect BiasConfig type hint for `label_values_or_threshold`
- How to recreate the predictor variable from the endpoint_name if somehow the variable is lost?
- No DataProcessing in local transform job HOT 1
- Update documentation to use `sagemaker-python-sdk` as opposed to `sagemaker` HOT 3
- Fix documentation of FeatureGroup HOT 1
- Sagemaker Local-Mode permission errors
- ModelStep name includes "-RegisterModel" suffix HOT 1
- Tags are't inherited from the `sagemaker_config` to hyperparameter tuning requests
- ValueError: Invalid explanations value when creating ModelCard from ModelPackage
- AsyncPredictor fails if name is None, despite it being the default
- Newline chars are not supported in sagemaker feature store string types
- SageMaker Batch currently doesn't support Model entity with container definitions which use ModelDataSource attribute
- 'base_job_name' parameter is not used to name the Processing Jobs that are created by the Model Monitoring Schedule
- (AutoMLV2) UnboundLocalError: local variable 'input_config' referenced before assignment
- Import/get data from bigquery
- Endless loop when try to deploy a sagemaker pipeline from a windows machine HOT 2
- HuggingFaceProcessor with ProcessingStep results in import errors (similar to issues/2656) HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sagemaker-python-sdk.