Skip to content

Instantly share code, notes, and snippets.

@siakon89
Last active March 17, 2020 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save siakon89/9d4e8b4f63b0177829e7e2a1dbc92d5b to your computer and use it in GitHub Desktop.
Save siakon89/9d4e8b4f63b0177829e7e2a1dbc92d5b to your computer and use it in GitHub Desktop.
import boto3, sagemaker
import pandas as pd
smrt = boto3.client('sagemaker-runtime')
sess = sagemaker.Session()
df = pd.read_csv('mnist/test.csv', chunksize=1000)
results_sub = []
counter = 0
for chunk in df:
payload = chunk.to_csv(header=False, index=False)
response = smrt.invoke_endpoint(
EndpointName="mnist-endopoint-1",
Body=payload.encode('utf8'),
ContentType='text/csv'
)
results = response['Body'].read().decode('utf-8')
results_final = list(map(lambda x: x, results.split('\n')))
results_sub += [y for y in results_final if y]
counter += chunk.shape[0]
print(f'Predicted {counter}')
results_final_submition = list(zip(range(1, len(results_sub) + 1), results_sub))
submitions = pd.DataFrame(results_final_submition)
submitions.columns = ['ImageId', 'Label']
submitions.to_csv('kaggle_submission.csv', index=False)
# sess.delete_endpoint(endpoint_name="mnist-endopoint-1")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment