Skip to content
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

benchmark: add some warping benchmarks to create a baseline #3260

Closed
wants to merge 2 commits into from

Conversation

hmaarrfk
Copy link
Member

PR #3253 is about speeding up computation when you want to.

I figured I would add some benchmarks to create a baseline.

It considers 2 cases:

  1. The case where want to go to "float64"
  2. The case where we don't care and just want the warped result as the final image.

I really wish I could test this on my own machine but I tried to install asv:

pip install git+https://github.com/airspeed-velocity/asv.git@v0.2.2rc1#egg=asv

and

pip install git+https://github.com/airspeed-velocity/asv.git#egg=asv

but all failed with

Traceback (most recent call last):
               File "/home/mark/miniconda3/envs/sk/lib/python3.6/site-packages/asv/benchmark.py", line 795, in <module>
                 commands[mode](args)
               File "/home/mark/miniconda3/envs/sk/lib/python3.6/site-packages/asv/benchmark.py", line 740, in main_discover
                 list_benchmarks(benchmark_dir, fp)
               File "/home/mark/miniconda3/envs/sk/lib/python3.6/site-packages/asv/benchmark.py", line 725, in list_benchmarks
                 for benchmark in disc_benchmarks(root):
               File "/home/mark/miniconda3/envs/sk/lib/python3.6/site-packages/asv/benchmark.py", line 710, in disc_benchmarks
                 for module in disc_files(root, os.path.basename(root) + '.'):
               File "/home/mark/miniconda3/envs/sk/lib/python3.6/site-packages/asv/benchmark.py", line 699, in disc_files
                 module = import_module(package + filename)
               File "/home/mark/git/scikit-image/.asv/env/eef864a9fed06fd59ca8023f9f5b02ad/lib/python3.6/importlib/__init__.py", line 126, in import_module
                 return _bootstrap._gcd_import(name[level:], package, level)
               File "<frozen importlib._bootstrap>", line 994, in _gcd_import
               File "<frozen importlib._bootstrap>", line 971, in _find_and_load
               File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
               File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
               File "<frozen importlib._bootstrap_external>", line 678, in exec_module
               File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
               File "/home/mark/git/scikit-image/benchmarks/transform_warp.py", line 2, in <module>
                 from skimage.transform import SimilarityTransform, warp

Checklist

[It's fine to submit PRs which are a work in progress! But before they are merged, all PRs should provide:]

[For detailed information on these and other aspects see scikit-image contribution guidelines]

References

[If this is a bug-fix or enhancement, it closes issue # ]
[If this is a new feature, it implements the following paper: ]

For reviewers

(Don't remove the checklist below.)

  • Check that the PR title is short, concise, and will make sense 1 year
    later.
  • Check that new functions are imported in corresponding __init__.py.
  • Check that new features, API changes, and deprecations are mentioned in
    doc/release/release_dev.rst.
  • Consider backporting the PR with @meeseeksdev backport to v0.14.x

@pep8speaks
Copy link

pep8speaks commented Jul 10, 2018

Hello @hmaarrfk! Thanks for updating the PR.

Cheers ! There are no PEP8 issues in this Pull Request. 🍻

Comment last updated on August 06, 2018 at 00:07 Hours UTC

translation=(0, 4))
self.order = order

def same_type(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you'll need to prefix these functions with time_ otherwise asv won't run / find them. And the signature must be able to accept all parameters as positional arguments because asv passes them implicitly to all setup, time_x and peakmem_ methods of the class.

@lagru
Copy link
Member

lagru commented Jul 14, 2018

I really wish I could test this on my own machine but I tried to install asv [...] but all failed with...

Is the traceback shown during installation of asv or when you try to run it?

I managed to install asv using either conda (conda-forge channel) or providing pip with the path to the cloned repository (which is similar to your attempts).

precision data type."""
result = warp(self.image, self.tform, order=self.order,
preserve_range=True)
convert(result, dtype=self.image.dtype, copy=False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now you are measuring the time it takes to execute warp and convert together. Is this intended? Wouldn't it be better to keep these measurements separate?

@hmaarrfk
Copy link
Member Author

hmaarrfk commented Jul 14, 2018 via email

@jni
Copy link
Member

jni commented Jul 23, 2018

@hmaarrfk yes, floating point values are critical for precision, but it is still useful to measure the time for each step separately. Therefore I would recommend benchmarks with and without conversion.

@codecov-io
Copy link

codecov-io commented Jul 23, 2018

Codecov Report

Merging #3260 into master will decrease coverage by 0.05%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3260      +/-   ##
==========================================
- Coverage   86.81%   86.75%   -0.06%     
==========================================
  Files         341      339       -2     
  Lines       27406    27356      -50     
==========================================
- Hits        23792    23733      -59     
- Misses       3614     3623       +9
Impacted Files Coverage Δ
skimage/io/_plugins/simpleitk_plugin.py 63.63% <0%> (-18.19%) ⬇️
skimage/io/_plugins/gtk_plugin.py 25% <0%> (-5.56%) ⬇️
skimage/io/tests/test_simpleitk.py 70.17% <0%> (-3.51%) ⬇️
skimage/_shared/_warnings.py 90.9% <0%> (-2.28%) ⬇️
skimage/io/_plugins/util.py 58.92% <0%> (-1.79%) ⬇️
skimage/measure/_moments.py 97.5% <0%> (-1.25%) ⬇️
skimage/draw/_random_shapes.py 95.78% <0%> (-1.06%) ⬇️
skimage/data/__init__.py 96% <0%> (-0.08%) ⬇️
skimage/measure/_regionprops.py 98.66% <0%> (-0.01%) ⬇️
skimage/filters/tests/test_thresholding.py 100% <0%> (ø) ⬆️
... and 13 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7549015...d49ecc5. Read the comment docs.

@hmaarrfk
Copy link
Member Author

@lagru @jni thank you for your comments.

I was treating the convert step as a "nop" in the time_to_float64. I feel like a common use case (at least for myself) is to cast things back to the original type after using many scikit-image functions.

My hypothesis:

  1. time_to_float64 test the current performance where the output is a float 64. This should improve for cases where the dtype of the image is not float64 with PR Enable warping with more than just doubles. #3253 as the computation will implicitly upcast to float64 (hopefully) but stay the same when the dtype is float64.
  2. time_same_type: should show improvements for the case when users need lower precision than 64bit. That said, the warping coefficients are still double. I should experiment to see if there are any gains in setting the warping coefficients to single precision when low precision types are used.

I had erroneously used convert as opposed to astype within the benchmarks.

Copy link
Member

@jni jni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hmaarrfk great, LGTM. Only a minor suggestion: I think it is preferred form to use np.random.random((N, N)) over np.random.rand(N, N) for consistency with other random functions, as well as the standard NumPy array creation functions (zeros, ones, full, etc).

@hmaarrfk
Copy link
Member Author

@jni, why can't I find the documentation for numpy.random.random

@hmaarrfk
Copy link
Member Author

hmaarrfk commented Jul 24, 2018

It isn't on this main page, but it does have its own doc page i'm just blind.

@hmaarrfk
Copy link
Member Author

@jni done!

@jni
Copy link
Member

jni commented Jul 24, 2018

@hmaarrfk

i'm just blind.

I suspected that might be the case as I saw your comments rolling in... =D

@hmaarrfk
Copy link
Member Author

hmaarrfk commented Jul 24, 2018

@jni, I realize i needed to install asv with system python3 and run it with bash or some combination thereof.

doesn't seem to be running correctly on my computer. mrg-1 for now. working now.

@soupault soupault added this to the 0.15 milestone Jul 28, 2018
@hmaarrfk hmaarrfk force-pushed the warp_benchmark branch 2 times, most recently from e2f3c8e to c597859 Compare August 6, 2018 00:07
@hmaarrfk
Copy link
Member Author

Closing in favour of just includeing this straight in #3253

@hmaarrfk hmaarrfk closed this Sep 15, 2018
@hmaarrfk hmaarrfk deleted the warp_benchmark branch November 4, 2018 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants