Skip to content

Instantly share code, notes, and snippets.

View koshian2's full-sized avatar

こしあん koshian2

View GitHub Profile
@koshian2
koshian2 / vae.py
Created September 13, 2018 17:59
Simple Variational Auto Encoder in PyTorch : MNIST, Fashion-MNIST, CIFAR-10, STL-10 (by Google Colab)
import torch
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as F
import torchvision
import torchvision.transforms as transforms
from torchvision.utils import save_image
from torchvision.datasets import MNIST, FashionMNIST, CIFAR10, STL10
import os
import pickle
@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 / CIFAR10_10Layers.py
Created July 31, 2018 13:19
Achieved 90% CIFAR-10 validation accuracy with 10-layers CNN
import matplotlib.pyplot as plt
import pickle
from keras.layers import Input, Conv2D, Activation, MaxPool2D, BatchNormalization, Flatten, Dense, Dropout
from keras.models import Model
from keras.optimizers import Adam
from keras.utils import to_categorical
from keras.datasets import cifar10
from keras.preprocessing.image import ImageDataGenerator
(X_train, y_train), (X_val, y_val) = cifar10.load_data()
@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 / unet_ae_keras.py
Created November 9, 2018 20:34
U-Net Keras
import tensorflow as tf
from tensorflow.keras.layers import Conv2D, BatchNormalization, Activation, Input, Concatenate, MaxPool2D, Conv2DTranspose, Add
from tensorflow.keras.models import Model
from tensorflow.keras.callbacks import Callback, History
import tensorflow.keras.backend as K
from keras.objectives import mean_squared_error
import os, tarfile, shutil, pickle
from PIL import Image
@koshian2
koshian2 / ex1.py
Created May 8, 2018 15:42
Coursera Machine LearningをPythonで実装 - [Week2]単回帰分析、重回帰分析 (1)単回帰分析
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
# 単回帰分析 #
# データ
X = np.array([6.1101,5.5277,8.5186,7.0032,5.8598,8.3829,7.4764,8.5781,6.4862,5.0546,5.7107,14.164,5.734,8.4084,5.6407,5.3794,6.3654,5.1301,6.4296,7.0708,6.1891,20.27,5.4901,6.3261,5.5649,18.945,12.828,10.957,13.176,22.203,5.2524,6.5894,9.2482,5.8918,8.2111,7.9334,8.0959,5.6063,12.836,6.3534,5.4069,6.8825,11.708,5.7737,7.8247,7.0931,5.0702,5.8014,11.7,5.5416,7.5402,5.3077,7.4239,7.6031,6.3328,6.3589,6.2742,5.6397,9.3102,9.4536,8.8254,5.1793,21.279,14.908,18.959,7.2182,8.2951,10.236,5.4994,20.341,10.136,7.3345,6.0062,7.2259,5.0269,6.5479,7.5386,5.0365,10.274,5.1077,5.7292,5.1884,6.3557,9.7687,6.5159,8.5172,9.1802,6.002,5.5204,5.0594,5.7077,7.6366,5.8707,5.3054,8.2934,13.394,5.4369])
@koshian2
koshian2 / optuna_cifar_keras.py
Created December 7, 2018 16:26
Optuna Keras
import tensorflow as tf
from tensorflow.keras.applications import InceptionV3, VGG16, MobileNet
from tensorflow.keras.layers import GlobalAveragePooling2D, Dense
from tensorflow.keras.models import Model
from tensorflow.keras.callbacks import History, Callback
import tensorflow.keras.backend as K
from tensorflow.contrib.tpu.python.tpu import keras_support
from keras.utils import to_categorical
from keras.datasets import cifar10
@koshian2
koshian2 / rgb_rgb.py
Created June 27, 2019 09:11
Pix2pix STL Colorize
import torch
from torch import nn
import torchvision
import torchvision.transforms as transforms
import numpy as np
from tqdm import tqdm
import os
import pickle
import statistics
@koshian2
koshian2 / gpu_tpu_1.py
Created May 14, 2019 00:05
GPU vs TPU 1
import tensorflow as tf
import tensorflow.python.keras as keras
import tensorflow.python.keras.layers as layers
from tensorflow.contrib.tpu.python.tpu import keras_support
import datetime
import time
import pickle
import os
def conv_bn_relu(input, ch, reps):