Last active
March 17, 2020 13:47
-
-
Save siakon89/9d4e8b4f63b0177829e7e2a1dbc92d5b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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