Skip to content

Commit e7c674d

Browse files
authored
Add MergeTileTransform (#796)
* Add MergeTileTransform * Update CHANGELOG.md * Use area to compare equivalence of two Polygons * Restrict fsspec package version to 2022.11.0 in Python 3.7 * Update fsspec license.txt in 3rd-party.txt * Update 3rd-party.txt Signed-off-by: Kim, Vinnam <[email protected]>
1 parent f4c8e3c commit e7c674d

File tree

9 files changed

+843
-183
lines changed

9 files changed

+843
-183
lines changed

3rd-party.txt

Lines changed: 240 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4926,8 +4926,6 @@ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
49264926
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
49274927
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
49284928
-------------------------------------------------------------
4929-
* Other names and brands may be claimed as the property of others.
4930-
-------------------------------------------------------------
49314929
shapely
49324930

49334931
https://github.com/shapely/shapely
@@ -4961,3 +4959,243 @@ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
49614959
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
49624960
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
49634961
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4962+
-------------------------------------------------------------
4963+
OpenVINO™
4964+
Apache License
4965+
Version 2.0, January 2004
4966+
http://www.apache.org/licenses/
4967+
4968+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
4969+
4970+
1. Definitions.
4971+
4972+
"License" shall mean the terms and conditions for use, reproduction,
4973+
and distribution as defined by Sections 1 through 9 of this document.
4974+
4975+
"Licensor" shall mean the copyright owner or entity authorized by
4976+
the copyright owner that is granting the License.
4977+
4978+
"Legal Entity" shall mean the union of the acting entity and all
4979+
other entities that control, are controlled by, or are under common
4980+
control with that entity. For the purposes of this definition,
4981+
"control" means (i) the power, direct or indirect, to cause the
4982+
direction or management of such entity, whether by contract or
4983+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
4984+
outstanding shares, or (iii) beneficial ownership of such entity.
4985+
4986+
"You" (or "Your") shall mean an individual or Legal Entity
4987+
exercising permissions granted by this License.
4988+
4989+
"Source" form shall mean the preferred form for making modifications,
4990+
including but not limited to software source code, documentation
4991+
source, and configuration files.
4992+
4993+
"Object" form shall mean any form resulting from mechanical
4994+
transformation or translation of a Source form, including but
4995+
not limited to compiled object code, generated documentation,
4996+
and conversions to other media types.
4997+
4998+
"Work" shall mean the work of authorship, whether in Source or
4999+
Object form, made available under the License, as indicated by a
5000+
copyright notice that is included in or attached to the work
5001+
(an example is provided in the Appendix below).
5002+
5003+
"Derivative Works" shall mean any work, whether in Source or Object
5004+
form, that is based on (or derived from) the Work and for which the
5005+
editorial revisions, annotations, elaborations, or other modifications
5006+
represent, as a whole, an original work of authorship. For the purposes
5007+
of this License, Derivative Works shall not include works that remain
5008+
separable from, or merely link (or bind by name) to the interfaces of,
5009+
the Work and Derivative Works thereof.
5010+
5011+
"Contribution" shall mean any work of authorship, including
5012+
the original version of the Work and any modifications or additions
5013+
to that Work or Derivative Works thereof, that is intentionally
5014+
submitted to Licensor for inclusion in the Work by the copyright owner
5015+
or by an individual or Legal Entity authorized to submit on behalf of
5016+
the copyright owner. For the purposes of this definition, "submitted"
5017+
means any form of electronic, verbal, or written communication sent
5018+
to the Licensor or its representatives, including but not limited to
5019+
communication on electronic mailing lists, source code control systems,
5020+
and issue tracking systems that are managed by, or on behalf of, the
5021+
Licensor for the purpose of discussing and improving the Work, but
5022+
excluding communication that is conspicuously marked or otherwise
5023+
designated in writing by the copyright owner as "Not a Contribution."
5024+
5025+
"Contributor" shall mean Licensor and any individual or Legal Entity
5026+
on behalf of whom a Contribution has been received by Licensor and
5027+
subsequently incorporated within the Work.
5028+
5029+
2. Grant of Copyright License. Subject to the terms and conditions of
5030+
this License, each Contributor hereby grants to You a perpetual,
5031+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
5032+
copyright license to reproduce, prepare Derivative Works of,
5033+
publicly display, publicly perform, sublicense, and distribute the
5034+
Work and such Derivative Works in Source or Object form.
5035+
5036+
3. Grant of Patent License. Subject to the terms and conditions of
5037+
this License, each Contributor hereby grants to You a perpetual,
5038+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
5039+
(except as stated in this section) patent license to make, have made,
5040+
use, offer to sell, sell, import, and otherwise transfer the Work,
5041+
where such license applies only to those patent claims licensable
5042+
by such Contributor that are necessarily infringed by their
5043+
Contribution(s) alone or by combination of their Contribution(s)
5044+
with the Work to which such Contribution(s) was submitted. If You
5045+
institute patent litigation against any entity (including a
5046+
cross-claim or counterclaim in a lawsuit) alleging that the Work
5047+
or a Contribution incorporated within the Work constitutes direct
5048+
or contributory patent infringement, then any patent licenses
5049+
granted to You under this License for that Work shall terminate
5050+
as of the date such litigation is filed.
5051+
5052+
4. Redistribution. You may reproduce and distribute copies of the
5053+
Work or Derivative Works thereof in any medium, with or without
5054+
modifications, and in Source or Object form, provided that You
5055+
meet the following conditions:
5056+
5057+
(a) You must give any other recipients of the Work or
5058+
Derivative Works a copy of this License; and
5059+
5060+
(b) You must cause any modified files to carry prominent notices
5061+
stating that You changed the files; and
5062+
5063+
(c) You must retain, in the Source form of any Derivative Works
5064+
that You distribute, all copyright, patent, trademark, and
5065+
attribution notices from the Source form of the Work,
5066+
excluding those notices that do not pertain to any part of
5067+
the Derivative Works; and
5068+
5069+
(d) If the Work includes a "NOTICE" text file as part of its
5070+
distribution, then any Derivative Works that You distribute must
5071+
include a readable copy of the attribution notices contained
5072+
within such NOTICE file, excluding those notices that do not
5073+
pertain to any part of the Derivative Works, in at least one
5074+
of the following places: within a NOTICE text file distributed
5075+
as part of the Derivative Works; within the Source form or
5076+
documentation, if provided along with the Derivative Works; or,
5077+
within a display generated by the Derivative Works, if and
5078+
wherever such third-party notices normally appear. The contents
5079+
of the NOTICE file are for informational purposes only and
5080+
do not modify the License. You may add Your own attribution
5081+
notices within Derivative Works that You distribute, alongside
5082+
or as an addendum to the NOTICE text from the Work, provided
5083+
that such additional attribution notices cannot be construed
5084+
as modifying the License.
5085+
5086+
You may add Your own copyright statement to Your modifications and
5087+
may provide additional or different license terms and conditions
5088+
for use, reproduction, or distribution of Your modifications, or
5089+
for any such Derivative Works as a whole, provided Your use,
5090+
reproduction, and distribution of the Work otherwise complies with
5091+
the conditions stated in this License.
5092+
5093+
5. Submission of Contributions. Unless You explicitly state otherwise,
5094+
any Contribution intentionally submitted for inclusion in the Work
5095+
by You to the Licensor shall be under the terms and conditions of
5096+
this License, without any additional terms or conditions.
5097+
Notwithstanding the above, nothing herein shall supersede or modify
5098+
the terms of any separate license agreement you may have executed
5099+
with Licensor regarding such Contributions.
5100+
5101+
6. Trademarks. This License does not grant permission to use the trade
5102+
names, trademarks, service marks, or product names of the Licensor,
5103+
except as required for reasonable and customary use in describing the
5104+
origin of the Work and reproducing the content of the NOTICE file.
5105+
5106+
7. Disclaimer of Warranty. Unless required by applicable law or
5107+
agreed to in writing, Licensor provides the Work (and each
5108+
Contributor provides its Contributions) on an "AS IS" BASIS,
5109+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
5110+
implied, including, without limitation, any warranties or conditions
5111+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
5112+
PARTICULAR PURPOSE. You are solely responsible for determining the
5113+
appropriateness of using or redistributing the Work and assume any
5114+
risks associated with Your exercise of permissions under this License.
5115+
5116+
8. Limitation of Liability. In no event and under no legal theory,
5117+
whether in tort (including negligence), contract, or otherwise,
5118+
unless required by applicable law (such as deliberate and grossly
5119+
negligent acts) or agreed to in writing, shall any Contributor be
5120+
liable to You for damages, including any direct, indirect, special,
5121+
incidental, or consequential damages of any character arising as a
5122+
result of this License or out of the use or inability to use the
5123+
Work (including but not limited to damages for loss of goodwill,
5124+
work stoppage, computer failure or malfunction, or any and all
5125+
other commercial damages or losses), even if such Contributor
5126+
has been advised of the possibility of such damages.
5127+
5128+
9. Accepting Warranty or Additional Liability. While redistributing
5129+
the Work or Derivative Works thereof, You may choose to offer,
5130+
and charge a fee for, acceptance of support, warranty, indemnity,
5131+
or other liability obligations and/or rights consistent with this
5132+
License. However, in accepting such obligations, You may act only
5133+
on Your own behalf and on Your sole responsibility, not on behalf
5134+
of any other Contributor, and only if You agree to indemnify,
5135+
defend, and hold each Contributor harmless for any liability
5136+
incurred by, or claims asserted against, such Contributor by reason
5137+
of your accepting any such warranty or additional liability.
5138+
5139+
END OF TERMS AND CONDITIONS
5140+
5141+
APPENDIX: How to apply the Apache License to your work.
5142+
5143+
To apply the Apache License to your work, attach the following
5144+
boilerplate notice, with the fields enclosed by brackets "[]"
5145+
replaced with your own identifying information. (Don't include
5146+
the brackets!) The text should be enclosed in the appropriate
5147+
comment syntax for the file format. We also recommend that a
5148+
file or class name and description of purpose be included on the
5149+
same "printed page" as the copyright notice for easier
5150+
identification within third-party archives.
5151+
5152+
Copyright [yyyy] [name of copyright owner]
5153+
5154+
Licensed under the Apache License, Version 2.0 (the "License");
5155+
you may not use this file except in compliance with the License.
5156+
You may obtain a copy of the License at
5157+
5158+
http://www.apache.org/licenses/LICENSE-2.0
5159+
5160+
Unless required by applicable law or agreed to in writing, software
5161+
distributed under the License is distributed on an "AS IS" BASIS,
5162+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5163+
See the License for the specific language governing permissions and
5164+
limitations under the License.
5165+
5166+
-------------------------------------------------------------
5167+
filesystem_spec
5168+
5169+
BSD 3-Clause License
5170+
5171+
Copyright (c) 2018, Martin Durant
5172+
All rights reserved.
5173+
5174+
Redistribution and use in source and binary forms, with or without
5175+
modification, are permitted provided that the following conditions are met:
5176+
5177+
* Redistributions of source code must retain the above copyright notice, this
5178+
list of conditions and the following disclaimer.
5179+
5180+
* Redistributions in binary form must reproduce the above copyright notice,
5181+
this list of conditions and the following disclaimer in the documentation
5182+
and/or other materials provided with the distribution.
5183+
5184+
* Neither the name of the copyright holder nor the names of its
5185+
contributors may be used to endorse or promote products derived from
5186+
this software without specific prior written permission.
5187+
5188+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
5189+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5190+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
5191+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
5192+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5193+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
5194+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
5195+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
5196+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
5197+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5198+
-------------------------------------------------------------
5199+
5200+
5201+
* Other names and brands may be claimed as the property of others.

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
(<https://github.com/openvinotoolkit/datumaro/pull/791>)
1414
- Add TileTransform documentation and Jupyter notebook example
1515
(<https://github.com/openvinotoolkit/datumaro/pull/794>)
16+
- Add MergeTile transformation
17+
(<https://github.com/openvinotoolkit/datumaro/pull/796>)
1618

1719
### Changed
1820
- Improved mask_to_rle performance

datumaro/components/annotation.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import attr
1313
import numpy as np
14+
import shapely.geometry as sg
1415
from attr import asdict, attrs, field
1516
from typing_extensions import Literal
1617

@@ -641,7 +642,7 @@ def _set_scale(self, value):
641642
self.scale[:] = np.around(value, COORDINATE_ROUNDING_DIGITS).tolist()
642643

643644

644-
@attrs(slots=True, order=False)
645+
@attrs(slots=True, order=False, eq=False)
645646
class Polygon(_Shape):
646647
_type = AnnotationType.polygon
647648

@@ -659,6 +660,21 @@ def get_area(self):
659660
area = mask_utils.area(rle)[0]
660661
return area
661662

663+
def __eq__(self, other):
664+
if not isinstance(other, __class__):
665+
return False
666+
if (
667+
not Annotation.__eq__(self, other)
668+
or self.label != other.label
669+
or self.z_order != other.z_order
670+
):
671+
return False
672+
673+
self_polygon = sg.Polygon(self.get_points())
674+
other_polygon = sg.Polygon(other.get_points())
675+
inter_area = self_polygon.intersection(other_polygon).area
676+
return abs(self_polygon.area - inter_area) == 0.0
677+
662678

663679
@attrs(slots=True, init=False, order=False)
664680
class Bbox(_Shape):
@@ -829,12 +845,19 @@ class Caption(Annotation):
829845
caption: str = field(converter=str)
830846

831847

832-
@attrs(slots=True, order=False)
848+
@attrs(slots=True, order=False, eq=False)
833849
class _ImageAnnotation(Annotation):
834850
image: Image = field()
835851

852+
def __eq__(self, other):
853+
if not super().__eq__(other):
854+
return False
855+
if not isinstance(other, __class__):
856+
return False
857+
return np.array_equal(self.image, other.image)
836858

837-
@attrs(slots=True, order=False)
859+
860+
@attrs(slots=True, order=False, eq=False)
838861
class SuperResolutionAnnotation(_ImageAnnotation):
839862
"""
840863
Represents high resolution images.
@@ -843,7 +866,7 @@ class SuperResolutionAnnotation(_ImageAnnotation):
843866
_type = AnnotationType.super_resolution_annotation
844867

845868

846-
@attrs(slots=True, order=False)
869+
@attrs(slots=True, order=False, eq=False)
847870
class DepthAnnotation(_ImageAnnotation):
848871
"""
849872
Represents depth images.

datumaro/components/media.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,3 +571,25 @@ def save(self, path):
571571
path = osp.abspath(path)
572572
os.makedirs(osp.dirname(path), exist_ok=True)
573573
save_image(path, self.data)
574+
575+
576+
ImageWithRoI = Tuple[Image, BboxIntCoords]
577+
578+
579+
class MosaicImage(Image):
580+
def __init__(self, imgs: List[ImageWithRoI], size: Tuple[int, int]) -> None:
581+
def _get_mosaic_img(_) -> np.ndarray:
582+
h, w = self.size
583+
mosaic_img = np.zeros(shape=(h, w, 3), dtype=np.uint8)
584+
for img, roi in imgs:
585+
assert isinstance(img, Image), "MosaicImage can only take a list of Images."
586+
x, y, w, h = roi
587+
mosaic_img[y : y + h, x : x + w] = img.data
588+
return mosaic_img
589+
590+
super().__init__(data=_get_mosaic_img, path=None, ext=None, size=size)
591+
592+
def save(self, path):
593+
path = osp.abspath(path)
594+
os.makedirs(osp.dirname(path), exist_ok=True)
595+
save_image(path, self.data)

0 commit comments

Comments
 (0)