Skip to content

Instantly share code, notes, and snippets.

Avatar

Takuya Tsunogawa nogawanogawa

View GitHub Profile
View simpleGAN_tensorflow.py
import tensorflow as tf
import numpy as np
import os
import matplotlib.pyplot as plt
from tensorflow.examples.tutorials.mnist import input_data
from init import xavier_init
from img_gen import plot
View simple_CGAN.py
import numpy
import math
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
import matplotlib.pyplot as plt
import os
import numpy as np
from img_gen import plot
View DCGAN_tensorflow.py
from __future__ import division
import os
import numpy as np
import tensorflow as tf
import time
import math
import matplotlib.pyplot as plt
from tensorflow.examples.tutorials.mnist import input_data
from glob import glob
from six.moves import xrange
View read_CIFAR-10.py
def unpickle(f):
fo = open(f, 'rb')
d = cPickle.load(fo, encoding='latin1')
fo.close()
return d
View write_CIFAR-10.py
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
# 縦横10枚ずつ画像を描画
def plot(samples):
fig = plt.figure(figsize=(10, 10))
gs = gridspec.GridSpec(10, 10)
gs.update(wspace=0.05, hspace=0.05)
for i, sample in enumerate(samples):
View BEGAN_model.py
from layer.layers import *
from ops.operators import *
class began(Operator): # Operatorを継承
# initialize
def __init__(self, sess):
self.sess = sess
View BEGAN_trainer.py
import sys, os
import glob
import time
import datetime
import numpy as np
import scipy.misc as scm
from function.img_read import *
from function.img_gen import *
from PIL import Image
View cyclegan_loss.py
def loss_calc(self):
# Cycle Consistency Loss
cyc_loss = tf.reduce_mean(tf.abs(self.x-self.cyc_x)) + tf.reduce_mean(tf.abs(self.y-self.cyc_y))
# Adversarial Loss
# Discriminatorのloss(偽物を偽物と見分ける)
disc_loss_x = tf.reduce_mean(tf.squared_difference(self.fake_rec_x,1))
disc_loss_y = tf.reduce_mean(tf.squared_difference(self.fake_rec_y,1))
View cyclegan_gen.py
# Generator
def generator(inputgen, name="generator", reuse=None):
if reuse:
scope.reuse_variables()
with tf.variable_scope(name):
f = 7
ks = 3
pad_input = tf.pad(inputgen,[[0, 0], [ks, ks], [ks, ks], [0, 0]], "REFLECT")
View cyclegan_disc.py
# Discriminator
def discriminator(inputdisc, name="discriminator", reuse=None):
if reuse:
scope.reuse_variables()
with tf.variable_scope(name):
f = 4
x = conv2d(inputdisc, ndf, f, f, 2, 2, 0.02, "SAME", "c1", do_norm=False, relufactor=0.2)
x = conv2d(x, ndf*2, f, f, 2, 2, 0.02, "SAME", "c2", relufactor=0.2)