Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 26 additions & 14 deletions project/starter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,15 @@
"))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -751,20 +760,20 @@
"\n",
"```python\n",
"{\n",
" \"inferences\": [], # Output of predictor.predict\n",
" \"s3_key\": \"\", # Source data S3 key\n",
" \"s3_bucket\": \"\", # Source data S3 bucket\n",
" \"image_data\": \"\" # base64 encoded string containing the image data\n",
" \"s3_key\": \"\", # Source data S3 key\n",
" \"image_data\": \"\", # base64 encoded string containing the image data\n",
" \"inferences\": [] # Output of predictor.predict\n",
"}\n",
"```\n",
"\n",
"A good test object that you can use for Lambda tests and Step Function executions, throughout the next section, might look like this:\n",
"\n",
"```python\n",
"{\n",
" \"image_data\": \"\",\n",
" \"s3_bucket\": MY_BUCKET_NAME, # Fill in with your bucket\n",
" \"s3_key\": \"test/bicycle_s_000513.png\"\n",
" \"s3_key\": \"test/bicycle_s_000513.png\",\n",
" \"image_data\": \"\"\n",
"}\n",
"```\n",
"\n",
Expand Down Expand Up @@ -798,9 +807,9 @@
" return {\n",
" 'statusCode': 200,\n",
" 'body': {\n",
" \"image_data\": image_data,\n",
" \"s3_bucket\": bucket,\n",
" \"s3_key\": key,\n",
" \"image_data\": image_data,\n",
" \"inferences\": []\n",
" }\n",
" }\n",
Expand Down Expand Up @@ -836,10 +845,10 @@
" inferences = ## TODO: fill in\n",
" \n",
" # We return the data back to the Step Function \n",
" event[\"inferences\"] = inferences.decode('utf-8')\n",
" event[\"body\"][\"inferences\"] = inferences.decode('utf-8')\n",
" return {\n",
" 'statusCode': 200,\n",
" 'body': json.dumps(event)\n",
" 'body': json.dumps(event[\"body\"])\n",
" }\n",
"```\n",
"\n",
Expand Down Expand Up @@ -869,7 +878,7 @@
"\n",
" return {\n",
" 'statusCode': 200,\n",
" 'body': json.dumps(event)\n",
" 'body': json.dumps(event[\"body\"])\n",
" }\n",
"```\n",
"Once you have tested the lambda functions, save the code for each lambda function in a python script called 'lambda.py'.\n",
Expand Down Expand Up @@ -988,12 +997,15 @@
"import os\n",
"\n",
"# List the file names we downloaded\n",
"file_handles = os.listdir(\"./captured_data\")\n",
"file_handles = []\n",
"for root, subFolders, files in os.walk(\"./captured_data\"):\n",
" if files:\n",
" file_handles += [root + '/' + file for file in files]\n",
"\n",
"# Dump all the data into an array\n",
"json_data = []\n",
"for jsonl in file_handles:\n",
" with jsonlines.open(f\"./captured_data/{jsonl}\") as f:\n",
" with jsonlines.open(jsonl) as f:\n",
" json_data.append(f.read())"
]
},
Expand Down Expand Up @@ -1084,9 +1096,9 @@
"metadata": {
"instance_type": "ml.t3.medium",
"kernelspec": {
"display_name": "Python 3 (Data Science)",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3__SAGEMAKER_INTERNAL__arn:aws:sagemaker:us-east-1:081325390199:image/datascience-1.0"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -1098,7 +1110,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.10"
"version": "3.7.6"
}
},
"nbformat": 4,
Expand Down