{"action":"created","comment":{"url":"https://api.github.com/repos/tensorflow/cleverhans/pulls/comments/141172813","pull_request_review_id":65349017,"id":141172813,"diff_hunk":"@@ -0,0 +1,257 @@\n+import numpy as np\n+import tensorflow as tf\n+\n+from cleverhans.model import Model, CallableModelWrapper\n+from cleverhans.attacks import Attack, FastGradientMethod\n+from cleverhans.utils_tf import model_loss\n+\n+from model import clone_variable, MLP_probs\n+\n+\n+class ProjectedGradientDescentMethod(Attack):\n+\n+    \"\"\"\n+    The Basic Iterative Method (Kurakin et al. 2016). The original paper used\n+    hard labels for this attack; no label smoothing.\n+    Paper link: https://arxiv.org/pdf/1607.02533.pdf\n+    \"\"\"\n+\n+    def __init__(self, model, back='tf', sess=None):\n+        \"\"\"\n+        Create a ProjectedGradientDescentMethod instance.\n+        \"\"\"\n+        super(ProjectedGradientDescentMethod, self).__init__(model, back, sess)\n+        self.feedable_kwargs = {'eps': np.float32,\n+                                'eps_iter': np.float32,\n+                                'y': np.float32,\n+                                'y_target': np.float32,\n+                                'clip_min': np.float32,\n+                                'clip_max': np.float32}\n+        self.structural_kwargs = ['ord', 'nb_iter']\n+\n+        if not isinstance(self.model, Model):\n+            self.model = MLP_probs(self.model)\n+\n+    def clip_eta(self, eta):\n+        # Clipping perturbation eta to self.ord norm ball\n+        if self.ord == np.inf:\n+            eta = tf.clip_by_value(eta, -self.eps, self.eps)\n+        elif self.ord in [1, 2]:\n+            reduc_ind = list(xrange(1, len(eta.get_shape())))\n+            if self.ord == 1:\n+                norm = tf.reduce_sum(tf.abs(eta),\n+                                     reduction_indices=reduc_ind,\n+                                     keep_dims=True)\n+            elif self.ord == 2:\n+                norm = tf.sqrt(tf.reduce_sum(tf.square(eta),\n+                                             reduction_indices=reduc_ind,\n+                                             keep_dims=True))\n+            eta = eta * self.eps / norm\n+        return eta\n+\n+    def PGDpgd(self, x, **kwargs):\n+        from cleverhans.utils_tf import model_loss\n+\n+        eta = tf.random_uniform(tf.shape(x), -self.eps, self.eps)\n+        eta = self.clip_eta(eta)\n+\n+        if self.y is not None:\n+            y = self.y\n+        else:\n+            preds = self.model.get_probs(x)\n+            preds_max = tf.reduce_max(preds, 1, keep_dims=True)\n+            y = tf.to_float(tf.equal(preds, preds_max))\n+            y = y / tf.reduce_sum(y, 1, keep_dims=True)\n+        y = tf.stop_gradient(y)\n+\n+        for i in range(self.nb_iter):\n+            adv_x = tf.stop_gradient(x + eta)\n+            preds = self.model.get_probs(adv_x)\n+            loss = model_loss(y, preds)\n+            grad, = tf.gradients(loss, adv_x)\n+            scaled_signed_grad = self.eps_iter * tf.sign(grad)\n+            adv_x = adv_x + scaled_signed_grad\n+            adv_x = tf.clip_by_value(adv_x, self.clip_min, self.clip_max)\n+            eta = adv_x - x\n+            eta = self.clip_eta(eta)\n+\n+        adv_x = x + eta\n+        if self.clip_min is not None and self.clip_max is not None:\n+            adv_x = tf.clip_by_value(adv_x, self.clip_min, self.clip_max)\n+        adv_x = tf.stop_gradient(adv_x)\n+\n+        return adv_x\n+\n+    def PGDpgd_singleStep(self, x, eta, y):","path":"examples/multigpu_advtrain/target_attack.py","position":85,"original_position":85,"commit_id":"2ef5a2c1e0ffc0fd8932debd03ab6a9e484957a2","original_commit_id":"2ef5a2c1e0ffc0fd8932debd03ab6a9e484957a2","user":{"login":"goodfeli","id":387866,"avatar_url":"https://avatars3.githubusercontent.com/u/387866?v=4","gravatar_id":"","url":"https://api.github.com/users/goodfeli","html_url":"https://github.com/goodfeli","followers_url":"https://api.github.com/users/goodfeli/followers","following_url":"https://api.github.com/users/goodfeli/following{/other_user}","gists_url":"https://api.github.com/users/goodfeli/gists{/gist_id}","starred_url":"https://api.github.com/users/goodfeli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/goodfeli/subscriptions","organizations_url":"https://api.github.com/users/goodfeli/orgs","repos_url":"https://api.github.com/users/goodfeli/repos","events_url":"https://api.github.com/users/goodfeli/events{/privacy}","received_events_url":"https://api.github.com/users/goodfeli/received_events","type":"User","site_admin":false},"body":"for this method name, I still don't know what \"PGDpgd\" means","created_at":"2017-09-26T20:23:18Z","updated_at":"2017-09-26T20:23:18Z","html_url":"https://github.com/tensorflow/cleverhans/pull/278#discussion_r141172813","pull_request_url":"https://api.github.com/repos/tensorflow/cleverhans/pulls/278","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/tensorflow/cleverhans/pulls/comments/141172813"},"html":{"href":"https://github.com/tensorflow/cleverhans/pull/278#discussion_r141172813"},"pull_request":{"href":"https://api.github.com/repos/tensorflow/cleverhans/pulls/278"}}},"pull_request":{"url":"https://api.github.com/repos/tensorflow/cleverhans/pulls/278","id":143192663,"html_url":"https://github.com/tensorflow/cleverhans/pull/278","diff_url":"https://github.com/tensorflow/cleverhans/pull/278.diff","patch_url":"https://github.com/tensorflow/cleverhans/pull/278.patch","issue_url":"https://api.github.com/repos/tensorflow/cleverhans/issues/278","number":278,"state":"open","locked":false,"title":"Iterative [multigpu] adversarial training on MNIST and CIFAR10.","user":{"login":"fartashf","id":7307513,"avatar_url":"https://avatars0.githubusercontent.com/u/7307513?v=4","gravatar_id":"","url":"https://api.github.com/users/fartashf","html_url":"https://github.com/fartashf","followers_url":"https://api.github.com/users/fartashf/followers","following_url":"https://api.github.com/users/fartashf/following{/other_user}","gists_url":"https://api.github.com/users/fartashf/gists{/gist_id}","starred_url":"https://api.github.com/users/fartashf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fartashf/subscriptions","organizations_url":"https://api.github.com/users/fartashf/orgs","repos_url":"https://api.github.com/users/fartashf/repos","events_url":"https://api.github.com/users/fartashf/events{/privacy}","received_events_url":"https://api.github.com/users/fartashf/received_events","type":"User","site_admin":false},"body":"","created_at":"2017-09-26T17:11:37Z","updated_at":"2017-09-26T20:23:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e5a77f113b04b73c2672fef20043ff38cdd8d897","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/tensorflow/cleverhans/pulls/278/commits","review_comments_url":"https://api.github.com/repos/tensorflow/cleverhans/pulls/278/comments","review_comment_url":"https://api.github.com/repos/tensorflow/cleverhans/pulls/comments{/number}","comments_url":"https://api.github.com/repos/tensorflow/cleverhans/issues/278/comments","statuses_url":"https://api.github.com/repos/tensorflow/cleverhans/statuses/2ef5a2c1e0ffc0fd8932debd03ab6a9e484957a2","head":{"label":"fartashf:multigpu","ref":"multigpu","sha":"2ef5a2c1e0ffc0fd8932debd03ab6a9e484957a2","user":{"login":"fartashf","id":7307513,"avatar_url":"https://avatars0.githubusercontent.com/u/7307513?v=4","gravatar_id":"","url":"https://api.github.com/users/fartashf","html_url":"https://github.com/fartashf","followers_url":"https://api.github.com/users/fartashf/followers","following_url":"https://api.github.com/users/fartashf/following{/other_user}","gists_url":"https://api.github.com/users/fartashf/gists{/gist_id}","starred_url":"https://api.github.com/users/fartashf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fartashf/subscriptions","organizations_url":"https://api.github.com/users/fartashf/orgs","repos_url":"https://api.github.com/users/fartashf/repos","events_url":"https://api.github.com/users/fartashf/events{/privacy}","received_events_url":"https://api.github.com/users/fartashf/received_events","type":"User","site_admin":false},"repo":{"id":92324014,"name":"cleverhans","full_name":"fartashf/cleverhans","owner":{"login":"fartashf","id":7307513,"avatar_url":"https://avatars0.githubusercontent.com/u/7307513?v=4","gravatar_id":"","url":"https://api.github.com/users/fartashf","html_url":"https://github.com/fartashf","followers_url":"https://api.github.com/users/fartashf/followers","following_url":"https://api.github.com/users/fartashf/following{/other_user}","gists_url":"https://api.github.com/users/fartashf/gists{/gist_id}","starred_url":"https://api.github.com/users/fartashf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fartashf/subscriptions","organizations_url":"https://api.github.com/users/fartashf/orgs","repos_url":"https://api.github.com/users/fartashf/repos","events_url":"https://api.github.com/users/fartashf/events{/privacy}","received_events_url":"https://api.github.com/users/fartashf/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/fartashf/cleverhans","description":"A library for benchmarking vulnerability to adversarial examples","fork":true,"url":"https://api.github.com/repos/fartashf/cleverhans","forks_url":"https://api.github.com/repos/fartashf/cleverhans/forks","keys_url":"https://api.github.com/repos/fartashf/cleverhans/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fartashf/cleverhans/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fartashf/cleverhans/teams","hooks_url":"https://api.github.com/repos/fartashf/cleverhans/hooks","issue_events_url":"https://api.github.com/repos/fartashf/cleverhans/issues/events{/number}","events_url":"https://api.github.com/repos/fartashf/cleverhans/events","assignees_url":"https://api.github.com/repos/fartashf/cleverhans/assignees{/user}","branches_url":"https://api.github.com/repos/fartashf/cleverhans/branches{/branch}","tags_url":"https://api.github.com/repos/fartashf/cleverhans/tags","blobs_url":"https://api.github.com/repos/fartashf/cleverhans/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fartashf/cleverhans/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fartashf/cleverhans/git/refs{/sha}","trees_url":"https://api.github.com/repos/fartashf/cleverhans/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fartashf/cleverhans/statuses/{sha}","languages_url":"https://api.github.com/repos/fartashf/cleverhans/languages","stargazers_url":"https://api.github.com/repos/fartashf/cleverhans/stargazers","contributors_url":"https://api.github.com/repos/fartashf/cleverhans/contributors","subscribers_url":"https://api.github.com/repos/fartashf/cleverhans/subscribers","subscription_url":"https://api.github.com/repos/fartashf/cleverhans/subscription","commits_url":"https://api.github.com/repos/fartashf/cleverhans/commits{/sha}","git_commits_url":"https://api.github.com/repos/fartashf/cleverhans/git/commits{/sha}","comments_url":"https://api.github.com/repos/fartashf/cleverhans/comments{/number}","issue_comment_url":"https://api.github.com/repos/fartashf/cleverhans/issues/comments{/number}","contents_url":"https://api.github.com/repos/fartashf/cleverhans/contents/{+path}","compare_url":"https://api.github.com/repos/fartashf/cleverhans/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fartashf/cleverhans/merges","archive_url":"https://api.github.com/repos/fartashf/cleverhans/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fartashf/cleverhans/downloads","issues_url":"https://api.github.com/repos/fartashf/cleverhans/issues{/number}","pulls_url":"https://api.github.com/repos/fartashf/cleverhans/pulls{/number}","milestones_url":"https://api.github.com/repos/fartashf/cleverhans/milestones{/number}","notifications_url":"https://api.github.com/repos/fartashf/cleverhans/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fartashf/cleverhans/labels{/name}","releases_url":"https://api.github.com/repos/fartashf/cleverhans/releases{/id}","deployments_url":"https://api.github.com/repos/fartashf/cleverhans/deployments","created_at":"2017-05-24T18:29:35Z","updated_at":"2017-06-08T15:30:32Z","pushed_at":"2017-09-26T18:04:43Z","git_url":"git://github.com/fartashf/cleverhans.git","ssh_url":"git@github.com:fartashf/cleverhans.git","clone_url":"https://github.com/fartashf/cleverhans.git","svn_url":"https://github.com/fartashf/cleverhans","homepage":null,"size":1159,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"tensorflow:master","ref":"master","sha":"b8d15f3d7b6f820f812087512b60d9675cb431eb","user":{"login":"tensorflow","id":15658638,"avatar_url":"https://avatars1.githubusercontent.com/u/15658638?v=4","gravatar_id":"","url":"https://api.github.com/users/tensorflow","html_url":"https://github.com/tensorflow","followers_url":"https://api.github.com/users/tensorflow/followers","following_url":"https://api.github.com/users/tensorflow/following{/other_user}","gists_url":"https://api.github.com/users/tensorflow/gists{/gist_id}","starred_url":"https://api.github.com/users/tensorflow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tensorflow/subscriptions","organizations_url":"https://api.github.com/users/tensorflow/orgs","repos_url":"https://api.github.com/users/tensorflow/repos","events_url":"https://api.github.com/users/tensorflow/events{/privacy}","received_events_url":"https://api.github.com/users/tensorflow/received_events","type":"Organization","site_admin":false},"repo":{"id":68254498,"name":"cleverhans","full_name":"tensorflow/cleverhans","owner":{"login":"tensorflow","id":15658638,"avatar_url":"https://avatars1.githubusercontent.com/u/15658638?v=4","gravatar_id":"","url":"https://api.github.com/users/tensorflow","html_url":"https://github.com/tensorflow","followers_url":"https://api.github.com/users/tensorflow/followers","following_url":"https://api.github.com/users/tensorflow/following{/other_user}","gists_url":"https://api.github.com/users/tensorflow/gists{/gist_id}","starred_url":"https://api.github.com/users/tensorflow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tensorflow/subscriptions","organizations_url":"https://api.github.com/users/tensorflow/orgs","repos_url":"https://api.github.com/users/tensorflow/repos","events_url":"https://api.github.com/users/tensorflow/events{/privacy}","received_events_url":"https://api.github.com/users/tensorflow/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/tensorflow/cleverhans","description":"An adversarial example library for constructing attacks, building defenses, and benchmarking both","fork":false,"url":"https://api.github.com/repos/tensorflow/cleverhans","forks_url":"https://api.github.com/repos/tensorflow/cleverhans/forks","keys_url":"https://api.github.com/repos/tensorflow/cleverhans/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tensorflow/cleverhans/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tensorflow/cleverhans/teams","hooks_url":"https://api.github.com/repos/tensorflow/cleverhans/hooks","issue_events_url":"https://api.github.com/repos/tensorflow/cleverhans/issues/events{/number}","events_url":"https://api.github.com/repos/tensorflow/cleverhans/events","assignees_url":"https://api.github.com/repos/tensorflow/cleverhans/assignees{/user}","branches_url":"https://api.github.com/repos/tensorflow/cleverhans/branches{/branch}","tags_url":"https://api.github.com/repos/tensorflow/cleverhans/tags","blobs_url":"https://api.github.com/repos/tensorflow/cleverhans/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tensorflow/cleverhans/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tensorflow/cleverhans/git/refs{/sha}","trees_url":"https://api.github.com/repos/tensorflow/cleverhans/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tensorflow/cleverhans/statuses/{sha}","languages_url":"https://api.github.com/repos/tensorflow/cleverhans/languages","stargazers_url":"https://api.github.com/repos/tensorflow/cleverhans/stargazers","contributors_url":"https://api.github.com/repos/tensorflow/cleverhans/contributors","subscribers_url":"https://api.github.com/repos/tensorflow/cleverhans/subscribers","subscription_url":"https://api.github.com/repos/tensorflow/cleverhans/subscription","commits_url":"https://api.github.com/repos/tensorflow/cleverhans/commits{/sha}","git_commits_url":"https://api.github.com/repos/tensorflow/cleverhans/git/commits{/sha}","comments_url":"https://api.github.com/repos/tensorflow/cleverhans/comments{/number}","issue_comment_url":"https://api.github.com/repos/tensorflow/cleverhans/issues/comments{/number}","contents_url":"https://api.github.com/repos/tensorflow/cleverhans/contents/{+path}","compare_url":"https://api.github.com/repos/tensorflow/cleverhans/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tensorflow/cleverhans/merges","archive_url":"https://api.github.com/repos/tensorflow/cleverhans/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tensorflow/cleverhans/downloads","issues_url":"https://api.github.com/repos/tensorflow/cleverhans/issues{/number}","pulls_url":"https://api.github.com/repos/tensorflow/cleverhans/pulls{/number}","milestones_url":"https://api.github.com/repos/tensorflow/cleverhans/milestones{/number}","notifications_url":"https://api.github.com/repos/tensorflow/cleverhans/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tensorflow/cleverhans/labels{/name}","releases_url":"https://api.github.com/repos/tensorflow/cleverhans/releases{/id}","deployments_url":"https://api.github.com/repos/tensorflow/cleverhans/deployments","created_at":"2016-09-15T00:28:04Z","updated_at":"2017-09-26T19:36:13Z","pushed_at":"2017-09-26T19:44:30Z","git_url":"git://github.com/tensorflow/cleverhans.git","ssh_url":"git@github.com:tensorflow/cleverhans.git","clone_url":"https://github.com/tensorflow/cleverhans.git","svn_url":"https://github.com/tensorflow/cleverhans","homepage":"","size":1130,"stargazers_count":1216,"watchers_count":1216,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":304,"mirror_url":null,"open_issues_count":13,"forks":304,"open_issues":13,"watchers":1216,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/tensorflow/cleverhans/pulls/278"},"html":{"href":"https://github.com/tensorflow/cleverhans/pull/278"},"issue":{"href":"https://api.github.com/repos/tensorflow/cleverhans/issues/278"},"comments":{"href":"https://api.github.com/repos/tensorflow/cleverhans/issues/278/comments"},"review_comments":{"href":"https://api.github.com/repos/tensorflow/cleverhans/pulls/278/comments"},"review_comment":{"href":"https://api.github.com/repos/tensorflow/cleverhans/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/tensorflow/cleverhans/pulls/278/commits"},"statuses":{"href":"https://api.github.com/repos/tensorflow/cleverhans/statuses/2ef5a2c1e0ffc0fd8932debd03ab6a9e484957a2"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"goodfeli"}}