Skip to content

Commit 4ad2d4c

Browse files
committed
Print freeform output
1 parent de27005 commit 4ad2d4c

File tree

5 files changed

+31
-5
lines changed

5 files changed

+31
-5
lines changed

examples/audio/classify.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,19 @@ def main(argv):
5252
print("Device ID "+ str(selected_device_id) + " has been provided as an argument.")
5353

5454
for res, audio in runner.classifier(device_id=selected_device_id):
55-
print('Result (%d ms.) ' % (res['timing']['dsp'] + res['timing']['classification']), end='')
56-
for label in labels:
57-
score = res['result']['classification'][label]
58-
print('%s: %.2f\t' % (label, score), end='')
59-
print('', flush=True)
55+
if "classification" in res["result"].keys():
56+
print('Result (%d ms.) ' % (res['timing']['dsp'] + res['timing']['classification']), end='')
57+
for label in labels:
58+
score = res['result']['classification'][label]
59+
print('%s: %.2f\t' % (label, score), end='')
60+
print('', flush=True)
61+
elif "freeform" in res['result'].keys():
62+
print('Result (%d ms.)' % (res['timing']['dsp'] + res['timing']['classification']))
63+
for i in range(0, len(res['result']['freeform'])):
64+
print(f' Freeform output {i}:', ", ".join(f"{x:.4f}" for x in res['result']['freeform'][i]))
65+
else:
66+
print('Result (%d ms.)' % (res['timing']['dsp'] + res['timing']['classification']))
67+
print(res['result'])
6068

6169
finally:
6270
if (runner):

examples/image/classify-full-frame.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ def print_classification(res, tag):
124124
print('%s: Found %d bounding boxes (%d ms.)' % (tag, len(res["result"]["bounding_boxes"]), res['timing']['dsp'] + res['timing']['classification']))
125125
for bb in res["result"]["bounding_boxes"]:
126126
print('\t%s (%.2f): x=%d y=%d w=%d h=%d' % (bb['label'], bb['value'], bb['x'], bb['y'], bb['width'], bb['height']))
127+
elif "freeform" in res['result'].keys():
128+
print('Result (%d ms.)' % (res['timing']['dsp'] + res['timing']['classification']))
129+
for i in range(0, len(res['result']['freeform'])):
130+
print(f' Freeform output {i}:', ", ".join(f"{x:.4f}" for x in res['result']['freeform'][i]))
127131

128132
if "visual_anomaly_grid" in res["result"].keys():
129133
print('Found %d visual anomalies (%d ms.)' % (len(res["result"]["visual_anomaly_grid"]), res['timing']['dsp'] +

examples/image/classify-image.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ def main(argv):
7777
print('\t%s (%.2f): x=%d y=%d w=%d h=%d' % (bb['label'], bb['value'], bb['x'], bb['y'], bb['width'], bb['height']))
7878
cropped = cv2.rectangle(cropped, (bb['x'], bb['y']), (bb['x'] + bb['width'], bb['y'] + bb['height']), (255, 0, 0), 1)
7979

80+
elif "freeform" in res['result'].keys():
81+
print('Result (%d ms.)' % (res['timing']['dsp'] + res['timing']['classification']))
82+
for i in range(0, len(res['result']['freeform'])):
83+
print(f' Freeform output {i}:', ", ".join(f"{x:.4f}" for x in res['result']['freeform'][i]))
84+
8085
if "visual_anomaly_grid" in res["result"].keys():
8186
print('Found %d visual anomalies (%d ms.)' % (len(res["result"]["visual_anomaly_grid"]), res['timing']['dsp'] +
8287
res['timing']['classification'] +

examples/image/classify-video.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ def getFrame(sec):
9595
print('\t%s (%.2f): x=%d y=%d w=%d h=%d' % (bb['label'], bb['value'], bb['x'], bb['y'], bb['width'], bb['height']))
9696
img = cv2.rectangle(cropped, (bb['x'], bb['y']), (bb['x'] + bb['width'], bb['y'] + bb['height']), (255, 0, 0), 1)
9797

98+
elif "freeform" in res['result'].keys():
99+
print('Result (%d ms.)' % (res['timing']['dsp'] + res['timing']['classification']))
100+
for i in range(0, len(res['result']['freeform'])):
101+
print(f' Freeform output {i}:', ", ".join(f"{x:.4f}" for x in res['result']['freeform'][i]))
102+
98103
# Object tracking output
99104
if "object_tracking" in res["result"].keys():
100105
print('Found %d tracked objects' % (len(res["result"]["object_tracking"])))

examples/image/classify.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ def main(argv):
118118
for bb in res["result"]["bounding_boxes"]:
119119
print('\t%s (%.2f): x=%d y=%d w=%d h=%d' % (bb['label'], bb['value'], bb['x'], bb['y'], bb['width'], bb['height']))
120120
img = cv2.rectangle(img, (bb['x'], bb['y']), (bb['x'] + bb['width'], bb['y'] + bb['height']), (255, 0, 0), 1)
121+
elif "freeform" in res['result'].keys():
122+
print('Result (%d ms.)' % (res['timing']['dsp'] + res['timing']['classification']))
123+
for i in range(0, len(res['result']['freeform'])):
124+
print(f' Freeform output {i}:', ", ".join(f"{x:.4f}" for x in res['result']['freeform'][i]))
121125

122126
if (show_camera):
123127
cv2.imshow('edgeimpulse', cv2.cvtColor(img, cv2.COLOR_RGB2BGR))

0 commit comments

Comments
 (0)