Exemplo n.º 1
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")

    mvtec_ad = MVTecAD()

    if not os.path.isdir(opt.dataset_name) or opt.force_download:
        mvtec_ad.download(opt.dataset_name)
        mvtec_ad.extract(opt.dataset_name)

    images = datasets.ImageFolder(f"./{opt.dataset_name}/test",
                                  transform=transforms.Compose([
                                      transforms.Resize([opt.img_size] * 2),
                                      transforms.RandomHorizontalFlip(),
                                      transforms.ToTensor(),
                                      transforms.Normalize([0.5, 0.5, 0.5],
                                                           [0.5, 0.5, 0.5])
                                  ]))
    test_dataloader = DataLoader(images, batch_size=1, shuffle=False)

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

    test_anomaly_detection(opt, generator, discriminator, encoder,
                           test_dataloader, device)
Exemplo n.º 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)
Exemplo n.º 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=1, shuffle=False)

    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)

    test_anomaly_detection(opt, generator, discriminator, encoder,
                           test_dataloader, device)
def main(opt):
    device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

    transform = transforms.Compose([
        transforms.Resize([opt.img_size] * 2),
        transforms.RandomHorizontalFlip(),
        transforms.ToTensor(),
        transforms.Normalize([0.5, 0.5, 0.5], [0.5, 0.5, 0.5])
    ])
    mvtec_ad = MVTecAD(".",
                       opt.dataset_name,
                       train=False,
                       transform=transform,
                       download=True)
    test_dataloader = DataLoader(mvtec_ad, batch_size=1, shuffle=False)

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

    test_anomaly_detection(opt, generator, discriminator, encoder,
                           test_dataloader, device)