Beispiel #1
0
def main():
    if not os.path.exists(args.output):
        os.makedirs(args.output)
    model, img_shape = getmodel(args.model)
    attacker = attack.FGSM(model=model,
                           goal=args.goal,
                           distance_metric=args.distance,
                           eps=args.eps)
    path = os.path.join('data', 'cfp-{}x{}'.format(img_shape[0], img_shape[1]))
    run_black(path, attacker, model, args)
Beispiel #2
0
def main():
    if not os.path.exists(args.output):
        os.makedirs(args.output)
    model, img_shape = getmodel(args.model)
    attacker = attack.Evolutionary(
        model=model,
        goal=args.goal,
        distance_metric=args.distance,
        max_queries=args.iters,
        threshold=threshold[args.model]['cos'],
    )
    path = os.path.join('data', 'cfp-{}x{}'.format(img_shape[0], img_shape[1]))
    Attacker = lambda xs, ys, pairs: attacker.batch_attack(xs, ys, pairs=pairs)
    run_white(path, Attacker, model, args, threshold[args.model]['cos'])
Beispiel #3
0
def main():
    if not os.path.exists(args.output):
        os.makedirs(args.output)
    model, img_shape = getmodel(args.model)

    attacker = attack.LGC(model=model,
                          goal=args.goal,
                          distance_metric=args.distance,
                          eps=args.eps,
                          mu=args.mu,
                          num_samples=args.num_samples,
                          iters=args.iters)

    path = os.path.join('data', 'ytf-{}x{}'.format(img_shape[0], img_shape[1]))
    run_black(path, attacker, model, args)
Beispiel #4
0
def main():
    if not os.path.exists(args.output):
        os.makedirs(args.output)
    model, img_shape = getmodel(args.model)
    attacker = attack.CW(model=model,
                         goal=args.goal,
                         distance_metric=args.distance,
                         iteration=args.iters,
                         threshold=threshold[args.model]['cos'],
                         search_steps=args.steps,
                         binsearch_steps=args.bin_steps,
                         confidence=args.confidence,
                         learning_rate=args.lr,
                         c=args.c)
    path = os.path.join('data', 'lfw-{}x{}'.format(img_shape[0], img_shape[1]))
    Attacker = lambda xs, ys, pairs: attacker.batch_attack(xs, ys, pairs=pairs)
    run_white(path, Attacker, model, args, threshold[args.model]['cos'])
Beispiel #5
0
def main():
    model, img_shape = getmodel(args.model)
    config = {
        'eps': args.eps,
        'method': attack.FGSM,
        'goal': args.goal,
        'distance_metric': args.distance,
        'threshold': threshold_ytf[args.model]['cos'],
        'steps': args.steps,
        'bin_steps': args.bin_steps,
        'model': model,
    }

    path = os.path.join('data', 'ytf-{}x{}'.format(img_shape[0], img_shape[1]))
    Attacker = lambda xs, ys, pairs: binsearch_basic(
        xs=xs, ys=ys, pairs=pairs, **config)
    run_white(path, Attacker, model, args, threshold_ytf[args.model]['cos'])
def main():
    if not os.path.exists(args.output):
        os.makedirs(args.output)
    model, img_shape = getmodel(args.model)
    config = {
        'eps': args.eps,
        'method': attack.BIM,
        'goal': args.goal,
        'distance_metric': args.distance,
        'threshold': threshold[args.model]['cos'],
        'steps': args.steps,
        'bin_steps': args.bin_steps,
        'model': model,
        'iters': args.iters,
    }
        
    path = os.path.join('data', 'lfw-{}x{}'.format(img_shape[0], img_shape[1]))
    Attacker = lambda xs, ys, pairs: binsearch_alpha(xs=xs, ys=ys, pairs=pairs, **config)
    run_white(path, Attacker, model, args, threshold[args.model]['cos'])
Beispiel #7
0
                    type=str,
                    default='impersonate',
                    choices=['dodging', 'impersonate'])
parser.add_argument('--distance',
                    help='l2 or linf',
                    type=str,
                    default='linf',
                    choices=['linf', 'l2'])
parser.add_argument('--anno',
                    help='output dir',
                    type=str,
                    default='output/expdemo/annotation.txt')
parser.add_argument('--log', help='log file', type=str, default='log.txt')
args = parser.parse_args()

model, img_shape = getmodel(args.model)
outputs = []
with open(args.anno, 'r') as f:
    for line in tqdm(f.readlines(), total=2500):
        adv_img_path, src_img_path, tar_img_path = line.strip().split(' ')

        adv_img = np.load(adv_img_path)
        resized_adv_img = cv2.resize(adv_img, (img_shape[1], img_shape[0]))
        resized_adv_img = torch.Tensor(
            resized_adv_img.transpose(2, 0, 1)[None, :]).cuda()
        adv_feat = model.forward(resized_adv_img)

        src_img = imread(src_img_path).astype(np.float32)

        tar_img = imread(tar_img_path).astype(np.float32)
        resized_tar_img = cv2.resize(tar_img, (img_shape[1], img_shape[0]))