AWS DeepLens Guia página 65

Tabla de contenido
results_thread = FIFO_Thread()
results_thread.start()
# Send a starting message to the AWS IoT console.
client.publish(topic=iotTopic, payload="Object detection starts now")
# Load the model to the GPU (use {"GPU": 0} for CPU).
mcfg = {"GPU": 1}
model = awscam.Model(modelPath, mcfg)
client.publish(topic=iotTopic, payload="Model loaded")
ret, frame = awscam.getLastFrame()
if ret == False:
raise Exception("Failed to get frame from the stream")
yscale = float(frame.shape[0]/input_height)
xscale = float(frame.shape[1]/input_width)
doInfer = True
while doInfer:
# Get a frame from the video stream.
ret, frame = awscam.getLastFrame()
# If you fail to get a frame, raise an exception.
if ret == False:
raise Exception("Failed to get frame from the stream")
# Resize the frame to meet the
frameResize = cv2.resize(frame, (input_width, input_height))
# Run model inference on the resized frame.
inferOutput = model.doInference(frameResize)
# Output the result of inference to the fifo file so it can be viewed with
mplayer.
parsed_results = model.parseResult(modelType, inferOutput)['ssd']
label = '{'
for obj in parsed_results:
if obj['prob'] > max_threshold:
xmin = int( xscale * obj['xmin'] ) + int((obj['xmin'] - input_width/2)
+ input_width/2)
ymin = int( yscale * obj['ymin'] )
xmax = int( xscale * obj['xmax'] ) + int((obj['xmax'] - input_width/2)
+ input_width/2)
ymax = int( yscale * obj['ymax'] )
cv2.rectangle(frame, (xmin, ymin), (xmax, ymax), (255, 165, 20), 4)
label += '"{}": {:.2f},'.format(outMap[obj['label']], obj['prob'] )
label_show = "{}:
obj['prob']*100 )
cv2.putText(frame, label_show, (xmin,
ymin-15),cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 165, 20), 4)
label += '"null": 0.0'
label += '}'
client.publish(topic=iotTopic, payload = label)
global jpeg
ret,jpeg = cv2.imencode('.jpg', frame)
except Exception as e:
msg = "Test failed: " + str(e)
client.publish(topic=iotTopic, payload=msg)
# Asynchronously schedule this function to be run again in 15 seconds.
Timer(15, greengrass_infinite_infer_run).start()
# Execute the function.
greengrass_infinite_infer_run()
AWS DeepLens Guía para desarrolladores
Creación de una función Lambda
para ver el flujo del proyecto
model input requirement.
{:.2f}%".format(outMap[obj['label']],
61
Tabla de contenido
loading

Tabla de contenido