Exemplo n.º 1
0
                        help='batch size')
    parser.add_argument('--load_from',
                        type=str,
                        default=None,
                        help='directory to load from')
    parser.add_argument('--loss',
                        type=str,
                        default='ls',
                        help='loss function: bce or ls')
    parser.add_argument('--mode',
                        type=str,
                        default='train',
                        help='mode train or evaluate')

    args = parser.parse_args()
    lr = args.lr
    noise_dim = args.noise_dim
    base_dim = args.base_dim
    loss = args.loss

    opt = VanillaGANOptimizer()
    runner = TrainingRunner('dcgan',
                            create_dogs_dataset(),
                            dogs.Generator(base_dim=base_dim,
                                           noise_dim=noise_dim),
                            dogs.Discriminator(base_dim=base_dim),
                            VanillaGANOptimizer(dsc_lr=lr,
                                                gen_lr=lr,
                                                loss=loss),
                            args=args)
    runner.execute(args)
Exemplo n.º 2
0
   Copyright 2018 JetBrains, s.r.o
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at
       http://www.apache.org/licenses/LICENSE-2.0
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
"""

from dogsgan.data.dogs import create_dogs_dataset
from dogsgan.training.optimizers import VanillaGANOptimizer
from dogsgan.training.runner import TrainingRunner

import dogsgan.models.dogs as dogs

if __name__ == '__main__':
    lr = 2e-4
    noise_dim = 1024

    for base_dim in [16, 32, 64, 96, 128, 160, 196, 256, 320]:
        opt = VanillaGANOptimizer()
        runner = TrainingRunner(
            f'dcgan-{base_dim}', create_dogs_dataset(),
            dogs.Generator(base_dim=base_dim, noise_dim=noise_dim),
            dogs.Discriminator(base_dim=base_dim),
            VanillaGANOptimizer(dsc_lr=lr, gen_lr=lr))

        runner.train(epochs=100)
Exemplo n.º 3
0
import argparse

from dogsgan.data.dogs import create_dogs_dataset
from dogsgan.training.optimizers import WGANGPOptimizer
from dogsgan.training.runner import TrainingRunner

import dogsgan.models.dogs as dogs


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='run dcgan training')
    parser.add_argument('--lr', type=float, default=1e-4 ,help='learning rate')
    parser.add_argument('--l', type=float, default=10.0, help='gradient penalty coefficent')
    parser.add_argument('--noise_dim', type=int, default=1024, help='noise dimension')
    parser.add_argument('--base_dim', type=int, default=128, help='base dimension')
    parser.add_argument('--batch_size', type=int, default=64, help='batch size')
    parser.add_argument('--load_from', type=str, default=None, help='directory to load from')
    parser.add_argument('--mode', type=str, default='train', help='mode train or evaluate')

    args = parser.parse_args()
    lr = args.lr
    l = args.l
    noise_dim = args.noise_dim
    base_dim = args.base_dim

    runner = TrainingRunner('wgan_gp', create_dogs_dataset(),
                            dogs.Generator(noise_dim=noise_dim, base_dim=base_dim),
                            dogs.Discriminator(base_dim=base_dim, batch_norm=False),
                            WGANGPOptimizer(lr=lr, l=l), args=args)

    runner.execute(args)
Exemplo n.º 4
0
"""
   Copyright 2018 JetBrains, s.r.o
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at
       http://www.apache.org/licenses/LICENSE-2.0
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
"""

from torch.utils.data import DataLoader
from dogsgan.data.dogs import create_dogs_dataset
from torchvision.utils import make_grid, save_image

if __name__ == '__main__':
    loader = DataLoader(create_dogs_dataset(), batch_size=104, shuffle=True)
    for X, _ in loader:
        save_image(make_grid(X, normalize=True), 'dogs.png')
        break
Exemplo n.º 5
0
def compute_marginal(dists):
    sums = torch.sum(dists, 0)
    return sums / torch.sum(sums)


def inception_score(images):
    inception = inception_v3(pretrained=True)
    inception.train(False)

    has_cuda = torch.cuda.device_count() > 0
    if has_cuda:
        inception = inception.cuda()

    scores = apply_classifier(inception, images)
    mdist = compute_marginal(scores)

    divs = []
    for i in range(0, scores.shape[0]):
        divs.append(kl_divergence(scores[i, :], mdist))

    sd = torch.Tensor(divs).std().exp().item()
    return torch.Tensor(divs).mean().exp().item(), sd / (scores.shape[0]**0.5)


if __name__ == '__main__':
    dogs_dataset = create_dogs_dataset(
        normalize=False, image_transforms=[transforms.Resize((299, 299))])
    print(inception_score(dogs_dataset))

    #14.634567260742188, 0.02150835660283012
Exemplo n.º 6
0
"""
   Copyright 2018 JetBrains, s.r.o
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at
       http://www.apache.org/licenses/LICENSE-2.0
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
"""

from dogsgan.data.dogs import create_dogs_dataset
from dogsgan.training.optimizers import WGANGPOptimizer
from dogsgan.training.runner import TrainingRunner

import dogsgan.models.dogs as dogs

if __name__ == '__main__':
    for l in [1.0, 2.0, 4.0, 8.0, 10.0, 16.0]:
        runner = TrainingRunner(
            f'wgan_gp-{l}', create_dogs_dataset(),
            dogs.Generator(base_dim=224),
            dogs.Discriminator(batch_norm=False, base_dim=224),
            WGANGPOptimizer(l=l))

        runner.train(epochs=100, batch_size=64)