Skip to content

Instantly share code, notes, and snippets.

View koshian2's full-sized avatar

こしあん koshian2

View GitHub Profile
@koshian2
koshian2 / kl.py
Created June 19, 2023 19:54 — forked from atabakd/kl.py
KL divergence for multivariate samples
# https://mail.python.org/pipermail/scipy-user/2011-May/029521.html
import numpy as np
def KLdivergence(x, y):
"""Compute the Kullback-Leibler divergence between two multivariate samples.
Parameters
----------
x : 2D array (n,d)
@koshian2
koshian2 / train.py
Last active May 15, 2022 13:12
PyTorch lightning CSVLogger
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.utils.data import DataLoader
import torchvision
import torchmetrics
import pytorch_lightning as pl
class TenLayersModel(pl.LightningModule):
def __init__(self):
@koshian2
koshian2 / res50_lightning.py
Created March 7, 2022 15:13
ResNet50 CIFAR
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.utils.data import DataLoader
import torchvision
import torchmetrics
import pytorch_lightning as pl
import time
class ResNet50(pl.LightningModule):
@koshian2
koshian2 / anko.txt
Created October 6, 2020 05:26
あんこ一覧
こしあん
つぶあん
しろあん
ごまあん
うぐいすあん
栗あん

第1章 タイトル

1.1 見出し1

ああああ

ここに本文が入る

# コメント
print("ほげほげ")
## コメント2
print("ふがふが")
import tensorflow as tf
from tensorflow.keras import backend as K
import tensorflow.keras.layers as layers
# https://github.com/IShengFang/SpectralNormalizationKeras/blob/master/SpectralNormalizationKeras.py
class ConvSN2D(layers.Conv2D):
def build(self, input_shape):
if self.data_format == 'channels_first':
channel_axis = 1
else:
@koshian2
koshian2 / compute_gradients.py
Created September 16, 2019 07:19
Normalization vs gradients
import torch
import torchvision
from models import TenLayersModel, ResNetLikeModel
from torchvision import transforms
from tqdm import tqdm
import numpy as np
import os
import pickle
def load_cifar():
@koshian2
koshian2 / models.py
Created August 19, 2019 09:04
ACGAN(5) AnimeFace, 10, resnet
import torch
from torch import nn
import torch.nn.functional as F
class ResidualBlock(nn.Module):
def __init__(self, ch):
super().__init__()
self.conv1 = self.conv_bn_relu(ch)
self.conv2 = self.conv_bn_relu(ch)
@koshian2
koshian2 / models.py
Created August 19, 2019 08:51
ACGAN(4) AnimeFace, 10, original
import torch
from torch import nn
import torch.nn.functional as F
class Generator(nn.Module):
def __init__(self, n_classes):
super().__init__()
self.linear = nn.Sequential(
nn.Linear(100 + n_classes, 768),
nn.ReLU(True)
@koshian2
koshian2 / models.py
Created August 19, 2019 08:48
ACGAN(3) AnimeFace, full, resnet
import torch
from torch import nn
import torch.nn.functional as F
class ResidualBlock(nn.Module):
def __init__(self, ch):
super().__init__()
self.conv1 = self.conv_bn_relu(ch)
self.conv2 = self.conv_bn_relu(ch)