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

Improve mask_to_rle performance #770

Merged
merged 8 commits into from
Dec 7, 2022

Conversation

vinnamkim
Copy link
Contributor

@vinnamkim vinnamkim commented Nov 25, 2022

Signed-off-by: Kim, Vinnam vinnam.kim@intel.com

Summary

import numpy as np
from datumaro.util.mask_tools import mask_to_rle, mask_to_rle_py
import pycocotools.mask as mask_utils
from time import time

img_size = 768
mask = np.zeros([img_size, img_size])
# mask = np.random.randint(0, 2, size=[img_size, img_size])

for i in range(img_size):
    mask[i, :i] = 1

mask = mask.astype(dtype=np.uint8)

t1 = time()
for _ in range(10):
    result = mask_to_rle_py(mask)
print(f"Datumaro old implementation: {(time() - t1) * 1000:.2f} (ms)")

t1 = time()
for _ in range(10):
    mask_utils.encode(np.asfortranarray(mask))
print(f"pycocotools compressed RLE: {(time() - t1) * 1000:.2f} (ms)")

t1 = time()
for _ in range(10):
    result = mask_to_rle(mask)
print(f"Datumaro C-API uncompressed RLE: {(time() - t1) * 1000:.2f} (ms)")
Datumaro old implementation: 25.32 (ms)
pycocotools compressed RLE: 10.40 (ms)
Datumaro C-API uncompressed RLE: 9.66 (ms)

How to test

If the new C-API is compatible with the previous API, our existing unit tests should be passed all.

Checklist

License

  • I submit my code changes under the same MIT License that covers the project.
    Feel free to contact the maintainers if that's a concern.
  • I have updated the license header for each file (see an example below)
# Copyright (C) 2021 Intel Corporation
#
# SPDX-License-Identifier: MIT

Signed-off-by: Kim, Vinnam <vinnam.kim@intel.com>
Signed-off-by: Kim, Vinnam <vinnam.kim@intel.com>
@codecov-commenter
Copy link

codecov-commenter commented Nov 25, 2022

Codecov Report

Base: 84.61% // Head: 84.67% // Increases project coverage by +0.06% 🎉

Coverage data is based on head (f93dcd9) compared to base (e3ca3b5).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #770      +/-   ##
===========================================
+ Coverage    84.61%   84.67%   +0.06%     
===========================================
  Files          157      157              
  Lines        22055    22064       +9     
  Branches      4829     4829              
===========================================
+ Hits         18661    18683      +22     
+ Misses        2284     2273      -11     
+ Partials      1110     1108       -2     
Flag Coverage Δ
macos-10.15_Python-3.10 84.58% <100.00%> (+0.49%) ⬆️
macos-10.15_Python-3.7 84.27% <100.00%> (+0.51%) ⬆️
macos-10.15_Python-3.8 84.51% <100.00%> (+0.49%) ⬆️
macos-10.15_Python-3.9 84.52% <100.00%> (+0.50%) ⬆️
ubuntu-20.04_Python-3.10 84.60% <100.00%> (+0.52%) ⬆️
ubuntu-20.04_Python-3.7 84.29% <100.00%> (+0.51%) ⬆️
ubuntu-20.04_Python-3.8 84.53% <100.00%> (+0.50%) ⬆️
ubuntu-20.04_Python-3.9 84.54% <100.00%> (+0.50%) ⬆️
windows-2019_Python-3.10 84.60% <100.00%> (+0.50%) ⬆️
windows-2019_Python-3.7 84.29% <100.00%> (+0.06%) ⬆️
windows-2019_Python-3.8 84.52% <100.00%> (+0.50%) ⬆️
windows-2019_Python-3.9 84.53% <100.00%> (+0.50%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
datumaro/plugins/synthetic_data/image_generator.py 93.49% <100.00%> (+10.66%) ⬆️
datumaro/util/mask_tools.py 76.78% <100.00%> (-3.83%) ⬇️
datumaro/plugins/synthetic_data/utils.py 84.61% <0.00%> (+2.56%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Signed-off-by: Kim, Vinnam <vinnam.kim@intel.com>
Signed-off-by: Kim, Vinnam <vinnam.kim@intel.com>
Signed-off-by: Kim, Vinnam <vinnam.kim@intel.com>
Signed-off-by: Kim, Vinnam <vinnam.kim@intel.com>
Signed-off-by: Kim, Vinnam <vinnam.kim@intel.com>
Signed-off-by: Kim, Vinnam <vinnam.kim@intel.com>
Copy link
Contributor

@bonhunko bonhunko left a comment

Choose a reason for hiding this comment

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

LGTM!

@wonjuleee wonjuleee merged commit 681e8c6 into openvinotoolkit:develop Dec 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ENHANCE Enhancement of existing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Performance] Converting mask to RLE comparison with COCO tools
4 participants