Skip to content

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

janjongboom
Copy link
Member

@janjongboom janjongboom commented Aug 4, 2025

Companion to https://github.com/edgeimpulse/edgeimpulse/pull/13597

  • Add support for shared memory to exchange features
  • Add support for set_threshold (plus example)
  • Also clean up / widen the requirements list; so less conflicts when importing this package

@janjongboom janjongboom changed the title Add support for EIM files with shared memory Add support for EIM files with shared memory, add support for setting thresholds Aug 4, 2025
@mmajchrzycki mmajchrzycki self-requested a review August 4, 2025 10:46
@@ -39,6 +43,7 @@ def main(argv):
with ImageImpulseRunner(modelfile) as runner:
try:
model_info = runner.init()
print('model_info', model_info)
Copy link
Member Author

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")
Copy link
Member Author

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.

Copy link

@jimbruges jimbruges Aug 6, 2025

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

Copy link
Contributor

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.

Copy link
Contributor

@mmajchrzycki mmajchrzycki left a 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.

Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants