3

我在通过任何方法生成对抗性示例时收到以下错误

InvalidArgumentError: assertion failed: [] [Condition x <= y did not hold element-wise:x (Placeholder_173:0) = ] [[[[158 112 49]]]...] [y (Cast_6:0) = ] [1]
     [[{{node assert_less_equal_1/Assert/AssertGuard/Assert}}]]

我的生成对抗样本的代码


from cleverhans.utils_keras import KerasModelWrapper
from cleverhans.attacks import FastGradientMethod
model=build_model()
sess =  K.get_session()
wrap = KerasModelWrapper(model)
fgsm = FastGradientMethod(wrap, sess=sess)
fgsm_params = {'eps': 0.3,
               'clip_min': 0.,
               'clip_max': 1.}
adv_x = fgsm.generate_np(x_test, **fgsm_params)

此处的模型代码 tensorflow 版本 = 1.13.1

https://github.com/geifmany/cifar-vgg/blob/master/cifar10vgg.py

完整的堆栈跟踪

---------------------------------------------------------------------------
InvalidArgumentError                      Traceback (most recent call last)
~/anaconda3/lib/python3.7/site-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)
   1333     try:
-> 1334       return fn(*args)
   1335     except errors.OpError as e:

~/anaconda3/lib/python3.7/site-packages/tensorflow/python/client/session.py in _run_fn(feed_dict, fetch_list, target_list, options, run_metadata)
   1318       return self._call_tf_sessionrun(
-> 1319           options, feed_dict, fetch_list, target_list, run_metadata)
   1320 

~/anaconda3/lib/python3.7/site-packages/tensorflow/python/client/session.py in _call_tf_sessionrun(self, options, feed_dict, fetch_list, target_list, run_metadata)
   1406         self._session, options, feed_dict, fetch_list, target_list,
-> 1407         run_metadata)
   1408 

InvalidArgumentError: assertion failed: [] [Condition x <= y did not hold element-wise:x (Placeholder_173:0) = ] [[[[158 112 49]]]...] [y (Cast_6:0) = ] [1]
     [[{{node assert_less_equal_1/Assert/AssertGuard/Assert}}]]

During handling of the above exception, another exception occurred:

InvalidArgumentError                      Traceback (most recent call last)
<ipython-input-4-8941aeed68c9> in <module>
      8                'clip_min': 0.,
      9                'clip_max': 1.}
---> 10 adv_x = fgsm.generate_np(x_test, **fgsm_params)

~/anaconda3/lib/python3.7/site-packages/cleverhans/attacks/__init__.py in generate_np(self, x_val, **kwargs)
    201       feed_dict[new_kwargs[name]] = feedable[name]
    202 
--> 203     return self.sess.run(x_adv, feed_dict)
    204 
    205   def construct_variables(self, kwargs):

~/anaconda3/lib/python3.7/site-packages/tensorflow/python/client/session.py in run(self, fetches, feed_dict, options, run_metadata)
    927     try:
    928       result = self._run(None, fetches, feed_dict, options_ptr,
--> 929                          run_metadata_ptr)
    930       if run_metadata:
    931         proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)

~/anaconda3/lib/python3.7/site-packages/tensorflow/python/client/session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
   1150     if final_fetches or final_targets or (handle and feed_dict_tensor):
   1151       results = self._do_run(handle, final_targets, final_fetches,
-> 1152                              feed_dict_tensor, options, run_metadata)
   1153     else:
   1154       results = []

~/anaconda3/lib/python3.7/site-packages/tensorflow/python/client/session.py in _do_run(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)
   1326     if handle is None:
   1327       return self._do_call(_run_fn, feeds, fetches, targets, options,
-> 1328                            run_metadata)
   1329     else:
   1330       return self._do_call(_prun_fn, handle, feeds, fetches)

~/anaconda3/lib/python3.7/site-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)
   1346           pass
   1347       message = error_interpolation.interpolate(message, self._graph)
-> 1348       raise type(e)(node_def, op, message)
   1349 
   1350   def _extend_graph(self):

InvalidArgumentError: assertion failed: [] [Condition x <= y did not hold element-wise:x (Placeholder_173:0) = ] [[[[158 112 49]]]...] [y (Cast_6:0) = ] [1]
     [[node assert_less_equal_1/Assert/AssertGuard/Assert (defined at /home/munib/anaconda3/lib/python3.7/site-packages/cleverhans/utils_tf.py:615) ]]


4

1 回答 1

0

看起来您的输入不在 [clip_min, clip_max] 区间内。在将其喂给之前,您是否确保将x_test其剪裁到该间隔?generate_np

于 2019-07-10T05:10:42.513 回答