< How AI Works

Lesson 5: Generative Images

45 minutes

Overview

This lesson centers around the How AI Works: Creativity and Imagination? video from the How AI Works video series. Watch this video first before exploring the lesson plan.

Diffusion models generate images. Diffusion AI converts an image to noise, and trains an AI to reverse the process. In this lesson, students learn how AI can generate images, then explore a diffusion AI widget. Finally, the class wraps up with a discussion about whether or not these models are creative.

This lesson can be taught on its own, or as part of a 7-lesson sequence on How AI Works - click here to view all lessons in this sequence.

CSTA K-12 Computer Science Standards (2017)
    • 3A-CS-01 - Explain how abstractions hide the underlying implementation details of computing systems embedded in everyday objects.
    • 2-IC-20 - Compare tradeoffs associated with computing technologies that affect people's everyday activities and career options.
    • 3A-IC-24 - Evaluate the ways computing impacts personal, ethical, social, economic, and cultural practices.
    • 3A-IC-28 - Explain the beneficial and harmful effects that intellectual property laws can have on innovation.

Agenda

Objectives

Students will be able to:
  • Describe that AI can generate fairly realistic looking images through a process known as diffusion – where a model learns how to draw details by reversing details
  • Discuss whether or not these models are creative and who owns these images

Preparation

  • Print copies of the activity guide for each student

Links

Heads Up! Please make a copy of any documents you plan to share with students.

For the teachers
For the students

Vocabulary

  • Diffusion AI - converting an image to noise, and training an AI to reverse the process
  • GAN (Generative Adversarial Network) - a way of using two competing AI models to generate something

Teaching Guide

Before the Lesson

Getting Started with Code.org: Consider watching our Getting Started with Code.org video series for an overview of how to navigate lesson plans, setup a classroom section, and other important features of the Code.org platform. Each video also has a support article if you'd prefer to read or print instructions - click here to learn more.

Setup a Classroom Section: You can use a class section in Code.org to manage your students, view their progress, and assign specific curriculum - click here to learn more.

If you are using a learning management system, there may be additional steps to sync your classes with Code.org:

  • Click here for steps to setup your classes with Google Classroom
  • Click Here for steps to setup your classes with Clever

Become a Verified Teacher: Lesson plans and levels have additional resources and answer keys for Verified Teachers, which is quick process that verifies your position at an educational institution. Click here to complete a form and you should have access to verified teacher resources in ~1 business day.

Supports for Teachers: You can learn more about bringing AI lessons to your classroom through our AI 101 for Teachers series. AI 101 for Teachers is a free, foundational online professional learning series for any teacher and educator interested in the groundbreaking world of artificial intelligence (AI) and its transformative potential in education.

Warm Up (5 minutes)

Prompt:

  1. Turn to a partner
  2. Count down from 5, and at the count of 1, both call out the name of an animal
  3. For 1 minute, each draw a mix of those 2 animals
  4. Compare your images -- what details are similar and what are different?
  5. Share your images with another partnership -- can they guess what the prompt was?
Content Corner

Gratitude: The Code.org curriculum team is grateful to computer science teacher Terence Stone, who first introduced this idea with great enthusiasm and hilarity at a Code.org training several years ago.

(Click the images below to see examples of what students may create)

Discuss: Debrief with the students what they found while comparing images. Feel free to take only 1-2 responses and not dwell on this as a class; students should have already discussed with each other

Discussion Goal: The lesson will be about how AI creates new images based on details in words. This activity has students doing something similar, to get them warmed up for the lesson itself. They can see what people created with the same prompt that was different, and think about these things as they work through the lesson.

Remarks

You all just created animals that didn't exist before you drew them. Increasingly, AI can do this sort of thing as well! Does that mean it's creative? Through this lesson, we'll explore how AI builds these new images, so we can answer this question

Teaching Tip

Optional Extension - Generating Images: You could consider using a generative image tool like Stable Diffusion to generate some images to emphasize the point in the remarks. A free demo version is available here: https://stablediffusionweb.com/#demo. However, this website is not always reliable (sometimes the website is down) and the images generated are not always school appropriate from the given prompt - we recommend vetting this resource on your own before considering to use with students.

If you do decide to generate a few images, consider using a prompt similar to what students did in this warm up: "An animal that looks like a combination of a __ and a __ in a handdrawn cartoon style". You can take suggestions from the class to fill in the blanks. As students wonder "how is this happening?", you can transition to the rest of the activity which explains how AI like this works.

Activity (35 minutes)

Show the Video and discuss (20 minutes)

Distribute: Hand out the Video and Vocabulary Guide

Video: Show the How AI Works: Creativity and Imagination video. At key points throughout (described below) we will be pausing the video to give students a chance to synthesize their understanding on the activity guide.

VideoTeacher
Pause video at 1:10 when it says "And even create complete video sequences with just a few words of instruction."

Prompt: What are some examples of things that AI can generate?

Discussion Goal: Look for a quick answer to check for understanding of the video so far.

Students may mention examples from the video such as building video sequences, but any place where humans provide AI with a prompt and it creates something will work. As a class, consider coming up with 1-2 examples not already stated in the video.

Pause video at 2:11 where it says "At this point, the generative AI has learned to generate real-looking imagery."

Prompt: How did Generative Adversarial Networks make realistic-seeming images?

Discussion Goal: This is a quick check for understanding. Students should know that a Generative Adversarial Network is made out of 2 networks -- one that generates images and another that says if it thinks the image was real or generated. Eventually, the generator is able to fool the discriminator and the image seem real.

Pause video at 2:53 when it says "...the image loses all details and becomes pure noise."

Prompt: What is happening in each version of the image?

Discussion Goal: This is a quick pause to allow students to synthesize what they are seeing. Students should note that the details in the images are getting slightly blurrier, but can still be seen. Eventually, the human eye can't see the details at all.

Pause video at 3:45 when it says "or to alter existing images."

Prompt: How does the diffusion process train computers to build new images with specific details?

Discussion Goal: This is a quick check for understanding. Students should know that diffusion models learn from slowly adding noise and then slowly subtracting noise from images, until the generator knows how to find details in noise.

Pause video at 4:36 when it says: "...so the legal questions here are not simple."

Discuss: Personal opinion: who do you think should "own" the images that AI creates?

Discussion Goal: There is no one answer to this question; the idea is for students to truly think about the implications of image generation in AI. Depending on your preferences and class timing, this can be an involved discussion that takes several minutes. See the Teacher tip for additional ideas for how to facilitate this discussion.

Continue watching the video until it ends

Prompt: What can you imagine creating with a diffusion model??

Discussion Goal: Get students excited about what diffusion models can do.

Vocabulary: Display the vocabulary from the video so students can check their vocabulary notetaker.

  • GAN (Generative Adversarial Network) - a way of using two competing AI models to generate something.
  • Diffusion AI - converting an image to noise, and training an AI to reverse the process.
Teaching Tip

Optional Activity: The focus on this lesson should be on the diffusion model, not the GAN. But, if you believe you will have extra time and would like to further understand this version of image generation, you can run an optional 20 minute GAN activity described near the end of this lesson plan.

Why Diffusion? Students may wonder where the term "diffusion" comes from. If so, it may help to show a video of a physical diffusion process, such as food coloring dispersing in water (such as in this video). If you show this video or a demonstration, point out that the food coloring is somewhat randomly slowly distributing itself throughout the water. This is what will happen with noise being added to images in diffusion models.

Who Owns the Image? For this discussion, some possible answers are:

  • the people who designed the images the AI learned on
  • The programmer who created the tool
  • The person who wrote the prompt
  • none of the above

If you linger on this question during the video, consider using the Nominal Group Technique and circulate, listening for students who are saying particularly interesting things to bring up with the whole group.

Diving Deeper: Questions of ownership, copyright, and labor are hotly debated as generative AI continues to expand. Many generative AI systems used images from living artists and can generate art in a similar style, even though their images were used without their consent and without payment. If students are interested in this ethical question, consider discussing this article with students: Artists Are Suing Artificial Intelligence Companies and...

Explore Diffusion (15 minutes)

Remarks

Today we're going to look closer at the diffusion process that is used by image-generating AI. This involves creating noise in an image. For this activity, we'll explore what you can see in an image with different levels of noise. Then, we'll guess other people's images based on what we can see at different levels of noise, just like an AI model does when it "generates" an image.

Distribute: Hand out the Noisy Image Widget Activity Guide

Model: Show how to use the Noisy Image Widget. Have the class fill out Part 1 of the activity guide as you demonstrate, asking them to describe what they can still see as you add more noise to the image.

WidgetModeling Notes
  • Demonstrate how to use the slider to add noise to an image. Point out the scale from 1 to 3000 for noise generation.
  • Show noise at different levels as shown in the activity guide, prompting the class to write what they can "still recognize" even with so much noise
  • Show how to add their own image via a URL. Consider having a URL ready, such as a school logo or class picture
  • Show how to repeat the noise generation process with a new image
Note: A full explanation of this widget is available in this User Guide: Noise Image Widget

Code Studio: Have students log into code studio and interact with the Noisy Image Widget, completing Parts 2-4 on the activity guide.

Teaching Tip

Patience is a Virtue: The noisy images can take a short while to load here (usually less than a minute, but nothing is happening for that time). We recommend you warn students this is the case, and give them something to be focusing on, for example, choosing the next image / numbers, sketching / describing the image on the back of their worksheets, or solving side puzzles for extra credit.

Circulate: Help student stay on task, guessing things about their images. Monitor them as they complete the activity guide and trade images with a partner. Make sure they are choosing school-appropriate images to share with neighbors.

Regroup: Have students regroup for a synthesis discussion

Discuss: What did you notice during this activity?

Follow-up (if necessary): Were you able to see details in the noisy images? Did you see more details once you knew the original image?

Discussion Goal: This discussion helps students synthesize what they were learning, and connect it back to the video on diffusion models finding details.

Wrap-up (5 minutes)

Discuss: Are diffusion models creative? Why or why not?

Discussion Goal: Students may have very different answers to this question. Some may think diffusion models are creative because they create things that have never been made before from prompts. Others will note that it's only re-creating details it has seen before in new configurations

After the Lesson

Teacher Survey

We'd love to learn more about the folks teaching these lessons and the classroom experience. Please let us know in this How AI Works Teacher Survey.

Additional Lessons

If you'd like to teach additional lessons from the How AI Works video series, click here to explore additional resources

AI and Machine Learning Unit

If you'd like to dive even deeper into AI and Machine Learning, consider exploring our 5-week unit on AI and Machine Learning. Click here to view the unit and learn more

(Optional) GAN Activity

(Optional) GAN Activity (20 minutes)

Model: Pass out the (Optional) GAN Game Activity Guide. Show students how to use the widget by playing one round of human guessing vs computer guessing. Feel free to use the slides at the end of the slide deck as a guide. Be sure to be clear to students that they have no information initially, and they do not have to over-think initial guesses. They'll get things wrong and that's ok! In fact, it's part of the model of the activity -- GANs are wildly guessing too until they have more information.

Teaching Tip

Exemplar: You can find an exemplar of this activity guide here: GAN Game Activity Guide Exemplar

Code Studio: Students log into Code studio to explore a game where they act like generators.

Teaching Tip

The rule that has been hard-coded into this activity is "must contain one red circle." Some students may figure this out before others. If this happens:

  • You can have students who have completed the task to help ask other students leading questions to help them figure out the rule.
  • You can have groups of completed students come up with their own password rules and figure out each other's in groups. This may be useful fun for all students, if you have extra time.

Circulate: Help student stay on task, coming up with guesses with them. (Eventually Students should figure out that the rule is a password must have a red circle -- help students who are struggling figure this out by procedurally trying different shapes and colors with them.

Regroup: Have students regroup for a synthesis discussion to help them further cement their understanding of generators and discriminators by connecting it to what they did in the activity.

Prompt: When were you acting like a generator in this activity?

Discussion Goal: When students generated random passwords -- even when they weren't accepted -- they were acting like a generator. Generators generate random images that may or may not be accepted as real.

Prompt: When were you acting like a discriminator in this activity?

Teaching Tip

Common Misconception: Students will frequently assume that the computer telling them if their guess was correct or not was the computer acting as a discriminator. This is not true. Discriminators don't necessarily have the truth -- they are, like the students guessing if the computer's password will follow the rule or not, also making guesses. The computer providing the "FOLLOWS" or "NOT" feedback is acting more like the programmer that feeds the Discriminator labeled data to learn from. More information on labeled data exists in the machine learning video.

Discussion Goal: Students acted like a discriminator when they guessed if the computer's generated password followed the rule or not. They didn't initially know, but got better as they got more data.

Creative Commons License (CC BY-NC-SA 4.0).

This work is available under a Creative Commons License (CC BY-NC-SA 4.0).

If you are interested in licensing Code.org materials for commercial purposes contact us.