-
Notifications
You must be signed in to change notification settings - Fork 28
Add support for EIM files with shared memory, add support for setting thresholds #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
examples/image/classify-image.py
Outdated
@@ -39,6 +43,7 @@ def main(argv): | |||
with ImageImpulseRunner(modelfile) as runner: | |||
try: | |||
model_info = runner.init() | |||
print('model_info', model_info) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be removed
|
||
if self._shm is not None: | ||
self._shm['shm'].close() | ||
resource_tracker.unregister(self._shm['shm']._name, "shared_memory") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to do this because we don't own the shared memory - otherwise will get a warning from the resource tracker that we leave shared memory behind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have found the for loops at the end of get_features_from_image_with_studio_mode()
add quite a lot of latency to inference- switching out for numpy flatten instead speeds things up significantly on slower devices
if is_grayscale:
resized_img = cv2.cvtColor(resized_img, cv2.COLOR_BGR2GRAY)
# Use numpy's vectorized operations for feature encoding
features = (resized_img.astype(np.uint32) * 0x010101).flatten().tolist()
else:
# Use numpy's vectorized operations for RGB feature encoding
pixels = resized_img.astype(np.uint32)
features = ((pixels[..., 0] << 16) | (pixels[..., 1] << 8) | pixels[..., 2]).flatten().tolist()
return features, resized_img
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, the new implementation is ~10 times faster.
Previous versions were ~10 slower than the new one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested it and it looks good. Added some small improvements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, the new implementation is ~10 times faster.
Companion to https://github.com/edgeimpulse/edgeimpulse/pull/13597
set_threshold
(plus example)