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

Speed up build_mask (~100 times) #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

chAwater
Copy link

Modifications

  • Use np.ogrid instead of double for loop to speed up the build_mask
  • Inspired by a StackOverflow post link

Tests & results

Code

# small image
%timeit -n 3 org_build_mask(256)
%timeit -n 1000 my_build_mask(256)

# large image
%timeit -n 3 org_build_mask(1800)
%timeit -n 100 my_build_mask(1800)

# diffs
(my_build_mask(256) - org_build_mask(256)).abs().sum()
(my_build_mask(1800) - org_build_mask(1800)).abs().sum()

Output

448 ms ± 44 ms per loop (mean ± std. dev. of 7 runs, 3 loops each)
2.21 ms ± 389 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)


23.4 s ± 325 ms per loop (mean ± std. dev. of 7 runs, 3 loops each)
144 ms ± 4.81 ms per loop (mean ± std. dev. of 7 runs, 100 loops each)

tensor(4.9242e-08, dtype=torch.float64)
tensor(1.2405e-06, dtype=torch.float64)

BTW

I'm also trying to make the same animation using the escnn.
But I have encountered some problems (I'll resolve them in the next few days, hopefully).
Please let me know if you already have the escnn version of the animation.py code.

@chAwater chAwater force-pushed the speed-up-mask branch 4 times, most recently from cbccee5 to 4d2d2d0 Compare April 12, 2023 02:08
Signed-off-by: hoho2b <chenhe@megarobo.tech>
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.

1 participant