Skip to content
Open
Show file tree
Hide file tree
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
3,164 changes: 3,164 additions & 0 deletions project/.ipynb_checkpoints/starter (1)-checkpoint.ipynb

Large diffs are not rendered by default.

Binary file added project/file.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions project/lambda function/classify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import json
import sagemaker
import base64
from sagemaker.serializers import IdentitySerializer
from sagemaker.predictor import Predictor

# Fill this in with the name of your deployed model
ENDPOINT = 'image-classification-2023-02-14-13-25-18-287' ## TODO: fill in

def lambda_handler(event, context):

# Decode the image data
image = base64.b64decode(## TODO: fill in)

# Instantiate a Predictor
## TODO: fill in
predictor = Predictor('image-classification-2023-02-14-13-25-18-287')

# For this model the IdentitySerializer needs to be "image/png"
predictor.serializer = IdentitySerializer("image/png")

# Make a prediction:
inferences = predictor.predict(predictor.serializer) ## TODO: fill in

# We return the data back to the Step Function
event["inferences"] = inferences.decode('utf-8')
return {
'statusCode': 200,
'body': json.dumps(event)
}
30 changes: 30 additions & 0 deletions project/lambda function/filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import json

THRESHOLD = .93


def lambda_handler(event, context):

# Grab the inferences from the event
inferences = event["inferences"] ## TODO: fill in

# Check if any values in our inferences are above THRESHOLD
meets_threshold = (inferences>THRESHOLD) ## TODO: fill in

# If our threshold is met, pass our data back out of the
# Step Function, else, end the Step Function with an error
if meets_threshold:
pass
else:
raise("THRESHOLD_CONFIDENCE_NOT_MET")

return {
'statusCode': 200,
'body': json.dumps(event)
}
def lambda_handler(event, context):
# TODO implement
return {
'statusCode': 200,
'body': json.dumps('Hello from Lambda!')
}
36 changes: 36 additions & 0 deletions project/lambda function/serializeImageData.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import json
import boto3
import base64

s3 = boto3.client('s3')

def lambda_handler(event, context):
"""A function to serialize target data from S3"""

# Get the s3 address from the Step Function event input
key = event["s3_key"] ## TODO: fill in
bucket =event["s3_bucket"] ## TODO: fill in

# Download the data from s3 to /tmp/image.png
## TODO: fill in

input_object = event['image_data']
file_name = '/tmp/image.png'
s3.download_file(bucket, input_object, file_name)

# We read the data from a file
with open("/tmp/image.png", "rb") as f:
image_data = base64.b64encode(f.read())

# Pass the data back to the Step Function
print("Event:", event.keys())
return {
'statusCode': 200,
'body': {
"image_data": image_data,
"s3_bucket": bucket,
"s3_key": key,
"inferences": []
}
}

Loading