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

Fix Datumaro visualizer's import errors after introducing lazy import #1220

Merged
merged 5 commits into from
Dec 13, 2023

Conversation

vinnamkim
Copy link
Contributor

@vinnamkim vinnamkim commented Dec 11, 2023

Summary

  • Ticket no. 127143

How to test

This Python code raises ImportError before this patch.

code
import numpy as np
import datumaro as dm

### Create example dataset ###


def create_example_dataset() -> dm.Dataset:
    blank_img = dm.Image.from_numpy(np.zeros([10, 10, 3], dtype=np.uint8))
    categories = ["label_1", "label_2", "label_3"]

    points_of_1x1_box = np.array([0, 0, 0, 1, 1, 1, 1, 0])

    item_not_to_drop = dm.DatasetItem(
        id="item_not_to_drop",
        media=blank_img,
        annotations=[
            dm.Polygon(
                points=label + points_of_1x1_box,
                label=label,
            )
            for label in range(len(categories))
        ],
    )

    item_drop_by_big_polygon = dm.DatasetItem(
        id="item_drop_by_big_polygon",
        media=blank_img,
        annotations=[
            dm.Polygon(
                points=8 * points_of_1x1_box,  # 8x8 box
                label=0,
            )
        ],
    )

    item_drop_by_polygon_union = dm.DatasetItem(
        id="item_drop_by_polygon_union",
        media=blank_img,
        annotations=[
            dm.Polygon(
                points=offset + 4 * points_of_1x1_box,  # 10 5x5 boxes placed in diagnoal
                label=1,
            )
            for offset in range(10)
        ],
    )

    return dm.Dataset.from_iterable(
        iterable=[
            item_not_to_drop,
            item_drop_by_big_polygon,
            item_drop_by_polygon_union,
        ],
        categories=categories,
    )


dataset = create_example_dataset()
vis = dm.Visualizer(dataset)
fig = vis.vis_gallery([item for item in dataset])
fig.show()

image

After this patch, there is no more these errors.

Checklist

  • I have added unit tests to cover my changes.​
  • I have added integration tests to cover my changes.​
  • I have added the description of my changes into CHANGELOG.​
  • I have updated the documentation accordingly

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) 2023 Intel Corporation
#
# SPDX-License-Identifier: MIT

Signed-off-by: Kim, Vinnam <vinnam.kim@intel.com>
@vinnamkim vinnamkim added the BUG Something isn't working label Dec 11, 2023
@vinnamkim vinnamkim marked this pull request as ready for review December 11, 2023 02:23
@vinnamkim vinnamkim requested review from a team as code owners December 11, 2023 02:23
@vinnamkim vinnamkim requested review from sooahleex and removed request for a team December 11, 2023 02:23
Signed-off-by: Kim, Vinnam <vinnam.kim@intel.com>
Copy link

codecov bot commented Dec 11, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (9b254ce) 80.10% compared to head (12b1803) 80.44%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1220      +/-   ##
===========================================
+ Coverage    80.10%   80.44%   +0.34%     
===========================================
  Files          269      269              
  Lines        29915    29913       -2     
  Branches      5850     5850              
===========================================
+ Hits         23962    24064     +102     
+ Misses        4617     4487     -130     
- Partials      1336     1362      +26     
Flag Coverage Δ
macos-11_Python-3.8 79.10% <100.00%> (+0.34%) ⬆️
ubuntu-20.04_Python-3.8 80.44% <100.00%> (+0.34%) ⬆️
windows-2022_Python-3.8 80.41% <100.00%> (+0.34%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@wonjuleee wonjuleee left a comment

Choose a reason for hiding this comment

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

Could you implement an optional showing of id and subset info in the visualizer too?

Copy link
Contributor

@wonjuleee wonjuleee left a comment

Choose a reason for hiding this comment

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

LGTM

@vinnamkim vinnamkim merged commit 4faaae5 into openvinotoolkit:develop Dec 13, 2023
6 checks passed
@vinnamkim vinnamkim deleted the fix-pyplot-import branch December 13, 2023 04:09
vinnamkim added a commit that referenced this pull request Dec 14, 2023
<!-- Contributing guide:
https://github.com/openvinotoolkit/datumaro/blob/develop/CONTRIBUTING.md
-->

### Summary

- Ticket no. 127587
- This option is needed for Datumaro GUI. See this comment,
#1220 (review)

### How to test
The existing unit test can cover `show_plot_title=True` option.
`show_plot_title=False` is not covered, but manually tested. Please see
this

![image](https://github.com/openvinotoolkit/datumaro/assets/26541465/be5f9c1f-d115-40a8-bac6-d91e16fc946f)
It might be addressed in the future when we transition the `Visualizer`
unit tests from the `unittest` to the `pytest` framework.

### Checklist
<!-- Put an 'x' in all the boxes that apply -->
- [ ] I have added unit tests to cover my changes.​
- [ ] I have added integration tests to cover my changes.​
- [x] I have added the description of my changes into
[CHANGELOG](https://github.com/openvinotoolkit/datumaro/blob/develop/CHANGELOG.md).​
- [ ] I have updated the
[documentation](https://github.com/openvinotoolkit/datumaro/tree/develop/docs)
accordingly

### License

- [x] I submit _my code changes_ under the same [MIT
License](https://github.com/openvinotoolkit/datumaro/blob/develop/LICENSE)
that covers the project.
  Feel free to contact the maintainers if that's a concern.
- [x] I have updated the license header for each file (see an example
below).

```python
# Copyright (C) 2023 Intel Corporation
#
# SPDX-License-Identifier: MIT
```

---------

Signed-off-by: Kim, Vinnam <vinnam.kim@intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BUG Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants