Optimize in time the image feature extractions algorithms#23
Optimize in time the image feature extractions algorithms#23hakim-cherif-mchp wants to merge 3 commits intoedgeimpulse:masterfrom
Conversation
… INTER_NEAREST is much quicker on hardware not equipped with image processing IPs.
…on some hardware platforms.
|
@Alex-EEE can you take a look? |
Alex-EEE
left a comment
There was a problem hiding this comment.
Thanks for the PR! The efficiency gains make a lot of sense, as you've converted a lot of this to numpy manipulations instead of slow lists
There's at least one bug to address, did you try running this code?
We'll also test and get back
| resize_size = (resize_size_w, resize_size_h) | ||
|
|
||
| resized = cv2.resize(img, resize_size, interpolation=cv2.INTER_AREA) | ||
| resized = cv2.resize(img, resize_size, interpolation=cv2.INTER_NEAREST) |
There was a problem hiding this comment.
We feel Inter Area is the best trade off for performance and output, especially since the user should only be downsizing. But I'm open to hear your thoughts
There was a problem hiding this comment.
Hi Alex,
Sorry for the delay, I tested more extensively the two algorithms, and it appears that it is possible to get a very high similarity score between the two sets of extracted features, but only under certain circumstances.
So, in my opinion, you should keep the INTER_AREA.
edge_impulse_linux/image.py
Outdated
| if is_grayscale: | ||
| resized_img = cv2.cvtColor(resized_img, cv2.COLOR_BGR2GRAY) | ||
| pixels = np.array(resized_img).flatten().tolist() | ||
| if self.isGrayscale: |
There was a problem hiding this comment.
Although this looks like a member function, it's actually outside of the class and thus there's no self variable
There was a problem hiding this comment.
Hi,
My mistake, I corrected it and pushed the related commit.
While working with code samples from this repository, I have seen that some parts are not optimized in time, and on some hardware the difference is significant.
On the Microchip SAMA7G54 is was able to divide by 25 the time taken for these operations. (From 500 ms to 20ms).