-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Where and how may I preprocess input data before making predictions? #100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
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? |
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:
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:
This didn't work and I get the same error. Here's the entire stacktrace:
|
After further debugging, I found out I wasn't pickling correctly. Once I get that resolved, this method should work. Thanks for your help! |
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? |
@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. |
This issue has been closed due to inactivity. If you still have questions, please re-open it. |
LDA Topic Models
I'd like to preprocess my data by sending in a string input through
predictor.predict(data)
and turning it into numerical embeddings just as mytrain_input_fn
is doing withvocab_processor.fit_transform
before going though mymodel_fn
:The documentation says to do it through serving_input_fn but I'm not sure how I can access and manipulate the data from my tensor using
vocab_processor.transform
. Here's my serving_input_fn for context:I tried doing so through a input_fn instead:
Here, I had an error deserializing:
What would be the best method to preprocess the data?
The text was updated successfully, but these errors were encountered: