Repository navigation
Separate noise estimation from sample weight calculation - #253
jeipollack merged 15 commits into
Conversation
jeipollack
left a comment
There was a problem hiding this comment.
Thanks, Chai, for your work on this PR. You implemented all the right ingredients to arrive at the correct outcome. There is just a question of the reusability of estimate_noise_sigma() as a general image-analysis tool, since it is currently coupled to the training logic.
One general point I'd like to ask you to keep in mind for this and future tasks: when the implementation exposes something that doesn't fit the conceptual responsibility of the code you're adding, stop and consider whether the design should change. Then make an intentional decision about whether that change belongs in the current scope.
If the improvement is small and directly related to the task, it can be addressed in the current PR. If it's larger or more loosely related, it can be captured as a follow-up issue. If it's necessary to implement the task cleanly, then the refactoring should be done as part of the work, even if that means separating it into a prerequisite PR.
This is the strategy I've been applying in the Quality Control Pipeline Milestone, and I think it has been working well.
|
Thanks a lot @jeipollack for this thorough review! As suggested, I have moved all the NoiseEstimator utilities into a noise.py file, and added a separate estimate_noise_batch method. This method is now no longer depends on the loss or any training-specific elements. Thanks a lot for pointing this shortcoming in the original PR. I have also updated the tests for the updated parts, and the PR is now ready for a second review pass 🙏 |
|
Thanks @ChaitanyaChawak for the updates. Moving To start, I think the training-specific resolution of This would give calculate_sample_weights(
images,
masks=None,
apply_sigmoid=False,
sigmoid_max_val=5.0,
sigmoid_power_k=1.0,
)I also think Finally, I wonder whether the construction of img_dim = (outputs.shape[1], outputs.shape[2])
win_rad = np.ceil(outputs.shape[1] / 3.33)
std_est = NoiseEstimator(img_dim=img_dim, win_rad=win_rad)The window-radius calculation in particular feels like knowledge that belongs with Putting this all together, I think this would leave us with a clearer boundary: Hope that makes sense! And, apologies for the back and forth. Just know I have such exchanges with Rory, too! ;-) |
|
yess, I think that makes a lot of sense! I've updated the I have also moved the window radius calculation in Finally, as you correctly predicted, all these changes rendered I've also updated the relevant sections of the |
|
Hi @ChaitanyaChawak, thanks for your positivity in our series of iterations. I spotted only 1-2 small code items that I think could be cleaned up. And noted now that I don't see a changelog fragment for this PR. we're also adding batch noise-estimation functionality to One these are completed I would be happy to approve this PR and merge. |
|
@jeipollack : Done! |
|
Hi @ChaitanyaChawak, I looked over your latest commits, and left a couple of comments concerning the CHANGELOG and a unit test. |
|
@jeipollack thanks for the speedy review! I've made the changes acc to your suggestions 🙌 |
Summary
What’s changed
train_utils.estimate_noise_sigmamethod which returns the per-observation noise standard deviation.calculate_sample_weightsto callestimate_noise_sigmainternally._is_masked_losshelper to help simplifycalculate_sample_weightsmethod.How to test / verify
Scope
Changelog
Reviewer Checklist
develop, ormainfor release PRs)ruff)Next Steps / Notes (if applicable)