def main(opt):
    if type(opt.seed) is int:
        torch.manual_seed(opt.seed)
    device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
    (x_train, y_train), _ = load_mnist("dataset",
                                       training_label=opt.training_label,
                                       split_rate=opt.split_rate)
    train_mnist = SimpleDataset(x_train,
                                y_train,
                                transform=transforms.Compose([
                                    transforms.ToPILImage(),
                                    transforms.ToTensor(),
                                    transforms.Normalize([0.5], [0.5])
                                ]))
    train_dataloader = DataLoader(train_mnist,
                                  batch_size=opt.batch_size,
                                  shuffle=True)

    img_shape = (opt.channels, opt.img_size, opt.img_size)
    generator = Generator(img_shape, opt.latent_dim)
    discriminator = Discriminator(img_shape)
    encoder = Encoder(img_shape)

    train_encoder_izif(opt, generator, discriminator, encoder,
                       train_dataloader, device)
Beispiel #2
0
def main(opt):
    device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
    _, (x_test, y_test) = load_mnist("dataset",
                                     training_label=opt.training_label,
                                     split_rate=opt.split_rate)
    test_mnist = SimpleDataset(x_test,
                               y_test,
                               transform=transforms.Compose([
                                   transforms.ToPILImage(),
                                   transforms.ToTensor(),
                                   transforms.Normalize([0.5], [0.5])
                               ]))
    test_dataloader = DataLoader(test_mnist, batch_size=1, shuffle=False)

    generator = Generator(opt)
    discriminator = Discriminator(opt)
    encoder = Encoder(opt)

    test_anomaly_detection(opt, generator, discriminator, encoder,
                           test_dataloader, device)
Beispiel #3
0
def main(opt):
    if type(opt.seed) is int:
        torch.manual_seed(opt.seed)
    device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
    _, (x_test, y_test) = load_mnist("dataset",
                                     training_label=opt.training_label,
                                     split_rate=opt.split_rate)
    test_mnist = SimpleDataset(x_test,
                               y_test,
                               transform=transforms.Compose([
                                   transforms.ToPILImage(),
                                   transforms.ToTensor(),
                                   transforms.Normalize([0.5], [0.5])
                               ]))
    test_dataloader = DataLoader(test_mnist,
                                 batch_size=opt.n_grid_lines,
                                 shuffle=True)

    generator = Generator(opt)
    encoder = Encoder(opt)

    save_compared_images(opt, generator, encoder, test_dataloader, device)