visualize the perturbation

40 views
Skip to first unread message

ephi...@yahoo.com

unread,
Nov 20, 2018, 4:37:19 PM11/20/18
to cleverhans dev
  in cleverhans/attacks.py, line 473, there is eq. (2) from arXiv:1610.00768v6, i.e., adv_x = x + optimal_perturbation. I would like to visualize a [1, 28, 28, 1] subset of "optimal_perturbation". Is there some thing similar to np.save ('filename.npy', optimal_perturbation) to do this. I am running into errors. I saw this kind of visualization in Figure 1 in arXiv:1412.6572v3.

Ian Goodfellow

unread,
Nov 20, 2018, 4:42:21 PM11/20/18
to ephi...@yahoo.com, cleverhans dev
There are at least the following options, maybe more:

You can use np.save to save the numpy files and then use the show_images.py script to view the images stored in the numpy file: https://github.com/tensorflow/cleverhans/blob/master/scripts/show_images.py

You can use cleverhans.plot.image.show to display the numpy array as an image.

You can use cleverhans.plot.save to save the numpy array as an image file, like .png


On Tue, Nov 20, 2018 at 1:37 PM 'ephi...@yahoo.com' via cleverhans dev <cleverh...@googlegroups.com> wrote:
  in cleverhans/attacks.py, line 473, there is eq. (2) from arXiv:1610.00768v6, i.e., adv_x = x + optimal_perturbation. I would like to visualize a [1, 28, 28, 1] subset of "optimal_perturbation". Is there some thing similar to np.save ('filename.npy', optimal_perturbation) to do this. I am running into errors. I saw this kind of visualization in Figure 1 in arXiv:1412.6572v3.

--
You received this message because you are subscribed to the Google Groups "cleverhans dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cleverhans-de...@googlegroups.com.
To post to this group, send email to cleverh...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cleverhans-dev/e66fe154-406c-48d7-ae7d-319d3b88e4bb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ephi...@yahoo.com

unread,
Nov 20, 2018, 5:27:24 PM11/20/18
to cleverhans dev
using  np.save('perturbation.npy',optimal_perturbation), I get the following error: TypeError: can't pickle _thread.RLock objects
I thought it would be more straight forward.

  File "C:\ProgramData\Miniconda3\envs\tensorflow\Lib\site-packages\cleverhans\attacks.py", line 353, in generate
    sanity_checks
=self.sanity_checks)
 
File "C:\ProgramData\Miniconda3\envs\tensorflow\Lib\site-packages\cleverhans\attacks.py", line 472, in fgm
    np
.save('perturbation.npy',optimal_perturbation)
 
File "C:\ProgramData\Miniconda3\envs\tensorflow\Lib\site-packages\numpy\lib\npyio.py", line 511, in save
    pickle_kwargs
=pickle_kwargs)
 
File "C:\ProgramData\Miniconda3\envs\tensorflow\Lib\site-packages\numpy\lib\format.py", line 586, in write_array
    pickle
.dump(array, fp, protocol=2, **pickle_kwargs)
TypeError: can't pickle _thread.RLock objects


On Tuesday, November 20, 2018 at 4:42:21 PM UTC-5, Ian Goodfellow wrote:
There are at least the following options, maybe more:

You can use np.save to save the numpy files and then use the show_images.py script to view the images stored in the numpy file: https://github.com/tensorflow/cleverhans/blob/master/scripts/show_images.py

You can use cleverhans.plot.image.show to display the numpy array as an image.

You can use cleverhans.plot.save to save the numpy array as an image file, like .png


On Tue, Nov 20, 2018 at 1:37 PM 'ephi...@yahoo.com' via cleverhans dev <cleverhans-dev@googlegroups.com> wrote:
  in cleverhans/attacks.py, line 473, there is eq. (2) from arXiv:1610.00768v6, i.e., adv_x = x + optimal_perturbation. I would like to visualize a [1, 28, 28, 1] subset of "optimal_perturbation". Is there some thing similar to np.save ('filename.npy', optimal_perturbation) to do this. I am running into errors. I saw this kind of visualization in Figure 1 in arXiv:1412.6572v3.

--
You received this message because you are subscribed to the Google Groups "cleverhans dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cleverhans-dev+unsubscribe@googlegroups.com.
To post to this group, send email to cleverhans-dev@googlegroups.com.

Ian Goodfellow

unread,
Nov 20, 2018, 6:15:08 PM11/20/18
to ephi...@yahoo.com, cleverhans dev
What is `type(optimal_perturbation)`?

On Tue, Nov 20, 2018 at 2:27 PM 'ephi...@yahoo.com' via cleverhans dev <cleverh...@googlegroups.com> wrote:
using  np.save('perturbation.npy',optimal_perturbation), I get the following error: TypeError: can't pickle _thread.RLock objects
I thought it would be more straight forward.
  File "C:\ProgramData\Miniconda3\envs\tensorflow\Lib\site-packages\cleverhans\attacks.py", line 353, in generate
    sanity_checks
=self.sanity_checks)
 
File "C:\ProgramData\Miniconda3\envs\tensorflow\Lib\site-packages\cleverhans\attacks.py", line 472, in fgm
    np
.save('perturbation.npy',optimal_perturbation)
 
File "C:\ProgramData\Miniconda3\envs\tensorflow\Lib\site-packages\numpy\lib\npyio.py", line 511, in save
    pickle_kwargs
=pickle_kwargs)
 
File "C:\ProgramData\Miniconda3\envs\tensorflow\Lib\site-packages\numpy\lib\format.py", line 586, in write_array
    pickle
.dump(array, fp, protocol=2, **pickle_kwargs)
TypeError: can't pickle _thread.RLock objects


On Tuesday, November 20, 2018 at 4:42:21 PM UTC-5, Ian Goodfellow wrote:
There are at least the following options, maybe more:

You can use np.save to save the numpy files and then use the show_images.py script to view the images stored in the numpy file: https://github.com/tensorflow/cleverhans/blob/master/scripts/show_images.py

You can use cleverhans.plot.image.show to display the numpy array as an image.

You can use cleverhans.plot.save to save the numpy array as an image file, like .png


On Tue, Nov 20, 2018 at 1:37 PM 'ephi...@yahoo.com' via cleverhans dev <cleverh...@googlegroups.com> wrote:
  in cleverhans/attacks.py, line 473, there is eq. (2) from arXiv:1610.00768v6, i.e., adv_x = x + optimal_perturbation. I would like to visualize a [1, 28, 28, 1] subset of "optimal_perturbation". Is there some thing similar to np.save ('filename.npy', optimal_perturbation) to do this. I am running into errors. I saw this kind of visualization in Figure 1 in arXiv:1412.6572v3.

--
You received this message because you are subscribed to the Google Groups "cleverhans dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cleverhans-de...@googlegroups.com.
To post to this group, send email to cleverh...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "cleverhans dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cleverhans-de...@googlegroups.com.
To post to this group, send email to cleverh...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cleverhans-dev/14d35a02-8046-414d-b91f-14611619c532%40googlegroups.com.

ephi...@yahoo.com

unread,
Nov 20, 2018, 6:28:52 PM11/20/18
to cleverhans dev
ipdb> optimal_perturbation
tf.Tensor 'mul:0' 
shape=(?, 32, 32, 3) 
dtype=float32

On Tuesday, November 20, 2018 at 6:15:08 PM UTC-5, Ian Goodfellow wrote:
What is `type(optimal_perturbation)`?

On Tue, Nov 20, 2018 at 2:27 PM 'ephi...@yahoo.com' via cleverhans dev <cleverhans-dev@googlegroups.com> wrote:
using  np.save('perturbation.npy',optimal_perturbation), I get the following error: TypeError: can't pickle _thread.RLock objects
I thought it would be more straight forward.
  File "C:\ProgramData\Miniconda3\envs\tensorflow\Lib\site-packages\cleverhans\attacks.py", line 353, in generate
    sanity_checks
=self.sanity_checks)
 
File "C:\ProgramData\Miniconda3\envs\tensorflow\Lib\site-packages\cleverhans\attacks.py", line 472, in fgm
    np
.save('perturbation.npy',optimal_perturbation)
 
File "C:\ProgramData\Miniconda3\envs\tensorflow\Lib\site-packages\numpy\lib\npyio.py", line 511, in save
    pickle_kwargs
=pickle_kwargs)
 
File "C:\ProgramData\Miniconda3\envs\tensorflow\Lib\site-packages\numpy\lib\format.py", line 586, in write_array
    pickle
.dump(array, fp, protocol=2, **pickle_kwargs)
TypeError: can't pickle _thread.RLock objects


On Tuesday, November 20, 2018 at 4:42:21 PM UTC-5, Ian Goodfellow wrote:
There are at least the following options, maybe more:

You can use np.save to save the numpy files and then use the show_images.py script to view the images stored in the numpy file: https://github.com/tensorflow/cleverhans/blob/master/scripts/show_images.py

You can use cleverhans.plot.image.show to display the numpy array as an image.

You can use cleverhans.plot.save to save the numpy array as an image file, like .png


On Tue, Nov 20, 2018 at 1:37 PM 'ephi...@yahoo.com' via cleverhans dev <cleverhans-dev@googlegroups.com> wrote:
  in cleverhans/attacks.py, line 473, there is eq. (2) from arXiv:1610.00768v6, i.e., adv_x = x + optimal_perturbation. I would like to visualize a [1, 28, 28, 1] subset of "optimal_perturbation". Is there some thing similar to np.save ('filename.npy', optimal_perturbation) to do this. I am running into errors. I saw this kind of visualization in Figure 1 in arXiv:1412.6572v3.

--
You received this message because you are subscribed to the Google Groups "cleverhans dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cleverhans-dev+unsubscribe@googlegroups.com.
To post to this group, send email to cleverhans-dev@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "cleverhans dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cleverhans-dev+unsubscribe@googlegroups.com.
To post to this group, send email to cleverhans-dev@googlegroups.com.

Ian Goodfellow

unread,
Nov 20, 2018, 8:04:22 PM11/20/18
to ephi...@yahoo.com, cleverhans dev
That is a TensorFlow tensor, not a Numpy array. You need to call its `eval` method or pass it to `sess.run` to get a NumPy value for it.

On Tue, Nov 20, 2018 at 3:28 PM 'ephi...@yahoo.com' via cleverhans dev <cleverh...@googlegroups.com> wrote:
ipdb> optimal_perturbation
tf.Tensor 'mul:0' 
shape=(?, 32, 32, 3) 
dtype=float32

On Tuesday, November 20, 2018 at 6:15:08 PM UTC-5, Ian Goodfellow wrote:
What is `type(optimal_perturbation)`?

On Tue, Nov 20, 2018 at 2:27 PM 'ephi...@yahoo.com' via cleverhans dev <cleverh...@googlegroups.com> wrote:
using  np.save('perturbation.npy',optimal_perturbation), I get the following error: TypeError: can't pickle _thread.RLock objects
I thought it would be more straight forward.
  File "C:\ProgramData\Miniconda3\envs\tensorflow\Lib\site-packages\cleverhans\attacks.py", line 353, in generate
    sanity_checks
=self.sanity_checks)
 
File "C:\ProgramData\Miniconda3\envs\tensorflow\Lib\site-packages\cleverhans\attacks.py", line 472, in fgm
    np
.save('perturbation.npy',optimal_perturbation)
 
File "C:\ProgramData\Miniconda3\envs\tensorflow\Lib\site-packages\numpy\lib\npyio.py", line 511, in save
    pickle_kwargs
=pickle_kwargs)
 
File "C:\ProgramData\Miniconda3\envs\tensorflow\Lib\site-packages\numpy\lib\format.py", line 586, in write_array
    pickle
.dump(array, fp, protocol=2, **pickle_kwargs)
TypeError: can't pickle _thread.RLock objects


On Tuesday, November 20, 2018 at 4:42:21 PM UTC-5, Ian Goodfellow wrote:
There are at least the following options, maybe more:

You can use np.save to save the numpy files and then use the show_images.py script to view the images stored in the numpy file: https://github.com/tensorflow/cleverhans/blob/master/scripts/show_images.py

You can use cleverhans.plot.image.show to display the numpy array as an image.

You can use cleverhans.plot.save to save the numpy array as an image file, like .png


On Tue, Nov 20, 2018 at 1:37 PM 'ephi...@yahoo.com' via cleverhans dev <cleverh...@googlegroups.com> wrote:
  in cleverhans/attacks.py, line 473, there is eq. (2) from arXiv:1610.00768v6, i.e., adv_x = x + optimal_perturbation. I would like to visualize a [1, 28, 28, 1] subset of "optimal_perturbation". Is there some thing similar to np.save ('filename.npy', optimal_perturbation) to do this. I am running into errors. I saw this kind of visualization in Figure 1 in arXiv:1412.6572v3.

--
You received this message because you are subscribed to the Google Groups "cleverhans dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cleverhans-de...@googlegroups.com.
To post to this group, send email to cleverh...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "cleverhans dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cleverhans-de...@googlegroups.com.
To post to this group, send email to cleverh...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "cleverhans dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cleverhans-de...@googlegroups.com.
To post to this group, send email to cleverh...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cleverhans-dev/4bf8c7f4-e8aa-4a1a-a1b7-a803a5e7ae9a%40googlegroups.com.

ephi...@yahoo.com

unread,
Nov 27, 2018, 3:18:39 PM11/27/18
to cleverhans dev
In cleverhans_tutorials\evaluate_pickled_model.py I have added
adv_x_sample = adv_x.eval(session=sess, feed_dict={x: x_test})

to save adv_x as a numpy array as 
np.save('adv-x-p2.npy',adv_x_sample)

In cleverhans\attacks.py I would like to do something similar to save the component 'optimal_perturbation. What can I write similar to the script below that will work?   
ln 473  adv_x = x + optimal_perturbation
        sess
= tf.Session()
       
with sess.as_default():
           bb
=optimal_perturbation.eval(session=sess, feed_dict={x?: x_test??})
           np
.save('p2_c.npy', bb)
Reply all
Reply to author
Forward
0 new messages