im trying to implement my loss function but having a problem. i tried to implement many different variable types such as long/float/int for ‘‘int’ object is not callable’’ . i cant understand where the problem is caused
It is not about data types you are using, I think it’s just a typo. Somewhere else in your code you are using dice_loss but it is no longer referring to Dice_Loss class.
Error says dice_loss should be an instance of Dice_Loss is a int.
It is pretty simple to find errors like this, just run your code in debug mode and add dice_loss to watch and check its type after dice_loss = Dice_Loss.apply or Dice_Loss()
Maybe I am missing something but for sure your loss class is correct (at least in case of your error) and another point is that you have syntax error in your class, view does not support dtype. So, if you pass anything to dice_loss then you should get error in the first line or even in a simpler scenario, if you pass nothing to dice_loss like:
loss = dice_loss()
you should get missing argument error but you are not getting it because somehow somewhere you are changing dice_loss.
i directly used Dice_Loss function in traning process but now that Dice_Loss object has no attribute backward. That is true but should i use backward method in new version of pytorch ? (i have seen a few comments without backward method ) i can’t find example about this method . Do you have an example about custom loss function backward method ?
Frankly I do not see any errors with the lines you have shared. I just ran your first post and it works. Do you want to create a notebook on google colab with a toy example and share the link so I can take a deeper look?