Exemplo n.º 1
0
 def test_modelkey(self):
     self.args.modelkey = 3213894809
     model = forest.Victim(self.args, self.defs, setup=self.setup)
     model.initialize(self.args.modelkey)
     self.assertAlmostEqual(model.model.linear.weight[0][0].item(),
                            0.007770763710141182,
                            places=5)
        if torch.distributed.get_rank() == 0:
            print('Currently evaluating -------------------------------:')
            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)
            targets.append(target)
            indices.append(idx)

        for enum, (img, target, idx) in enumerate(data.targetset):
            targets.append(target)
            indices.append('target')
            img = img.unsqueeze(0).to(**data.setup)
            f = feature_extractor(img).detach().cpu().numpy()
            feats = np.append(feats, f, axis=0)
    return feats, targets, indices

if __name__ == "__main__":

    setup = forest.utils.system_startup(args)

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

    start_time = time.time()
    if args.pretrained_model:
        print('Loading pretrained model...')
        stats_clean = None
    elif args.skip_clean_training:
        print('Skipping clean training...')
        stats_clean = None