title: Invoking Endpoint in AWS SageMaker for Scikit Learn Model
body: <p>After deploying a scikit model on AWS Sagemaker, I invoke my model using below:</p>
  
  <pre><code>import pandas as pd
  payload = pd.read_csv('test3.csv')
  payload_file = io.StringIO()
  payload.to_csv(payload_file, header = None, index = None)
  
  import boto3
  client = boto3.client('sagemaker-runtime')
  response = client.invoke_endpoint(
      EndpointName= endpoint_name,
      Body= payload_file.getvalue(),
      ContentType = 'text/csv')
  import json
  result = json.loads(response['Body'].read().decode())
  print(result)
  </code></pre>
  
  <p>The above code works perfectly but when I try:</p>
  
  <pre><code>payload = np.array([[100,5,1,2,3,4]])
  </code></pre>
  
  <p>I get the error:</p>
  
  <pre><code>ModelError: An error occurred (ModelError) when calling the InvokeEndpoint operation: Received server error (500) from container-1 with message 
  "&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"&gt; &lt;title&gt;500 Internal Server Error&lt;/title&gt; &lt;h1&gt;
  Internal Server Error&lt;/h1&gt; &lt;p&gt;The server encountered an internal error and was unable to complete your request.  
  Either the server is overloaded or there is an error in the application.&lt;/p&gt; 
  </code></pre>
  
  <p>It was mentioned in <a href="https://github.com/aws/sagemaker-python-sdk/blob/master/src/sagemaker/sklearn/README.rst" rel="nofollow noreferrer">Scikit-learn SageMaker Estimators and Models</a>, that the </p>
  
  <blockquote>
    <p>SageMaker Scikit-learn model server provides a default implementation
    of input_fn. This function deserializes JSON, CSV, or NPY encoded data
    into a NumPy array.</p>
  </blockquote>
  
  <p>I would like to know how I can modify the default to accept a 2D numpy array so it can be used for real-time prediction.</p>
  
  <p>Any suggestion? I have tried using <a href="https://github.com/awslabs/amazon-sagemaker-examples/blob/master/sagemaker-python-sdk/scikit_learn_inference_pipeline/Inference%20Pipeline%20with%20Scikit-learn%20and%20Linear%20Learner.ipynb" rel="nofollow noreferrer">Inference Pipeline with Scikit-learn and Linear Learner</a> as a reference but could not replace the Linear Learner with a Scikit model. I received the same error.</p>