softsys4ai/athena

Issues running script on gcloud

Closed this issue · 3 comments

  File "scripts.py", line 308, in <module>
    tf.app.run()
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/platform/app.py", line 40, in run
    _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
  File "/usr/local/lib/python3.5/dist-packages/absl/app.py", line 300, in run
    _run_main(main, args)
  File "/usr/local/lib/python3.5/dist-packages/absl/app.py", line 251, in _run_main
    sys.exit(main(argv))
  File "scripts.py", line 290, in main
    generate_adversarial_examples(DATA.mnist, ATTACK.JSMA)
  File "scripts.py", line 177, in generate_adversarial_examples
    theta=theta, gamma=gamma)
  File "/home/tester/advML/attacks/attacker.py", line 107, in get_adversarial_examples
    X_adv, Y = whitebox.generate(model_name, X, Y, attack_method, attack_params)
  File "/home/tester/advML/attacks/whitebox.py", line 172, in generate
    adv_x = attacker.generate(model.input, **attack_params)
  File "/home/tester/.local/lib/python3.5/site-packages/cleverhans/attacks/__init__.py", line 948, in generate
    labels, nb_classes = self.get_or_guess_labels(x, kwargs)
  File "/home/tester/.local/lib/python3.5/site-packages/cleverhans/attacks/__init__.py", line 281, in get_or_guess_labels
    preds = self.model.get_probs(x)
  File "/home/tester/.local/lib/python3.5/site-packages/cleverhans/utils_keras.py", line 179, in get_probs
    return self.get_layer(x, name)
  File "/home/tester/.local/lib/python3.5/site-packages/cleverhans/utils_keras.py", line 227, in get_layer
    output = self.fprop(x)
  File "/home/tester/.local/lib/python3.5/site-packages/cleverhans/utils_keras.py", line 203, in fprop
    self.keras_model = KerasModel(new_input, out_layers)
  File "/usr/local/lib/python3.5/dist-packages/keras/legacy/interfaces.py", line 91, in wrapper
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/keras/engine/network.py", line 93, in __init__
    self._init_graph_network(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/keras/engine/network.py", line 231, in _init_graph_network
    self.inputs, self.outputs)
  File "/usr/local/lib/python3.5/dist-packages/keras/engine/network.py", line 1366, in _map_graph_network
    tensor_index=tensor_index)
  File "/usr/local/lib/python3.5/dist-packages/keras/engine/network.py", line 1347, in build_map
    for i in range(len(node.inbound_layers)):
**TypeError: object of type 'InputLayer' has no len()**

This issue can be addressed by upgrading cleverhans.
cleverhans-lab/cleverhans#960

However, a new issue comes out.

  File "/home/researcher/PycharmProjects/adversarial_transformers/scripts.py", line 296, in <module>
    tf.app.run()
  File "/home/researcher/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/platform/app.py", line 40, in run
    _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
  File "/home/researcher/anaconda3/envs/tf/lib/python3.7/site-packages/absl/app.py", line 300, in run
    _run_main(main, args)
  File "/home/researcher/anaconda3/envs/tf/lib/python3.7/site-packages/absl/app.py", line 251, in _run_main
    sys.exit(main(argv))
  File "/home/researcher/PycharmProjects/adversarial_transformers/scripts.py", line 278, in main
    generate_adversarial_examples(DATA.mnist, ATTACK.FGSM)
  File "/home/researcher/PycharmProjects/adversarial_transformers/scripts.py", line 122, in generate_adversarial_examples
    X_adv, _ = get_adversarial_examples(model_name, method, X, Y, eps=eps)
  File "/home/researcher/PycharmProjects/adversarial_transformers/attacks/attacker.py", line 30, in get_adversarial_examples
    X_adv, Y = whitebox.generate(model_name, X, Y, attack_method, attack_params)
  File "/home/researcher/PycharmProjects/adversarial_transformers/attacks/whitebox.py", line 163, in generate
    metrics=['accuracy', adv_accuracy_metric]
  File "/home/researcher/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/training/tracking/base.py", line 457, in _method_wrapper
    result = method(self, *args, **kwargs)
  File "/home/researcher/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py", line 330, in compile
    masks=self._prepare_output_masks())
  File "/home/researcher/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py", line 2170, in _handle_metrics
    target, output, output_mask))
  File "/home/researcher/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py", line 2118, in _handle_per_output_metrics
    mask)
  File "/home/researcher/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py", line 2094, in _call_metric_fn
    strategy=self._distribution_strategy)
  File "/home/researcher/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/keras/distribute/distributed_training_utils.py", line 1054, in call_replica_local_fn
    return fn(*args, **kwargs)
  File "/home/researcher/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/keras/engine/training_utils.py", line 873, in call_metric_function
    return metric_fn(y_true, y_pred, sample_weight=weights)
  File "/home/researcher/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/keras/metrics.py", line 170, in __call__
    update_op = self.update_state(*args, **kwargs)  # pylint: disable=not-callable
  File "/home/researcher/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/keras/utils/metrics_utils.py", line 73, in decorated
    update_op = update_state_fn(*args, **kwargs)
  File "/home/researcher/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/keras/metrics.py", line 549, in update_state
    matches = self._fn(y_true, y_pred, **self._fn_kwargs)
  File "/home/researcher/PycharmProjects/adversarial_transformers/attacks/whitebox.py", line 224, in adv_acc
    preds_adv = model(x_adv)
  File "/home/researcher/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py", line 561, in __call__
    base_layer_utils.create_keras_history(inputs)
  File "/home/researcher/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer_utils.py", line 200, in create_keras_history
    _, created_layers = _create_keras_history_helper(tensors, set(), [])
  File "/home/researcher/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer_utils.py", line 246, in _create_keras_history_helper
    layer_inputs, processed_ops, created_layers)
  File "/home/researcher/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer_utils.py", line 246, in _create_keras_history_helper
    layer_inputs, processed_ops, created_layers)
  File "/home/researcher/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer_utils.py", line 246, in _create_keras_history_helper
    layer_inputs, processed_ops, created_layers)
  [Previous line repeated 14 more times]
  File "/home/researcher/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer_utils.py", line 244, in _create_keras_history_helper
    constants[i] = backend.function([], op_input)([])
  File "/home/researcher/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/keras/backend.py", line 3292, in __call__
    run_metadata=self.run_metadata)
  File "/home/researcher/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 1458, in __call__
    run_metadata_ptr)
tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'conv2d_input' with dtype float and shape [?,28,28,1]
	 [[{{node conv2d_input}}]]```

This was due to the incorrect versions of libraries being installed.
Make sure to install tensorflow 1.13 and the newest cleverhans (via pip install git+https://github.com/tensorflow/cleverhans.git#egg=cleverhans, this requires a pip >= 19).

Problem has been solved on local machine. This issue will be closed after we test it on GCP.

a requirements.txt has been uploaded to the repo.

Above solution works on google cloud platform as well. Close.