Skip to content

Instantly share code, notes, and snippets.

View alex-vasilchenko-md's full-sized avatar

alex-vasilchenko-md

View GitHub Profile
@alex-vasilchenko-md
alex-vasilchenko-md / weighted_sum_composition_loss.py
Last active June 20, 2022 17:15
A little composition wrapper for Pytorch loss functions. It calculates weighted sum of multiple loss functions.
from collections.abc import Collection
from torch import nn
class WeightedSumCompositionLoss(nn.Module):
def __init__(self, loss_funcs: Collection, weights: Collection):
super().__init__()
self.loss_funcs = loss_funcs
self.weights = weights
@alex-vasilchenko-md
alex-vasilchenko-md / vgg_perceptual_loss.py
Last active April 11, 2024 23:36 — forked from alper111/vgg_perceptual_loss.py
PyTorch implementation of VGG perceptual loss
import torch
from torch import nn
import torchvision
class VGGPerceptualLoss(nn.Module):
DEFAULT_FEATURE_LAYERS = [0, 1, 2, 3]
IMAGENET_RESIZE = (224, 224)
IMAGENET_MEAN = [0.485, 0.456, 0.406]
IMAGENET_STD = [0.229, 0.224, 0.225]