Skip to content

Commit 41dc929

Browse files
committed
doc strings
1 parent d1def10 commit 41dc929

File tree

5 files changed

+24
-15
lines changed

5 files changed

+24
-15
lines changed

sample-apps/aws-panorama-sample/code/lambda_function.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
class people_counter(panoramasdk.base):
1616

1717
def interface(self):
18+
"""Defines the application's configurable settings, input type, and output type."""
1819
return {
1920
"parameters":
2021
(
@@ -34,6 +35,7 @@ def interface(self):
3435
}
3536

3637
def init(self, parameters, inputs, outputs):
38+
"""Initializes the application's attributes with parameters from the interface, and default values."""
3739
try:
3840
self.threshold = parameters.threshold
3941
self.person_index = parameters.person_index
@@ -67,6 +69,7 @@ def init(self, parameters, inputs, outputs):
6769
return False
6870

6971
def entry(self, inputs, outputs):
72+
"""Processes one frame of video from one or more video streams."""
7073
frame_start = time.time()
7174
self.frame_num += 1
7275
# Loop through attached video streams
@@ -92,6 +95,7 @@ def entry(self, inputs, outputs):
9295
return True
9396

9497
def process_media(self, media):
98+
"""Runs inference on a buffered frame of video, and buffers the new frame."""
9599
stream = media.stream_uri
96100
# Set up stream buffer
97101
if not self.buffered_media.get(stream):
@@ -120,6 +124,7 @@ def process_media(self, media):
120124
return output
121125

122126
def process_results(self, batch_set, output_media):
127+
"""Processes output tensors from a computer vision model and annotates a video frame."""
123128
# Model outputs (classes, probabilities, bounding boxes) are collected in
124129
# the BatchSet returned by model.get_result
125130
# Each output is a Batch of arrays, one for each input in the batch
@@ -147,6 +152,7 @@ def process_results(self, batch_set, output_media):
147152
return output_media
148153

149154
def preprocess(self, img):
155+
"""Resizes and normalizes a frame of video."""
150156
resized = cv2.resize(img, (HEIGHT, WIDTH))
151157
mean = [0.485, 0.456, 0.406]
152158
std = [0.229, 0.224, 0.225]

sample-apps/custom-model/code/application.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
class people_counter(panoramasdk.base):
1717

1818
def interface(self):
19+
"""Defines the application's configurable settings, input type, and output type."""
1920
return {
2021
"parameters":
2122
(
@@ -34,7 +35,7 @@ def interface(self):
3435
}
3536

3637
def init(self, parameters, inputs, outputs):
37-
"""Load the model and allocate input and output arrays"""
38+
"""Initializes the application's attributes with parameters from the interface, and default values."""
3839
try:
3940
self.threshold = parameters.threshold
4041
self.person_index = parameters.person_index
@@ -64,7 +65,7 @@ def init(self, parameters, inputs, outputs):
6465
return False
6566

6667
def entry(self, inputs, outputs):
67-
"""Process a frame of video from each input stream"""
68+
"""Processes one frame of video from one or more video streams."""
6869
frame_start = time.time()
6970
self.frame_num += 1
7071
# Loop through attached video streams
@@ -92,7 +93,7 @@ def entry(self, inputs, outputs):
9293
return True
9394

9495
def process_media(self, media):
95-
"""Buffer image and run inference"""
96+
"""Runs inference on a buffered frame of video, and buffers the new frame."""
9697
stream = media.stream_uri
9798
# Set up stream buffer
9899
if not self.buffered_media.get(stream):
@@ -121,7 +122,7 @@ def process_media(self, media):
121122
return output
122123

123124
def process_results(self, batch_set, output_media):
124-
"""Write text overlay on output image"""
125+
"""Processes output tensors from a computer vision model and annotates a video frame."""
125126
# Model outputs (classes, probabilities, bounding boxes) are collected in
126127
# the BatchSet returned by model.get_result
127128
# Each output is a Batch of arrays, one for each input in the batch
@@ -137,7 +138,7 @@ def process_results(self, batch_set, output_media):
137138
return output_media
138139

139140
def preprocess(self, img):
140-
"""Resize and normalize input image"""
141+
"""Resizes and normalizes a frame of video."""
141142
resized = cv2.resize(img, (HEIGHT, WIDTH))
142143
mean = [0.485, 0.456, 0.406]
143144
std = [0.229, 0.224, 0.225]

sample-apps/custom-model/code/keras-model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
class KerasModel():
2121

2222
def __init__(self):
23-
"""Get service role and bucket name from CloudFormation stack outputs"""
23+
"""Gets the service role and bucket name from CloudFormation stack outputs."""
2424
stack = cfn_client.describe_stacks(
2525
StackName='panorama-custom-model'
2626
)
@@ -31,7 +31,7 @@ def __init__(self):
3131
logger.info('Bucket: {}'.format(self.BUCKET_NAME))
3232

3333
def compile(self, model_name='DenseNet121'):
34-
"""Compile a Keras application model"""
34+
"""Compiles a Keras application model."""
3535
#model_names = [model[0] for model in getmembers(tf.keras.applications, isfunction)]
3636
compilation_jobs = {}
3737
packaging_jobs = {}

sample-apps/custom-model/code/model.test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
class TestFunction(unittest.TestCase):
1616

1717
def setUp(self):
18+
"""Gets resource names and IDs from the CloudFormation stack."""
1819
stack = cfn_client.describe_stacks(
1920
StackName='panorama-custom-model'
2021
)
@@ -23,6 +24,7 @@ def setUp(self):
2324
self.BUCKET_NAME=resources['bucketName']
2425

2526
def test_function(self):
27+
"""Tests the compilation and packaging workflows with a single model."""
2628
#model_names = [model[0] for model in getmembers(tf.keras.applications, isfunction)]
2729
#model_names = ['ResNet50V2']
2830
#model_names = ['MobileNetV2']

sample-apps/custom-model/code/model/model.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
class Model:
2525

2626
def __init__(self, bucket_name, service_role_arn):
27-
"""Save bucket name and service role ARN"""
27+
"""Saves the bucket name and service role ARN."""
2828
self.bucket_name = bucket_name
2929
self.service_role_arn = service_role_arn
3030

3131
def export_model(self, model_class, model_name):
32-
"""Export a TensorFlow model in SavedModel format and upload it to Amazon S3"""
32+
"""Exports a TensorFlow model in SavedModel format and uploads it to Amazon S3."""
3333
# TensorFlow 2 only
3434
# MODEL_NAME=model_class.__name__
3535
MODEL_NAME=model_name
@@ -55,7 +55,7 @@ def export_model(self, model_class, model_name):
5555
return model_uri, model_input_name, model_input_shape
5656

5757
def compile_model(self, s3_uri, input_name='input_1', input_shape='224,224,3', framework='TENSORFLOW', device='jetson_xavier'):
58-
"""Compile a model with Amazon Sagemaker Neo"""
58+
"""Compiles a model with Amazon Sagemaker Neo."""
5959
MODEL_INPUT_SHAPE = '{{"{}":[1,{}]}}'.format(input_name,input_shape)
6060
COMPILED_MODEL_FOLDER_URI = 's3://{}/models-compiled'.format(self.bucket_name)
6161
COMPILATION_JOB = 'panorama-custom-model-'+ str(time.time()).split('.')[0]
@@ -80,7 +80,7 @@ def compile_model(self, s3_uri, input_name='input_1', input_shape='224,224,3', f
8080
return COMPILATION_JOB
8181

8282
def package_model(self, model_name, compilation_job):
83-
"""Package a model with Amazon Sagemaker Neo"""
83+
"""Packages a model with Amazon Sagemaker Neo."""
8484
PACKAGING_JOB=compilation_job+"-packaging"
8585
MODEL_VERSION = "1.0"
8686
PACKAGED_MODEL_FOLDER_URI = 's3://{}/models-packaged'.format(self.bucket_name)
@@ -99,7 +99,7 @@ def package_model(self, model_name, compilation_job):
9999
return PACKAGING_JOB
100100

101101
def wait_compilation(self, job):
102-
"""Wait for a Sagemaker Neo compilation job to complete"""
102+
"""Waits for a Sagemaker Neo compilation job to complete."""
103103
while True:
104104
response = sagemaker_client.describe_compilation_job(CompilationJobName=job)
105105
if response['CompilationJobStatus'] == 'COMPLETED':
@@ -110,7 +110,7 @@ def wait_compilation(self, job):
110110
time.sleep(5)
111111

112112
def wait_packaging(self, job):
113-
"""Wait for a Sagemaker Neo packaging job to complete"""
113+
"""Waits for a Sagemaker Neo packaging job to complete."""
114114
while True:
115115
response = sagemaker_client.describe_edge_packaging_job(EdgePackagingJobName=job)
116116
if response['EdgePackagingJobStatus'] == 'COMPLETED':
@@ -121,13 +121,13 @@ def wait_packaging(self, job):
121121
time.sleep(5)
122122

123123
def upload(self, bucket, key, src):
124-
"""Upload a file to Amazon S3"""
124+
"""Uploads a file to Amazon S3."""
125125
uri = 's3://{}/{}'.format(bucket,key)
126126
s3_resource.Bucket(bucket).Object(key).upload_file(src)
127127
return uri
128128

129129
def remove(self, path):
130-
"""Remove a file or directory from /tmp"""
130+
"""Removes a file or directory from /tmp."""
131131
if os.path.exists(path) and path.startswith('/tmp/') and len(path) > 5:
132132
if os.path.isfile(path) or os.path.islink(path):
133133
os.unlink(path)

0 commit comments

Comments
 (0)