Skip to content

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

Merged
wyli merged 11 commits intoProject-MONAI:devfrom
wyli:writer-backend-selector
Feb 10, 2022
Merged

2620 3595 Writer backend selector, deprecating nifti_saver/writer, png_saver/writer#3773
wyli merged 11 commits intoProject-MONAI:devfrom
wyli:writer-backend-selector

Conversation

@wyli
Copy link
Copy Markdown
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, ericspod and rijobro February 9, 2022 11:10
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 <[email protected]>
Signed-off-by: Wenqi Li <[email protected]>
Signed-off-by: Wenqi Li <[email protected]>
Signed-off-by: Wenqi Li <[email protected]>
@wyli wyli force-pushed the writer-backend-selector branch from 6b2e6d8 to f86ce2b Compare February 10, 2022 10:39
Signed-off-by: Wenqi Li <[email protected]>
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
Copy Markdown
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
Copy Markdown
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.

Copy link
Copy Markdown
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.

@Nic-Ma
Copy link
Copy Markdown
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.

@wyli wyli force-pushed the writer-backend-selector branch from 67826e8 to 01853a6 Compare February 10, 2022 18:14
@wyli
Copy link
Copy Markdown
Contributor Author

wyli commented Feb 10, 2022

/integration-test
/black

@wyli
Copy link
Copy Markdown
Contributor Author

wyli commented Feb 10, 2022

/build

Signed-off-by: Wenqi Li <[email protected]>
@wyli
Copy link
Copy Markdown
Contributor Author

wyli commented Feb 10, 2022

/build

Signed-off-by: Wenqi Li <[email protected]>
@wyli wyli force-pushed the writer-backend-selector branch from 696c77e to 0152543 Compare February 10, 2022 22:36
@wyli
Copy link
Copy Markdown
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