Open MilesTidmarsh opened 10 months ago
Issue
learn = vision_learner(dls, resnet18, metrics=error_rate, loss_func = nn.CrossEntropyLoss(weight=tensor(2.,1.)))
learn.summary()
Optimizer used: <function Adam at 0x79df4959c790> Loss function: CrossEntropyLoss()
The workaround
learn.loss_func.func = nn.CrossEntropyLoss(weight=tensor(2.,1.))
Optimizer used: <function Adam at 0x79df4959c790> Loss function: CrossEntropyLoss( (func): CrossEntropyLoss() )
https://forums.fast.ai/t/changing-default-loss-functions/28981
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