コード例 #1
0
from torch import optim as tOpt
from keras_callbacks import ProgressBarCallback as bar
import imageio

PHRASE = "TRAIN"

DIMENSION = 2

iterations = 3000
cuda = False
bs = 2000
z_dim = 2
input_path = "inputs/Z.jpg"

density_img = io.imread(input_path, True)
lut_2d = sampler.generate_lut(density_img)

visualizer = visualizer.GANDemoVisualizer(
    'GAN 2D Example Visualization of {}'.format(input_path))

if PHRASE == "TRAIN":

    class SimpleMLP(nn.Module):
        def __init__(self, input_size, hidden_size, output_size):
            super(SimpleMLP, self).__init__()
            self.map1 = nn.Linear(input_size, hidden_size)
            self.map2 = nn.Linear(hidden_size, output_size)

        def forward(self, x):
            x = F.leaky_relu(self.map1(x), 0.1)
            return F.sigmoid(self.map2(x))
コード例 #2
0
from keras_commons import sampler as sampler
from keras_commons import visualize as visualizer
import torch.nn.functional as F
from torch import optim as tOpts
from keras_callbacks import ProgressBarCallback as bar
import imageio
PHRASE = "TRAIN"
DIMENSION = 2
cuda = False
bs = 2000
iterations = 3000
z_dim = 2
input_path = "inputs/binary"
image_paths = [os.sep.join([input_path, x]) for x in os.listdir(input_path)]
density_imgs = [io.imread(x, True) for x in image_paths]
luts_2d = [sampler.generate_lut(x) for x in density_imgs]
# Sampling based on visual density, a too small batch size may result in failure with conditions
pix_sums = [numpy.sum(x) for x in density_imgs]
total_pix_sums = numpy.sum(pix_sums)
c_indices = [0] + [
    int(sum(pix_sums[:i + 1]) / total_pix_sums * bs + 0.5)
    for i in range(len(pix_sums) - 1)
] + [bs]
c_dim = len(luts_2d)
visualizer = visualizer.CGANDemoVisualizer(
    'Conditional GAN 2D Example Visualization of {}'.format(input_path))

if PHRASE == "TRAIN":

    class SimpleMLP(nn.Module):
        def __init__(self, input_size, hidden_size, output_size):