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

Cannot add in loss function when creating learner #631

Open
MilesTidmarsh opened this issue Jan 5, 2024 · 0 comments
Open

Cannot add in loss function when creating learner #631

MilesTidmarsh opened this issue Jan 5, 2024 · 0 comments

Comments

@MilesTidmarsh
Copy link

Issue

loss function added in when creating learner

learn = vision_learner(dls, resnet18, metrics=error_rate, loss_func = nn.CrossEntropyLoss(weight=tensor(2.,1.)))

learn.summary reveals no modified loss function in use

learn.summary()

Optimizer used: <function Adam at 0x79df4959c790>
Loss function: CrossEntropyLoss()

The workaround

loss function added in when creating learner

learn = vision_learner(dls, resnet18, metrics=error_rate, loss_func = nn.CrossEntropyLoss(weight=tensor(2.,1.)))

After learner is created I add in the loss function

learn.loss_func.func = nn.CrossEntropyLoss(weight=tensor(2.,1.))

summary reveals the function actually updated this time

learn.summary()

Optimizer used: <function Adam at 0x79df4959c790>
Loss function: CrossEntropyLoss(
(func): CrossEntropyLoss()
)

forum posts that reveal the same issue

https://forums.fast.ai/t/changing-default-loss-functions/28981

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

1 participant