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 norm param to ResNet #7752

Merged
merged 8 commits into from
May 23, 2024
Merged

Conversation

Pkaps25
Copy link
Contributor

@Pkaps25 Pkaps25 commented May 9, 2024

Fixes #7294 .

Description

Adds a norm param to ResNet

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.

@ericspod
Copy link
Member

Hi @Pkaps25 thanks for this, is it ready to review? We should add at least one test for the new argument in Daf3D however.

@Pkaps25
Copy link
Contributor Author

Pkaps25 commented May 13, 2024

Hi @Pkaps25 thanks for this, is it ready to review? We should add at least one test for the new argument in Daf3D however.

Daf3D doesn't currently have a norm parameter and it looks like adding that in might be tricky since certain parts of the network expect group norm and others use ResNet's batch norm. I'd like to avoid adding that param in this PR, so short of that, would the existing tests cover my change?

Peter Kaplinsky added 6 commits May 13, 2024 16:09
Signed-off-by: Peter Kaplinsky <peterkaplinsky@gmail.com>
Signed-off-by: Peter Kaplinsky <peterkaplinsky@gmail.com>
Signed-off-by: Peter Kaplinsky <peterkaplinsky@gmail.com>
Signed-off-by: Peter Kaplinsky <peterkaplinsky@gmail.com>
Signed-off-by: Peter Kaplinsky <peterkaplinsky@gmail.com>
@Pkaps25 Pkaps25 force-pushed the 7294-resnet-norm branch from 3a63960 to a5fd655 Compare May 13, 2024 20:09
I, Peter Kaplinsky <peterkaplinsky@gmail.com>, hereby add my Signed-off-by to this commit: 335ab0f

Signed-off-by: Peter Kaplinsky <peterkaplinsky@gmail.com>
@KumoLiu
Copy link
Contributor

KumoLiu commented May 15, 2024

Hi @Pkaps25, after we discussed from the dev meeting.
One thing I overlooked in this PR is whether the change of the name of act will affect the weights loading of the original model, can you help check that, if so, maybe we need to revert the name change for the variable and add an alias.

Thanks!

@Pkaps25
Copy link
Contributor Author

Pkaps25 commented May 15, 2024 via email

@Pkaps25
Copy link
Contributor Author

Pkaps25 commented May 15, 2024

Hi @Pkaps25, after we discussed from the dev meeting. One thing I overlooked in this PR is whether the change of the name of act will affect the weights loading of the original model, can you help check that, if so, maybe we need to revert the name change for the variable and add an alias.

Thanks!

Hi @KumoLiu, I trained ResNet with latest MONAI and loaded the model state using my branch. The model loaded successfully, had the same layers, and a forward pass with a random input produced the same result on both branches. Let me know if that's a sufficient check and if we need to add tests for this compatibility in the future

@KumoLiu
Copy link
Contributor

KumoLiu commented May 16, 2024

Hi @Pkaps25, after we discussed from the dev meeting. One thing I overlooked in this PR is whether the change of the name of act will affect the weights loading of the original model, can you help check that, if so, maybe we need to revert the name change for the variable and add an alias.
Thanks!

Hi @KumoLiu, I trained ResNet with latest MONAI and loaded the model state using my branch. The model loaded successfully, had the same layers, and a forward pass with a random input produced the same result on both branches. Let me know if that's a sufficient check and if we need to add tests for this compatibility in the future

Thanks to the quick verification, and make sense it works since the activation function usually has no parameters to learn in the neural network. I guess we don't need to add a test for this. But if the norm layer name changed, it should be worth to add the test. What do you think? cc @ericspod

@Pkaps25
Copy link
Contributor Author

Pkaps25 commented May 16, 2024

Hi @Pkaps25, after we discussed from the dev meeting. One thing I overlooked in this PR is whether the change of the name of act will affect the weights loading of the original model, can you help check that, if so, maybe we need to revert the name change for the variable and add an alias.
Thanks!

Hi @KumoLiu, I trained ResNet with latest MONAI and loaded the model state using my branch. The model loaded successfully, had the same layers, and a forward pass with a random input produced the same result on both branches. Let me know if that's a sufficient check and if we need to add tests for this compatibility in the future

Thanks to the quick verification, and make sense it works since the activation function usually has no parameters to learn in the neural network. I guess we don't need to add a test for this. But if the norm layer name changed, it should be worth to add the test. What do you think? cc @ericspod

Agreed that if the name changes we should add that test, but I don't change the name in this PR.

@Pkaps25 Pkaps25 marked this pull request as ready for review May 17, 2024 18:44
Copy link
Contributor

@KumoLiu KumoLiu left a comment

Choose a reason for hiding this comment

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

The norm type added in ResNet look good to me. But have a concern regarding the norm layer added in daf3d added inline. Thanks!

monai/networks/nets/daf3d.py Show resolved Hide resolved
@ericspod
Copy link
Member

Thanks to the quick verification, and make sense it works since the activation function usually has no parameters to learn in the neural network. I guess we don't need to add a test for this. But if the norm layer name changed, it should be worth to add the test. What do you think? cc @ericspod

This looks good then, I thought that a layer with no parameters wouldn't show up in the state dict but it's best to double check.

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.

i think things are fine if all comments are addressed.

monai/networks/nets/daf3d.py Show resolved Hide resolved
@KumoLiu
Copy link
Contributor

KumoLiu commented May 22, 2024

/build

1 similar comment
@KumoLiu
Copy link
Contributor

KumoLiu commented May 23, 2024

/build

@KumoLiu KumoLiu merged commit 373c003 into Project-MONAI:dev May 23, 2024
28 checks passed
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.

Implement the ability to use layernorm with resnet models
3 participants