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

Add NDR #113

Merged
merged 11 commits into from
Feb 26, 2021
Merged

Add NDR #113

merged 11 commits into from
Feb 26, 2021

Conversation

byeongkyu-kang
Copy link
Contributor

@byeongkyu-kang byeongkyu-kang commented Feb 19, 2021

Summary

Added NDR to remove duplicated images in a dataset.

How to test

python -m unittest -v tests/test_ndr.py

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

Copy link
Contributor

@zhiltsov-max zhiltsov-max left a comment

Choose a reason for hiding this comment

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

Hi, thanks for your contribution!
Please fix formatting - avoid lines longer than 80 characters.

CHANGELOG.md Outdated
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `Icdar13/15` dataset format (<https://github.com/openvinotoolkit/datumaro/pull/96>)
- Laziness, source caching, tracking of changes and partial updating for `Dataset` (<https://github.com/openvinotoolkit/datumaro/pull/102>)
- `Market-1501` dataset format (<https://github.com/openvinotoolkit/datumaro/pull/108>)
- Add NDR (<https://github.com/openvinotoolkit/datumaro/pull/113>)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use the full form here instead of abbreviation to make it more clear for readers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I will update.

def __init__(self, extractor, working_subset=None, duplicated_subset="duplicated", algorithm='gradient',
num_cut=None, over_sample='random', under_sample='uniform', seed=None, **kwargs):
"""
Near-duplicated image removal
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi, please include a couple of examples in the class doc and maybe some explanation for the CLI parameters, if this function is supposed to be used from CLI. An example can be found here: https://github.com/openvinotoolkit/datumaro/blob/develop/datumaro/plugins/transforms.py#L313

Copy link
Contributor Author

@byeongkyu-kang byeongkyu-kang Feb 25, 2021

Choose a reason for hiding this comment

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

I planned to support CLI by inheriting CliPlugin in another PR. Do I need to write a documentation anyway?

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add it in another PR then.


Arguments
---------------
working_subset: str
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if using a parameter is better than passing just a subset as an input. Also, I think, it looks more natural, when None run the algorithm for the whole dataset.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that might return unexpected results if user has a subset like val or test.

raise ValueError("Invalid under_sample")

self.duplicated_subset = duplicated_subset
self._remove(algorithm, working_subset, num_cut, over_sample, under_sample, **kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

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

Try to make the transform lazy - it should only be applied when __iter__ is called, look at "splitter" transforms for example. You'll also need to move the initialization of RNG into __iter__. Consider __iter__ in the input dataset a heavy operation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I will check "splitter" and change to lazy transformation

super().__init__(extractor)
if seed:
np.random.seed(seed)
if len(extractor) < 1:
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this situation should be considered an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I will update

if num_cut and num_cut > len(all_imgs):
raise ValueError("The number of images is smaller than the cut you want")

if algorithm == "gradient":
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using an enum instead of a string constant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you explain more about enum?

class Algo_name(Enum):
    algo_name1 = "..."
    ....

...
if algorithm == Algo_name.algo_name1

Do you mean creating a class by inheriting Enum like above?

Copy link
Contributor

Choose a reason for hiding this comment

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

continue

# Hash collision: compare dot-product based feature similarity
max_sim = np.max(np.dot(clr_dict[key], clr) ** 50)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please make the use of 50 more clear. It is unclear if it is just a random number, or something with a strong mathematical proof.

Copy link
Contributor Author

@byeongkyu-kang byeongkyu-kang Feb 25, 2021

Choose a reason for hiding this comment

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

We do not have any experimental results for that number. The number is for maximizing the gap between duplicated-images and non-duplicated-images and is set arbitrarily. Then do we need to change it as a parameter?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have any complaints against the value, but I'd better make it a named constant to clarify its use.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I understand. Okay, I will update

@zhiltsov-max zhiltsov-max merged commit 88d7df9 into develop Feb 26, 2021
@zhiltsov-max zhiltsov-max deleted the bk/initial-ndr branch February 26, 2021 17:59
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.

2 participants