def main(): # tf.logging.set_verbosity(tf.logging.INFO) # instantiate blackbox and substitute model # instantiate blackbox and substitute model forward_model = load_model() # backward_model1 = create_fmodel_18() backward_model2 = create_fmodel_ALP() backward_model3 = create_fmodel_ALP1000() # print(backward_model1[0]) # instantiate differntiable composite model # (predictions from blackbox, gradients from substitute) model = CompositeModel( forward_model=forward_model, backward_models=[backward_model2, backward_model3], weights = [0.5, 0.5]) predictor = tp.OfflinePredictor(tp.PredictConfig( model=SaliencyModel(), session_init=tp.get_model_loader("resnet_v1_50.ckpt"), input_names=['image'], output_names=['saliency'])) for (file_name, image, label) in read_images(): pos_salience = find_salience(predictor, image) adversarial = run_attack(model, image, label, pos_salience) store_adversarial(file_name, adversarial) attack_complete()
def main(): loader = TinyImageNetLoader() forward_model = load_model() backward_model1 = create_fmodel_ALP() backward_model2 = create_fmodel_ALP1000() model = CompositeModel(forward_model=forward_model, backward_models=[backward_model1, backward_model2], weights=[0.3, 0.7]) i = 0 total_sum = 0.0 prev_avg = 0.0 for (file_name, image, label) in read_images(): is_boundary = True is_adam = True adversarial = run_attack(loader, forward_model, image, label) # Calculate both Adam and Boundary for first 5 images. if i < 5: adversarial_adam = run_attack2(model, image, label, None) if adversarial is not None: error1 = distance(adversarial, image) else: error1 = 100000.0 is_boundary = False if adversarial_adam is not None: error_adam = distance(adversarial_adam, image) else: error_adam = 200000.0 is_adam = False if is_adam and error1 - error_adam > 0.0: adversarial = adversarial_adam if is_adam or is_boundary: i += 1 total_sum += min(error1, error_adam) else: if adversarial is not None: error1 = distance(adversarial, image) prev_avg = total_sum / i i += 1 total_sum += error1 else: error1 = 100000.0 if error1 > 25.0 or error1 > prev_avg or adversarial is None: adversarial_adam = run_attack2(model, image, label, None) if adversarial_adam is not None: error_adam = distance(adversarial_adam, image) else: error_adam = 200000.0 if error1 - error_adam > 0.0: adversarial = adversarial_adam store_adversarial(file_name, adversarial) # Announce that the attack is complete # NOTE: In the absence of this call, your submission will timeout # while being graded. attack_complete()
def main(): # tf.logging.set_verbosity(tf.logging.INFO) # instantiate blackbox and substitute model # instantiate blackbox and substitute model forward_model = load_model() backward_model1 = create_fmodel_18() backward_model2 = create_fmodel_ALP() # print(backward_model1[0]) # instantiate differntiable composite model # (predictions from blackbox, gradients from substitute) model = CompositeModel(forward_model=forward_model, backward_models=[backward_model1, backward_model2]) for (file_name, image, label) in read_images(): adversarial = run_attack(model, image, label) store_adversarial(file_name, adversarial) attack_complete()
def main(): loader = TinyImageNetLoader() forward_model = load_model() backward_model1 = create_fmodel_ALP() backward_model2 = create_fmodel_ALP1000() model = CompositeModel(forward_model=forward_model, backward_models=[backward_model1, backward_model2], weights=[0.5, 0.5]) for (file_name, image, label) in read_images(): adversarial = run_attack(loader, forward_model, image, label) if adversarial is None: adversarial = run_attack2(model, image, label, None) store_adversarial(file_name, adversarial) # Announce that the attack is complete # NOTE: In the absence of this call, your submission will timeout # while being graded. attack_complete()
def main(): loader = TinyImageNetLoader() forward_model = load_model() backward_model1 = create_fmodel_ALP() backward_model2 = create_fmodel_ALP1000() model = CompositeModel(forward_model=forward_model, backward_models=[backward_model1, backward_model2], weights=[0.5, 0.5]) predictor = tp.OfflinePredictor( tp.PredictConfig(model=SaliencyModel(), session_init=tp.get_model_loader("resnet_v1_50.ckpt"), input_names=['image'], output_names=['saliency'])) for (file_name, image, label) in read_images(): adversarial = run_attack(loader, forward_model, image, label) if adversarial is None: pos_salience = find_salience(predictor, image) adversarial = run_attack2(model, image, label, pos_salience) store_adversarial(file_name, adversarial) # Announce that the attack is complete # NOTE: In the absence of this call, your submission will timeout # while being graded. attack_complete()