Danish Gada
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Generative Adversarial Networks (GANs) **Neural Networks** have made tremendours Advancements in the last few years.They can now Recognise images ,Videos and Voice Messages with performance comparable to Humans. But Even today ,Complete Automation without Human intervension is still far fetched. Few tasks like those listed below still seem impossible to be done by a machine. 1. Predicting what is going to happen in the next Scenes of a Video or Making Paintings that dont really exist. 2. Writing an article online that will help many AI enthusiasts to get their hands dirty in this field . xD Or maybe ? These difficult tasks can also be done! **Generative Adversarial Networks**, or GANs in short, is an approach to generative modeling using deep learning methods, like CNN. > The GAN architecture was first described in the 2014 paper by Ian Goodfellow, et al. titled “Generative Adversarial Networks.” Generative modeling is an unsupervised learning task which involves automatically discovering and learning regularities and patterns in the input data in a way that the model can be used to generate new examples indistinguistable from the original data. The main Ingrediants you will need to Develope a GAN for generating images are: * **Discriminator** -> CNN model for classifying whether a given image is real or fake. * **Generator** -> Model that uses ICNN layers like Transpose Convolution to transform an noise input sampled from a ditribution into a 2D Image. To have a clear Understanding about the working of GANs , let us take a real life example. The Generator can be Interpreted as a forger who tries to make Fake Money. The Discriminator can be Interpreted as a Police Man who tries to catch the Fake Currency. So now its clear the forger will try its best to make the Fake money as close to real as possible and the Police will get better and better at distinguising between real and fake. This is like a Game where both players want to outsmart their opponents. After infinite time the forger will become so good that it will be able to generate Fake Money which has no difference to the real one and the police therefore will not be able to say with certainty if the money is real or fake . It will end up being a 50% probability that the money could be real or fake since it is indistinguishable. ![](https://i.imgur.com/LuTMHbX.jpg) > Generative adversarial networks are based on a game theoretic scenario in which the generator network must compete against an adversary. The generator network directly produces samples. Its adversary, the discriminator network, attempts to distinguish between samples drawn from the training data and samples drawn from the generator. ~Goodfellow, et al. ## 1.Generator The Generator Model takes a fixed length vector as Input.Values of the vector are Sampled Randomly from distributions like Gaussian.The vector is used to seed the generative process. After training, points in this multidimensional vector space will correspond to points in the latent space (Zeta), forming a compressed representation of the data distribution. A latent space can be interpreted as a projection or compression of a data distribution. In the case of GANs, the generator model applies meaning to points in a chosen latent space, such that new points drawn from the latent space can be provided to the generator model as input and used to generate new and different outputs. ## 2.Discriminator The discriminator model takes an example from the domain as input (real or generated) and predicts a binary class label of real or fake. The real example comes from the training dataset. The generated examples are output by the generator model. The discriminator is just a binary classification model. ## Working Generator and Discriminator are trained together. The Generator generates a batch of samples. Discrimator is fed these along with real example from the training Dataset for it to classify them as real or fake. Backpropagation is done and the Discriminator is updated. The generator is also updated based on how well, or not, the generated samples fooled the discriminator. When the discriminator successfully identifies real and fake samples, it is rewarded or no change is needed to the model parameters, whereas the generator is penalized with large updates to model parameters. Alternately, when the generator fools the discriminator, it is rewarded, or no change is needed to the model parameters, but the discriminator is penalized and its model parameters are updated. At a limit, the generator generates perfect replicas from the Trainig Set every time, and the discriminator cannot tell the difference and predicts 50% for real and fake in every case. > Since the Training of Gans is quite unstable , Since it is not a simple optimisation problem,rather the two different models try to outsmart one another , there can be scenarios where we might not reach a Limit. ![](https://i.imgur.com/DTU4Lbo.png) ## Mathamatical Interpretation > Let *x* be real data belonging to **X** (All Real Samples) > Let *z* be the Latent Vector belonging to **zeta** (Latent Space) > Let **G** represent the Generator, i.e **G** is a mapping from *z* to **G(*z*)** > **G(*z*)** is the fake data > Let **D** represent the Discriminator > **D(*x*)** is Discriminators output on real Data > **D(**G(*z*)**)** is Discriminators output on fake Data > Let Error(a,b) be the error between a and b > Let real image denote 1 and fake image denote 0 #### L_d (loss function of discriminator) will be L_d = Error(D(x),1)+Error(D(G(z)),0) #### L_g (loss function of generator) will be L_g=Error(D(G(z)),1) The Error function defined here is very generic and is just a function that tells us the distance or the difference between two functional parameter. (In reality this Error function is something like Cross Entropy , KL divergence ,etc) ### Considering Binary Cross Entropy H(y,y') = − ∑ ylog(y') + (1 − y)log(1 − y') #### Discriminator Loss L_d = − ∑ log(D(x)) + log(1 − D(G(z))) where x belongs to X and z belongs to zeta Loss(D)= max{log(D(x)) + log(1 − D(G(z)))} <!-- ![](https://i.imgur.com/AjrFVkN.jpg) --> #### Generator loss L_g = − ∑ log(D(G(z)) where z belongs to zeta Since log(1) = 0 Loss(G) = min{log(D(x)) + log(1-D(G(z))} <!-- ![](https://i.imgur.com/LWdmAUw.jpg) --> <!-- The original paper by Goodfellow presents a slightly different version of the loss functions shown above. ![](https://i.imgur.com/KyPWCLg.jpg) - (B) Essentially, the difference between (A) and (B) is the difference in sign, and whether we want to minimize or maximize a given quantity. In (A), we framed the function as a loss function to be minimized, whereas the original formulation presents it as a maximization problem, with the sign flipped. Coming back to equation (B) --> #### Combined loss function ![](https://i.imgur.com/ZQh6W1P.jpg) Remember that the above loss function is valid only for a single data point, to consider entire dataset we need to take the expectation of the above equation as ![](https://i.imgur.com/Xd2Pj0X.jpg) which is the same equation as described in the original paper by Goodfellow et al. Further More . ![](https://i.imgur.com/lI9ESqs.jpg) ![](https://i.imgur.com/kr9KNfY.jpg) The goal of the discriminator is to maximize this value function. Through a partial derivative of V(G,D) with respect to D(x), we see that the optimal discriminator, denoted as D∗(x), occurs when ![](https://i.imgur.com/QJoWdaH.jpg) Rearranging, we get ![](https://i.imgur.com/0sFuhPN.jpg) And this is the condition for the optimal discriminator! Note that the formula makes intuitive sense: if some sample x is highly genuine, we would expect pdata(x) to be close to one and pg(x) to be converge to zero, in which case the optimal discriminator would assign 1 to that sample. On the other hand, for a generated sample x=G(z), we expect the optimal discriminator to assign a label of zero, since pdata(G(z)) should be close to zero.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully