https://github.com/samet-akcay/ganomaly
Tip revision: 78da4ea9a99f5b02ab60dd651a18def929176d77 authored by Samet Akcay on 06 February 2022, 21:11:17 UTC
Update README.md
Update README.md
Tip revision: 78da4ea
loss.py
"""
Losses
"""
# pylint: disable=C0301,C0103,R0902,R0915,W0221,W0622
##
# LIBRARIES
import torch
##
def l1_loss(input, target):
""" L1 Loss without reduce flag.
Args:
input (FloatTensor): Input tensor
target (FloatTensor): Output tensor
Returns:
[FloatTensor]: L1 distance between input and output
"""
return torch.mean(torch.abs(input - target))
##
def l2_loss(input, target, size_average=True):
""" L2 Loss without reduce flag.
Args:
input (FloatTensor): Input tensor
target (FloatTensor): Output tensor
Returns:
[FloatTensor]: L2 distance between input and output
"""
if size_average:
return torch.mean(torch.pow((input-target), 2))
else:
return torch.pow((input-target), 2)