Skip to content

Instantly share code, notes, and snippets.

@rosinality
rosinality / mathology.html
Created January 23, 2015 07:34
Very simple latex sketchpad
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Mathology</title>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
}
@rosinality
rosinality / adasoft.py
Last active July 21, 2021 03:42
Adaptive Softmax implementation for PyTorch
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 / logtest.py
Last active April 8, 2017 14:22
Simple live log plotting tool for Visdom
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 / mhsampler-in-pytorch.ipynb
Created April 15, 2017 02:40
Metropolis-Hastings sampler in PyTorch. Made to explore possibility of bayesian computation in PyTorch.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rosinality
rosinality / discriminator_example.py
Created December 9, 2017 15:37
Implementation of Spectral Normalization for PyTorch
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 / perceptual_loss.py
Created February 7, 2020 13:08
Perceptual loss implementation sample
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 February 7, 2020 13:08
Perceptual loss implementation sample
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 = (