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

adding additional hyperparameters #2625

Open
komiloserdov opened this issue Nov 28, 2024 · 2 comments
Open

adding additional hyperparameters #2625

komiloserdov opened this issue Nov 28, 2024 · 2 comments
Assignees

Comments

@komiloserdov
Copy link

komiloserdov commented Nov 28, 2024

Hi,

I want to play around with additional loss functions which introduce additional hyperparameters (e.g. Focal Loss). I tried to figure out a (relatively) simple way to add those without changing the source code but in the end didn't find a way that satisfied me.

Is there a way to easily add additional hyperparameters which are also included in experiment planning or at least can be incorporated into the Plansmanager? From my perspective, I'd need to introduce a new Experiment Planner, but also edit the Plans- or Configuration Manager for the changes to properly flow through all the processes - which would require a lot of changes for "just" a hyperparameter or two.

Am I missing something or is this simply not supported by nnUNet?

Thanks a lot and all the best,
Konstantin

@ykirchhoff
Copy link
Member

Hi @komiloserdov,

if you want to add another loss function you will need to touch the source code, except for some losses, which are included in nnUNet already. You can find existing trainers with some other loss functions here.
Focal loss is not implemented in nnUNet so far, but if I find the time I can try to put it into the repo, I have a nnUNet specific implementation laying around somewhere, which would however need to be cleaned a bit.
We can maybe include space for loss hyperparameter somehow in the plans, so you can change those without fiddling around with the source code, but I guess that only makes sense if we have more than one or two loss functions in there, which actually require hyperparameters (even focal loss with gamma=2 works fine most of the time).
I will discuss that with Fabi but this will very likely not have high priority for now.

Best,
Yannick

@komiloserdov
Copy link
Author

Hi @ykirchhoff,

I managed to resolve the issue by adding some hyperparameters to the Configuration Manager. For example:

@property
def alpha(self) -> float:
    return self.configuration['alpha'] if 'alpha' in self.configuration.keys() else None

Could this approach be generalized by introducing a dictionary for hyperparameters? For example:

@property
def hyperparams(self) -> dict:
    return self.configuration['hyperparams'] if 'hyperparams' in self.configuration.keys() else None

Here, hyperparams would be defined as a dictionary in the plans file. This approach seems quite flexible for accommodating any hyperparameter changes or additions, and it would require minimal implementation effort.

Anyways, thanks for the update!

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

No branches or pull requests

2 participants