From the course: Programming Generative AI: From Variational Autoencoders to Stable Diffusion with PyTorch and Hugging Face

Unlock this course with a free trial

Join today to access over 24,800 courses taught by industry experts.

Representing images as tensors

Representing images as tensors

- This lesson is going to be all about how do we build generative models for images? But before we can get to that, we have to think about how might we actually represent image data itself in code or in a computational way? From the previous lesson, when we were talking about how machine learning and how generative models can actually create things, I presented this image of a cat, some black box, we're either predicting the label cat or we're giving it the label cat and having it generate an image. What I didn't talk about is that usually when we are representing images in code, they're represented in some numerical sense. The most basic is actually a gray-scale image and representing it as values simply between zero and 255 that correspond to the luminosity of a given pixel, or essentially how light or dark it is. Given this picture of a cat and a kind of highly simplified version of a matrix, which, as we learned, is actually a tensor, but for this gray-scale image, we have a…

Contents