Exemplo n.º 1
0
    def test_poisonkey(self):
        self.args.poisonkey = 280878748
        data = forest.Kettle(self.args, self.defs, setup=self.setup)

        class_names = data.trainset.classes
        self.assertTrue(class_names[data.targetset[0][1]] == 'cat')
        self.assertTrue(class_names[data.poisonset[0][1]] == 'bird')
            print(datetime.datetime.now().strftime("%A, %d. %B %Y %I:%M%p"))
            print(args)
            print(repr(defs))
            print(
                f'CPUs: {torch.get_num_threads()}, GPUs: {torch.cuda.device_count()} on {socket.gethostname()}'
            )
            print(
                f'Ensemble launched on {torch.distributed.get_world_size()} GPUs'
                f' with backend {forest.consts.DISTRIBUTED_BACKEND}.')

    if torch.cuda.is_available():
        print(f'GPU : {torch.cuda.get_device_name(device=device)}')

    model = forest.Victim(args, setup=setup)
    data = forest.Kettle(args,
                         model.defs.batch_size,
                         model.defs.augmentations,
                         setup=setup)
    witch = forest.Witch(args, setup=setup)

    start_time = time.time()
    if args.pretrained:
        print('Loading pretrained model...')
        stats_clean = None
    else:
        stats_clean = model.train(data, max_epoch=args.max_epoch)
    train_time = time.time()

    poison_delta = witch.brew(model, data)
    brew_time = time.time()

    if not args.pretrained and args.retrain_from_init: