[optimizing] vectorize, cache and precompute#49
[optimizing] vectorize, cache and precompute#49davidfischer-ch merged 15 commits intosmartcrop:masterfrom
Conversation
…uted prescores from score method - avoid a multiplication each score run.
…of stacking, maximum instead of boolean masks
Pull Request Test Coverage Report for Build 21993256552Details
💛 - Coveralls |
|
@davidfischer-ch so, that part is done, what do you think about it? |
|
This looks great, I am interested in getting some speed, CPU and memory usage metrics. For example you may run this and previous version using Thank you. |
I already use some kind of benchmark on project's test pix. Here a gist with the code. If you want to run it, just put it into the project directory, create an 'othercrops' directory with directories of other versions of SmartCrop (or just import somehow another SmartCrop from somewhere and fix the import). Here are the timingsaverage times of 5 shuffeled runs If you're interested in memory usage, I haven't measured anything yet, but my gut feeling is that there aren't that many differences. Nothing crazy happens in the code, a few importance maps are cached, but it's not a thing at all. |
Vectorized importance map: The
get_importance()method now generates a composite weighting map using numpy, replacing the slow per-pixel computations with efficient array operations.Caching for repeated calculations: Importance maps are cached per crop dimensions, avoiding redundant computations across multiple crop candidates.
Precomputed features: The new
precompute_features()method consolidates scaling, biasing, and weighting operations into a single, vectorized step. This eliminates repetitive calculations during scoring.Other small things:
debug_crop()