New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds adversarial example generation script #11
Conversation
Adds the adversarial example generating script (in adversarial_depth.py) which takes in a DepthModelWrapper instance (in depth_model_wrapper.py), which has methods to load and call predict on a depth model, and moves adversarial code into a separate directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the large number of files - most are due to my moving the existing starter project code into a separate directory from this adversarial script I'm adding now. The main code that has been added is all in adversarial_depth.py and depth_model_wrapper.py.
Reviewable status: 0 of 37 files reviewed, all discussions resolved (waiting on @annxingyuan and @EmilyReif)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 37 files at r1.
Reviewable status: 1 of 37 files reviewed, 5 unresolved discussions (waiting on @annxingyuan, @ellenjiang7, and @EmilyReif)
adversarial/adversarial_depth.py, line 26 at r1 (raw file):
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '5'
Add note for what this means
adversarial/adversarial_depth.py, line 30 at r1 (raw file):
# Image Paths SINK_IMAGE = "/usr/local/google/home/ellenj/Documents/BigPicture/DenseDepth/examples/1_image.png"
Nit: can you make these local paths? Just to avoid info leaking out in the world (your name, "BigPicture", and "DenseDepth")
adversarial/adversarial_depth.py, line 126 at r1 (raw file):
for i in range(iterations): loss, gradients = retrieve_loss_and_gradients(input_image) print('Loss at', i, ':', loss)
FYI: can change to python string formatting if you want:
'Loss at %d : %.2f' % (i, loss)
adversarial/adversarial_depth.py, line 156 at r1 (raw file):
gradients /= K.maximum(K.mean(K.abs(gradients)), K.epsilon()) # normalize global get_loss_and_gradients
In general, avoid python globals: http://go/pystyle#global-variables
Can you pass get_loss_and_gradients into gradient_ascent?
adversarial/depth_model_wrapper.py, line 16 at r1 (raw file):
# ============================================================================== """Abstract Wrapper class for the depth model for generating adversarial examples."""
Nice, looks great. Want to add a simple usage example here? (something like what was in the main() function of the depth model that implements this interface)
(lemme know if this doesn't make sense and we can sync in person)
depth_visualizer/static/illusions.77de5100.css, line 1 at r1 (raw file):
/* Copyright 2019 Google LLC
Hm, this looks like a generated file. Can we add static/*.css to the gitignore?
actually, this looks like it happened a few times below too-- there are some generated .js, .map, and image files
https://stackoverflow.com/questions/5241644/using-gitignore-to-ignore-everything-but-specific-directories might be helpful-- not sure what is the most elegant way to deal with the static folder in gitignore
Removes line that suppresses logging, changes image paths to local paths in adversarial_depth.py, changes loss printing to Python string formatting, removes global variable, and adds usage example to depth_model_wrapper.py.
Fixes gitignore paths that have been moved to the depthvisualizer directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 31 files reviewed, 5 unresolved discussions (waiting on @annxingyuan and @EmilyReif)
adversarial/adversarial_depth.py, line 26 at r1 (raw file):
Previously, EmilyReif (Emily Reif) wrote…
Add note for what this means
Hmm it suppresses logging, though now that I think about it - perhaps it might be better to remove this and allow the default logging, in case it's helpful for someone troubleshooting when they use the script?
adversarial/adversarial_depth.py, line 30 at r1 (raw file):
Previously, EmilyReif (Emily Reif) wrote…
Nit: can you make these local paths? Just to avoid info leaking out in the world (your name, "BigPicture", and "DenseDepth")
Oh yeah, good point. Done.
adversarial/adversarial_depth.py, line 126 at r1 (raw file):
Previously, EmilyReif (Emily Reif) wrote…
FYI: can change to python string formatting if you want:
'Loss at %d : %.2f' % (i, loss)
Done.
adversarial/adversarial_depth.py, line 156 at r1 (raw file):
Previously, EmilyReif (Emily Reif) wrote…
In general, avoid python globals: http://go/pystyle#global-variables
Can you pass get_loss_and_gradients into gradient_ascent?
Whoops yeah, sounds good. Done.
adversarial/depth_model_wrapper.py, line 16 at r1 (raw file):
Previously, EmilyReif (Emily Reif) wrote…
Nice, looks great. Want to add a simple usage example here? (something like what was in the main() function of the depth model that implements this interface)
(lemme know if this doesn't make sense and we can sync in person)
Yeah, sounds great! Does this work?
depth_visualizer/static/illusions.77de5100.css, line 1 at r1 (raw file):
Previously, EmilyReif (Emily Reif) wrote…
Hm, this looks like a generated file. Can we add static/*.css to the gitignore?
actually, this looks like it happened a few times below too-- there are some generated .js, .map, and image files
https://stackoverflow.com/questions/5241644/using-gitignore-to-ignore-everything-but-specific-directories might be helpful-- not sure what is the most elegant way to deal with the static folder in gitignore
Oh I just realized I forgot to change the paths of the static folder items in gitignore when I moved the starter project into a subdirectory. Fixed now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ellen this is awesome! Sorry I didn't have more comments - everything looks good to me though :) Would love to get a demo of everything if you get a chance at some point!
adversarial/adversarial_depth.py
Outdated
BATHTUB_IMAGE = "images/bathtub.png" | ||
|
||
|
||
def get_sink_to_bathtub_inputs(depth_model_wrapper, model): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a brief description of the sink to bathtub experiment?
return input_image | ||
|
||
|
||
def generate_adversarial_example(depth_model_wrapper, iterations = 100, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe make input_image and goal_output configurable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet thanks!
Reviewable status: 0 of 28 files reviewed, 6 unresolved discussions (waiting on @annxingyuan and @EmilyReif)
adversarial/adversarial_depth.py, line 31 at r2 (raw file):
Previously, annxingyuan (Ann Yuan) wrote…
Maybe add a brief description of the sink to bathtub experiment?
Done.
adversarial/adversarial_depth.py, line 128 at r2 (raw file):
Previously, annxingyuan (Ann Yuan) wrote…
Maybe make input_image and goal_output configurable?
Ah yea good idea! Done.
adversarial/adversarial_depth.py, line 26 at r1 (raw file): Previously, ellenjiang7 wrote…
sure, sgtm |
adversarial/depth_model_wrapper.py, line 16 at r1 (raw file): Previously, ellenjiang7 wrote…
Looks perfect! |
depth_visualizer/static/escher-trippy.5b69c0dc.jpg, line 0 at r3 (raw file): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 23 of 37 files at r1, 12 of 16 files at r2, 1 of 1 files at r3.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @annxingyuan, @ellenjiang7, and @EmilyReif)
Looks good to me! |
depth_visualizer/static/illusions.77de5100.css, line 1 at r1 (raw file): Previously, ellenjiang7 wrote…
gotcha, sounds good! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 22 of 25 files reviewed, 5 unresolved discussions (waiting on @annxingyuan and @EmilyReif)
adversarial/adversarial_depth.py, line 26 at r1 (raw file):
Previously, EmilyReif (Emily Reif) wrote…
sure, sgtm
Done.
depth_visualizer/static/escher-trippy.5b69c0dc.jpg, line at r3 (raw file):
Previously, EmilyReif (Emily Reif) wrote…
wait, I think this is a generated file? Or maybe reviewable is just showing me this cause it was in the PR at one point... (just check to make sure that in your current branch, there's no more generated files)
Done.
depth_visualizer/static/illusions.77de5100.css, line 1 at r1 (raw file):
Previously, EmilyReif (Emily Reif) wrote…
gotcha, sounds good!
Done.
Adds the adversarial example generating script (in adversarial_depth.py)
which takes in a DepthModelWrapper instance (in depth_model_wrapper.py),
which has methods to load and call predict on a depth model, and moves
adversarial code into a separate directory.
This change is