• Skip to primary navigation
  • Skip to main content
The Data Lab

The Data Lab

Pruple button with the word menu
  • Business Support
        • Business Support

          We’ll help you harness the power of data so you can innovate and grow your business.

          Visit our Business Support page

        • Accessing Talent
          • Data Talent
          • Placements
        • Funding
        • Small Business Support
        • Digital Strategy
        • Academic Project Funding
        • The Data Lab Community
  • Professional Development
        • Professional Development

          We’ll help you harness the power of data so you can innovate at work and also advance your career.

          Visit our Professional Development page

        • Workshops
        • Online Courses
        • Data Skills for Work Programme
        • The Data Lab Community
  • Students
        • Students

          We’ll help you learn about the power of data and gain real-world experience and career-focused qualifications.

          Visit our Students page

        • The Data Lab Academy
        • PhD
        • TDL Academy Placements
        • Scholarships
        • The Data Lab Community
  • Partner With Us
        • Partner With Us

          We work in partnership with companies to help them gain maximum benefit from the strategic use of data.

          Visit our Partner With Us page

        • Collaborate With Specialists
        • Partnerships
  • About Us
        • About Us

          We discover opportunities, connect people and ideas, develop knowledge and expertise and bring game-changing data projects to fruition.

          About Us

        • Our Team
        • Careers With Us
        • Academic Opportunities
        • The Data Lab Community
        • Case Studies
        • News & Podcasts
        • DataFest
        • Scottish AI Alliance
        • Contact us

Generative Adversarial Networks – when AI gets creative

Tech blog 22/01/2019

Since Frank Rosenblatt introduced the Perceptron in 1958, neural networks have significantly evolved and taken the world by storm. Their ability to model complex, non-linear relationships that exist in data, led to novel neural network architectures, able to outperform humans in various challenging tasks like face recognition, disease prognosis and playing video games.
However, even though computers are currently very good at executing deterministic tasks, they have been lacking one key element that defines human intelligence – the element of creativity. A major step to overcoming this was made in 2014, when Ian Goodfellow came up with the idea of Generative Adversarial Networks (GANs), while drinking with his friends in a pub in downtown Montreal. He then coded the first working version of the algorithm that same night, providing us with what Yann Lecun has described as “the most interesting idea in the last 10 years in ML”, as well as with another proof of the validity of the Ballmer Peak theory.

A short intro to GANs

The main concept behind GANs is that of an adversarial game between two agents which, in the vanilla version of the algorithm, are two fully-connected feed forward neural networks being trained to perform two competing tasks. The first network, called the Generator, is being trained to generate fake, but realistic-looking data, similar to those of an original dataset. The other network, called the Discriminator, learns how to distinguish between fake data produced by the Generator and real data coming from the original dataset.
The two networks are being trained in parallel. In each iteration of the algorithm the Discriminator is tasked to classify data samples produced by the Generator. If the Discriminator gets fooled by misclasifying these samples as real, it receives negative feedback that forces it to improve by adapting its weights accordingly. In the next iteration, the improved Discriminator will likely be able to correctly classify the Generator’s samples as fake. This will trigger a negative feedback to the Generator that will in turn try to adapt its weights to produce more realistic data samples.

Those who have studied zero-sum game theory have probably realised by now that this training framework corresponds to a minimax two-player game and as such, it can be proven that it has a Nash Equilibrium – a state where neither one of the networks can further improve its performance by making any changes to its parameters. In our case, this is achieved when the data samples produced by the Generator are so indistinguishable from the real ones that the Discriminator, even though properly trained, has no confidence in its decision of whether these samples are real or not. This is the ultimate goal of adversarial training.

Using GANs to create synthetic food images

What makes GANs even more versatile, is the fact that we are not constrained by the need to provide labelled data when training them. One can simply pick a random unlabelled dataset and the Generator will eventually learn how to model the various distributions in the dataset and produce new realistic samples. Interesting applications of GANs include anime character generation as well as music composition. So, I decided to take advantage of this level of freedom and experiment with teaching a GAN something interesting – how to create images of food.

Initially, I put together a dataset of 1000 coloured 64×64 images of food to be used as my training data. The size of the dataset is relatively small, but proved good enough to lead to some interesting results. Finding the right parameters and design for my GAN was a very challenging task, as even minor architectural changes can lead to one of the two networks overpowering the other, leading to failure mode. The architecture I ended up using is that of a Deep Convolutional GAN (DCGAN), which due to its translation invariance and parameter sharing properties, yielded meaningful images without requiring too much training (~1.5 hours on an NVIDIA Titan X). You can find the code with the full network architecture on this github repository.

So, without further delay, let’s move to the main course (pun intended) . The images presented below are some examples of the Generator’s output. Keep in mind that these are not the results of combining or modifying existing food images. The Generator has learned frequently occurring motifs in real food images and is now using these motifs to generate new images that never existed before.

Evidently, the network has learned the entity of the plate and the fact that it can come in different colours. Also it has picked up the fact that pictures of food can be taken from various different angles and distances. Regarding the actual food, even though fine details are not particularly clear, one can observe the existence of different textures and colours we usually see in everyday food. Using a little bit of imagination, you could probably spot some pasta, a piece of roast ham and a green leaf salad. Maybe even a beef stake tartare.

A sample of the real images used for training is presented below for reference.

Epilogue

If the synthetic food presented above doesn’t look particularly appealing/convincing to you, I suggest having a look at some other examples of awesome GAN applications as well as some seminal papers (you can find a nice collection here).

GANs have been proven to be the state-of-the-art generative approach for a plethora of scenarios and despite the fact that they can sometimes be more of an art rather than a science, considering how notoriously unstable their training is, they are here to stay. Given the amount of attention GANs are currently getting within the machine learning research community, I believe that it won’t be long until they reach maturity and start being widely embedded in real-life applications.

Tags: AI, GAN, machine learning

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Innovate • Support • Grow • Respect

Get in touch

t: +44 (0) 131 651 4905

info@thedatalab.com

Follow us on social

  • Twitter
  • YouTube
  • Instagram
  • LinkedIn
  • TikTok

The Data Lab is part of the University of Edinburgh, a charitable body registered in Scotland with registration number SC005336.

  • Website Accessibility
  • Privacy Policy
  • Terms & Conditions

© 2023 The Data Lab

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsReject AllAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-advertisement1 yearSet by the GDPR Cookie Consent plugin, this cookie is used to record the user consent for the cookies in the "Advertisement" category .
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
CookieLawInfoConsent1 yearRecords the default button state of the corresponding category & the status of CCPA. It works only in coordination with the primary cookie.
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
CookieDurationDescription
_ga2 yearsThe _ga cookie, installed by Google Analytics, calculates visitor, session and campaign data and also keeps track of site usage for the site's analytics report. The cookie stores information anonymously and assigns a randomly generated number to recognize unique visitors.
_ga_DPXX4XJSJ82 yearsThis cookie is installed by Google Analytics.
_gat_gtag_UA_54851888_11 minuteSet by Google to distinguish users.
_gat_UA-54851888-11 minuteA variation of the _gat cookie set by Google Analytics and Google Tag Manager to allow website owners to track visitor behaviour and measure site performance. The pattern element in the name contains the unique identity number of the account or website it relates to.
_gcl_au3 monthsProvided by Google Tag Manager to experiment advertisement efficiency of websites using their services.
_gid1 dayInstalled by Google Analytics, _gid cookie stores information on how visitors use a website, while also creating an analytics report of the website's performance. Some of the data that are collected include the number of visitors, their source, and the pages they visit anonymously.
CONSENT2 yearsYouTube sets this cookie via embedded youtube-videos and registers anonymous statistical data.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
CookieDurationDescription
personalization_id2 yearsTwitter sets this cookie to integrate and share features for social media and also store information about how the user uses the website, for tracking and targeting.
VISITOR_INFO1_LIVE5 months 27 daysA cookie set by YouTube to measure bandwidth that determines whether the user gets the new or old player interface.
YSCsessionYSC cookie is set by Youtube and is used to track the views of embedded videos on Youtube pages.
yt-remote-connected-devicesneverYouTube sets this cookie to store the video preferences of the user using embedded YouTube video.
yt-remote-device-idneverYouTube sets this cookie to store the video preferences of the user using embedded YouTube video.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
CookieDurationDescription
cl-bypass-cache1 hourNo description
muc_ads2 yearsNo description
SAVE & ACCEPT
Powered by CookieYes Logo