{"id":16135578,"url":"https://github.com/mayukhdeb/deep-chicken-saviour","last_synced_at":"2025-03-18T15:31:24.170Z","repository":{"id":112695510,"uuid":"252113694","full_name":"Mayukhdeb/deep-chicken-saviour","owner":"Mayukhdeb","description":"using adversarial attacks to confuse deep-chicken-terminator :shield: :chicken:","archived":false,"fork":false,"pushed_at":"2020-09-13T05:34:39.000Z","size":4699,"stargazers_count":7,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-28T10:34:00.683Z","etag":null,"topics":["adversarial-attacks","adversarial-examples","computer-vision","fgsm","object-detection","opencv","pytorch"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Mayukhdeb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-01T08:16:38.000Z","updated_at":"2022-05-24T06:46:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"6bc2e8fe-19cc-4bbb-be16-51fb75c46dd8","html_url":"https://github.com/Mayukhdeb/deep-chicken-saviour","commit_stats":{"total_commits":43,"total_committers":3,"mean_commits":"14.333333333333334","dds":0.4883720930232558,"last_synced_commit":"bcd87e2694958a77dd498d24927ee44cb568cdc7"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mayukhdeb%2Fdeep-chicken-saviour","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mayukhdeb%2Fdeep-chicken-saviour/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mayukhdeb%2Fdeep-chicken-saviour/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mayukhdeb%2Fdeep-chicken-saviour/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Mayukhdeb","download_url":"https://codeload.github.com/Mayukhdeb/deep-chicken-saviour/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243936376,"owners_count":20371504,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["adversarial-attacks","adversarial-examples","computer-vision","fgsm","object-detection","opencv","pytorch"],"created_at":"2024-10-09T23:08:39.094Z","updated_at":"2025-03-18T15:31:24.164Z","avatar_url":"https://github.com/Mayukhdeb.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# deep-chicken-saviour :shield: :chicken:\n\n\n[![Binder](https://camo.githubusercontent.com/bfeb5472ee3df9b7c63ea3b260dc0c679be90b97/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f72656e6465722d6e627669657765722d6f72616e67652e7376673f636f6c6f72423d66333736323626636f6c6f72413d346434643464)](https://nbviewer.jupyter.org/github/Mayukhdeb/deep-chicken-saviour/tree/master/)\n\n## Adversarial blocks generated by negative epsilon FGSM to confuse the trained deep neural network\n\n\u003cimg src = \"images/adversarial_block.gif\" width = \"80%\"\u003e\n\n\n## Before:\n\u003cimg src = \"images/no_FGSM.gif\" width = \"60%\"\u003e\n\n## After:\n\u003cimg src = \"images/FGSM.gif\" width = \"60%\"\u003e\n\n\n\n\nThese blocks are made by starting out with a dark grey image and then backpropagating on the image with the pre trained network with a negative epsilon in order to minimise loss for the target class, a more negative epsilon will not necessarily give a better result. But it's a bell curve instead, and the epsilon is optimized by looking for the local target class probability maxima in the domain [`lower_limit`, `0`)\n\nThese adversarial blocks can be generated for any animal class.\n\n\u003cimg src = \"images/patch_to_block.png\" width = \"80%\"\u003e\n\n\n## Fast Gradient Sign Method :chart_with_upwards_trend:\n\u003cimg src = \"images/adversarial_attack.png\" width = \"100%\"\u003e\n\n* `sign(data_gradients)` gives the element wise signs of the data gradient\n* `epsilon` defines the \"strength\" of the perturbation of the image\n\nIn a nutshell, instead of **optimizing the model to reduce the loss**, we're **un-optimizing the input image to maximise loss**.\n\n* This works primarily because of the piecewise linear nature of deep neural networks. For example, look at ReLU or at maxout functions, they're all piecewise linear. Even a carefully tuned sigmoid has an approximate linear nature when taken piecewise.\n\n* With varying values of epsilon, we will see an approximately linear relationship between \"confidence\" and epsilon.\n\n## Negative epsilon FGSM\n* this can be used to turn one animal into another specific animal for the deep neural network\n\u003cdiv style=\"center\"\u003e\n\u003cimg src = \"images/negative_eps_FGSM.png\" width = \"40%\"\u003e\n\n## How are the images \"optimized\" using the same FGSM ?\n* The key here is to understand how FGSM actually worked.\nIn FGSM, we were tampering with the pixels which has a *positive* gradient and added a certain value `gradient * epsilon` to each of those pixels. This made the image deviate further and further away from the class it actually belongs to and thus maximising loss in the process. Note that this was done with a __positive epsilon__ value\n\nBut for our current objective, we will try to \"optimize\" the image to a different class. This can be done by:\n* Doing a forward pass with an image of class `x` and with a label of `y`. Where `y` is the class to which we want to convert our image to. \n* Performing a backpropagation on the network and extracting the gradients on the input image.\n* Now instead of trying to maximise loss using the FGSM, we'll reduce the loss with a __negative epsilon__ FGSM.\n* This will help reduce the loss of the image with respect to the target class `y`, and with a sufficiently  negative epsilon value, the image gets mis-classified as the target class.\n\nIf you didn't read the boring stuff above, just remember that \n* A __positive epsilon__ value will __un-optimize__ the image \n* A __negative epsilon__ value will __optimize__ the image for the given label class\n\n## Generating adversarial patches from black images \n\n\u003cimg src = \"images/epsilon_vs_class_prob.png\" width = \"80%\"\u003e\n\n\u003cimg src = \"images/adversarial_patches.png\" width = \"50%\"\u003e\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmayukhdeb%2Fdeep-chicken-saviour","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmayukhdeb%2Fdeep-chicken-saviour","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmayukhdeb%2Fdeep-chicken-saviour/lists"}