Skip to content

Instantly share code, notes, and snippets.

Avatar

Kim Seonghyeon rosinality

View GitHub Profile
@rosinality
rosinality / perceptual_loss.py
Created Feb 7, 2020
Perceptual loss implementation sample
View perceptual_loss.py
import torch
from torch import nn
from torchvision.models import vgg16, vgg16_bn, vgg19, vgg19_bn
class PerceptualLoss(nn.Module):
def __init__(self, arch, indices, weights, normalize=True, min_max=(-1, 1)):
super().__init__()
vgg = (
@rosinality
rosinality / perceptual_loss.py
Created Feb 7, 2020
Perceptual loss implementation sample
View perceptual_loss.py
import torch
from torch import nn
from torchvision.models import vgg16, vgg16_bn, vgg19, vgg19_bn
class PerceptualLoss(nn.Module):
def __init__(self, arch, indices, weights, normalize=True, min_max=(-1, 1)):
super().__init__()
vgg = (
@rosinality
rosinality / discriminator_example.py
Created Dec 9, 2017
Implementation of Spectral Normalization for PyTorch
View discriminator_example.py
from torch import nn
from torch.nn import init
from torch.nn import functional as F
def init_conv(conv, glu=True):
init.kaiming_normal(conv.weight)
if conv.bias is not None:
conv.bias.data.zero_()
class ConvBlock(nn.Module):
@rosinality
rosinality / mhsampler-in-pytorch.ipynb
Created Apr 15, 2017
Metropolis-Hastings sampler in PyTorch. Made to explore possibility of bayesian computation in PyTorch.
View mhsampler-in-pytorch.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rosinality
rosinality / logtest.py
Last active Apr 8, 2017
Simple live log plotting tool for Visdom
View logtest.py
from vislog import Logger
from time import sleep
import numpy as np
import shutil
log = Logger('test')
brown1 = log.line('brown1')
brown2 = log.line('brown2')
image1 = log.image('image1')
@rosinality
rosinality / adasoft.py
Last active Jul 21, 2021
Adaptive Softmax implementation for PyTorch
View adasoft.py
import torch
from torch import nn
from torch.autograd import Variable
class AdaptiveSoftmax(nn.Module):
def __init__(self, input_size, cutoff):
super().__init__()
self.input_size = input_size
self.cutoff = cutoff
@rosinality
rosinality / mathology.html
Created Jan 23, 2015
Very simple latex sketchpad
View mathology.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Mathology</title>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
}