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

2620 3595 Writer backend selector, deprecating nifti_saver/writer, png_saver/writer #3773

Merged
merged 11 commits into from
Feb 10, 2022

Conversation

wyli
Copy link
Contributor

@wyli wyli commented Feb 5, 2022

closes #3595
closes #2620

Description

this is to add a resolve_writer and register_writer,
update monai.transform.SaveImage to use the latest API.

Status

Ready

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • Breaking change (fix or new feature that would cause existing functionality to change).
  • New tests added to cover the changes.
  • Integration tests passed locally by running ./runtests.sh -f -u --net --coverage.
  • Quick tests passed locally by running ./runtests.sh --quick --unittests --disttests.
  • In-line docstrings updated.
  • Documentation updated, tested make html command in the docs/ folder.

@wyli wyli force-pushed the writer-backend-selector branch 2 times, most recently from c122c0e to a934a49 Compare February 7, 2022 16:02
@wyli wyli mentioned this pull request Feb 7, 2022
7 tasks
@wyli wyli force-pushed the writer-backend-selector branch from 88b00c0 to c4e23df Compare February 8, 2022 14:26
@wyli wyli changed the title 3595 Writer backend selector, deprecating nifti_saver/writer, png_saver/writer 2620 3595 Writer backend selector, deprecating nifti_saver/writer, png_saver/writer Feb 8, 2022
@wyli wyli marked this pull request as ready for review February 9, 2022 11:09
@wyli wyli requested review from Nic-Ma, rijobro and ericspod February 9, 2022 11:10
Copy link
Member

@ericspod ericspod left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@Nic-Ma
Copy link
Contributor

Nic-Ma commented Feb 9, 2022

Hi @wyli ,

Thanks for the quick update.
I will try to review this PR tomorrow morning.

Thanks.

@wyli
Copy link
Contributor Author

wyli commented Feb 9, 2022

/black

@wyli wyli mentioned this pull request Feb 9, 2022
@wyli wyli force-pushed the writer-backend-selector branch from a4df129 to d55e922 Compare February 10, 2022 10:36
wyli added 7 commits February 10, 2022 10:39
Signed-off-by: Wenqi Li <wenqil@nvidia.com>
Signed-off-by: Wenqi Li <wenqil@nvidia.com>
Signed-off-by: Wenqi Li <wenqil@nvidia.com>
Signed-off-by: Wenqi Li <wenqil@nvidia.com>
Signed-off-by: Wenqi Li <wenqil@nvidia.com>
Signed-off-by: Wenqi Li <wenqil@nvidia.com>
Signed-off-by: Wenqi Li <wenqil@nvidia.com>
@wyli wyli force-pushed the writer-backend-selector branch from 6b2e6d8 to f86ce2b Compare February 10, 2022 10:39
Signed-off-by: Wenqi Li <wenqil@nvidia.com>
monai/data/image_writer.py Outdated Show resolved Hide resolved
monai/data/image_writer.py Outdated Show resolved Hide resolved
fmt = f"{ext_name}".lower()
existing = look_up_option(fmt, SUPPORTED_WRITERS, default=())
all_writers = im_writer + existing
SUPPORTED_WRITERS[fmt] = all_writers
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @wyli ,

Here you use a global dictionary to store the supported format -> writers mapping, while in the image readers we store readers in LoadImage transform with its own supported formats, for example:
https://github.com/Project-MONAI/MONAI/blob/dev/monai/data/image_reader.py#L386

I am not very sure which way is better, the readers way is similar to the Chain of Responsibility design pattern, This global SUPPORTED_WRITERS may be not easy to maintain, especially in multi-threads cases, etc.
Maybe because I was Java / C++ developer before, I usually never use global variables even in python. I prefer to use class to implement complicated logic, because it can maintain self-contained local states. For example you implemented FolderLayout as a class instead of a function.
Glad to see your opinions.
@ericspod @rijobro What do you guys think?

Thanks in advance.

Copy link
Contributor Author

@wyli wyli Feb 10, 2022

Choose a reason for hiding this comment

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

SUPPORTED_WRITERS is a module-level variable, it's not a global one. it's a global dict accessed without global keyword.. I believe it's a
very common design, for example, scikit-image and PIL used it in a similar way

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, I am not sure whether it can work fine if calling SaveImage in multi-thread? I think all our non-random transforms are thread-safe now.

Thanks.

monai/data/image_writer.py Outdated Show resolved Hide resolved
monai/data/image_writer.py Outdated Show resolved Hide resolved
monai/data/image_writer.py Show resolved Hide resolved
monai/data/image_writer.py Outdated Show resolved Hide resolved
monai/data/image_writer.py Show resolved Hide resolved
monai/transforms/io/array.py Show resolved Hide resolved
monai/transforms/io/array.py Outdated Show resolved Hide resolved
@Nic-Ma
Copy link
Contributor

Nic-Ma commented Feb 10, 2022

Hi @wyli ,

Thanks for the quick implementation, put some comments inline, I will review the unit tests later.

Thanks.

tests/min_tests.py Outdated Show resolved Hide resolved
Signed-off-by: Wenqi Li <wenqil@nvidia.com>
@wyli wyli force-pushed the writer-backend-selector branch from 67826e8 to 01853a6 Compare February 10, 2022 18:14
@wyli
Copy link
Contributor Author

wyli commented Feb 10, 2022

/integration-test
/black

@wyli
Copy link
Contributor Author

wyli commented Feb 10, 2022

/build

Signed-off-by: Wenqi Li <wenqil@nvidia.com>
@wyli
Copy link
Contributor Author

wyli commented Feb 10, 2022

/build

Signed-off-by: Wenqi Li <wenqil@nvidia.com>
@wyli wyli force-pushed the writer-backend-selector branch from 696c77e to 0152543 Compare February 10, 2022 22:36
@wyli
Copy link
Contributor Author

wyli commented Feb 10, 2022

/build

@wyli wyli enabled auto-merge (squash) February 10, 2022 22:39
@wyli wyli merged commit 127e823 into Project-MONAI:dev Feb 10, 2022
@wyli wyli deleted the writer-backend-selector branch April 27, 2022 22:35
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.

refactoring the image writer modules Image writer with itk backend to support more output image formats
3 participants