![]() ![]() Now we can build the same image but with the tensor, with code like so: const checkySmalls = tf. Our black-and-white checkered pattern example from earlier could be significantly condensed using that last bit of knowledge. Īs a corollary to the two aforementioned systems, if the final channel has only one value instead of three or four, the resulting image would be grayscale. A 1024 x 768 image with transparency would be stored in a tensor with the shape. Much like in web color, #FFFFFF00 would be white at zero opacity, and a tensor pixel with a red, green, blue, alpha (RGBA) value of would be similarly transparent. You’re not limited to RGB, as you might have expected adding a fourth value to the RGB dimension of a tensor will add an alpha channel. ![]() ![]() This also means is pure white in a float32 tensor and interpreted as next to black in an int32 tensor.ĭepending on the tensor data type, you get two color extremes from a pixel encoded as, as shown in Figure 4-1.įigure 4-2. So, an integer represents pure white, but in float form the equivalent would be. When our tensor is float32, the values are assumed to be in the range 0-1. When our tensor is the data type int32, this is the interpretation method that is used. This 0-255 array of values looks like for integers and like #FFFFFF for most websites seeking a hexadecimal version of the same three values. Your art teacher probably used yellow over green to help lighten up paints that darken as you add more in a “subtractive” color system, like paint on paper.Ī pixel is commonly colored by the ordered amounts of red, green, and blue within the confines of a singular byte. The human eye uses RGB, which is based on an “additive” color system-a system of emitting light, like computer screens do. The RGB system is another instance of art imitating life. When you finish this chapter, you’ll be confident in managing real-world image data, and a lot of this knowledge will apply to managing tensors in general. Identify what makes a tensor an image tensorĬonvert existing images to tensors and back We’ll need to identify some common practices and tricks of the trade, so you don’t have to reinvent the wheel every time. During this exercise with a simple 3 x 3 grid, you identified one method for converting a game’s state, but another person might have come up with a completely different strategy. As you recall, in the previous chapter, you converted a tic-tac-toe game to tensors. We’ll also get to utilize some existing best practices. This is, of course, true in the world of images! This is an exciting chapter because you’ll start working with real data, and we’ll be able to see the effects of your tensor operations immediately. You’re going to need to learn how to deal with large tensors, which are more common. As you might guess, printing tensors can take you only so far and in so many dimensions. In the previous chapter, you created and destroyed simple tensors. ![]()
0 Comments
Leave a Reply. |