Skip to content

Instantly share code, notes, and snippets.

@level14taken
Created December 29, 2020 10:08
Show Gist options
  • Save level14taken/f32fbbcfebb67eb5c6c5ba19626068e2 to your computer and use it in GitHub Desktop.
Save level14taken/f32fbbcfebb67eb5c6c5ba19626068e2 to your computer and use it in GitHub Desktop.
def get_losslv_simple(model,inp):
no_mask,final=model(inp[0])
final=final*inp[-1].view(-1,1,1,1)
mfl=nn.BCEWithLogitsLoss()
lv=LovaszLoss()
weights=[.1/2.1,2/2.1]
loss=[mfl(no_mask.view(-1,1,1,1),inp[-1].view(-1,1,1,1)),lv(final,inp[1])]
accuracy=acc(no_mask.reshape(-1),inp[-1],center=True)/len(inp[-1])
loss=sum(x_i*y_i for x_i, y_i in zip(weights, loss))
return loss,accuracy,final
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment