Code Monkey home page Code Monkey logo

gangster's Introduction

GANgster

A Generative Adversarial Network to create mugshots

generated gif

A) What is a GAN

A Generative Adversarial Network is a model of machine learning used to generate fake data from a dataset. It can be used in various fields, such as creating images of people who don't exist see thispersondoesnotexist.com

1) How to build one

There are two main parts in a GAN :

  • The discriminator :

The discriminator networks are the most used neural networks in the field of Artificial Intelligence. Those are networks that are trained to recognise some type of data and extract an information out of them. For example, an IA that will classify plants such as G.R.O.O.T. is most likely built with a discriminator network.

  • The generator :

This is the most important part of the GAN. It will create data from a random noise, and will be trained against the discriminator in order to build more realistic data over time.

2) How to train one

The way GANs work (most of the time at least) is the following: The Generator is given an array of noise, and processes this array to spit out an array of imformation that it thinks is a valid representation of true data. The discriminator is then fed this data and tries to figure out whether it is true data or false data. The discriminator may be fed data from the dataset as well as data from the Generator. The idea behind is to make both the networks compete against each other to get better and better at generating or recognizing fake data.

During the training, the output of the discriminator will go through an loss function, and the result will be used to update both the discriminator neurons and the generator neurons. The generator will therefore be trained to replicate data similar to the dataset, in order to fool the discriminator. The diagrams of the first draft may help understanding how the networks work together.

3) How to use one

Once the generator is trained, it is easy to gather the data it produces, and tranform them into useful data. In our first draft, the data will simply be used as x, y coordinates, and should (If the GAN has been correctly trained) resemble a sine wave. In our second case, the output will be used as gray values for a pixel.

B) First draft: Generate Sine wave values

This first draft will be an easy one for two reasons:

  • We can generate an infinite dataset
  • The networks won't be extremely large as the data we're working on are just two digits

1) The discriminator :

SineDiscriminator

2) The generator :

SineGenerator

3) The training

TrainingDiagram

C) GANgster

For this part, we'll first need a dataset of mugshots, on which we will train the networks. I found a good dataset on kaggle. From this, we'll need to select only the ones we want, in our case, the pictures taken from the front. To do this, we simply need to iterate through the folders, and take the pictures with an 'F' just before the .png. This is the purpose of this bit of code :

for filepath in glob.glob(f"{images_folder}/*/*F.png"):
    image = PIL.Image.open(filepath)
    if self.transform is not None:
        image = self.transform(image)
    self.df.append((image, os.path.split(filepath)[1].split(".")[0]))

Located in our CustomDataset class. These images then go through some transformations in order to have a

1) The discriminator :

SineDiscriminator

2) The generator :

SineGenerator

D) Installation + training

gangster's People

Contributors

minigrim0 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.