官术网_书友最值得收藏!

3-D tensors

When we add multiple matrices together, we get a 3-D tensor. 3-D tensors are used to represent data-like images. Images can be represented as numbers in a matrix, which are stacked together. An example of an image shape is 224, 224, 3, where the first index represents height, the second represents width, and the third represents a channel (RGB). Let's see how a computer sees a panda, using the next code snippet:

from PIL import Image
# Read a panda image from disk using a library called PIL and convert it to numpy array
panda = np.array(Image.open('panda.jpg').resize((224,224)))
panda_tensor = torch.from_numpy(panda)
panda_tensor.size()

Output - torch.Size([224, 224, 3])
#Display panda
plt.imshow(panda)

Since displaying the tensor of size 224, 224, 3 would occupy a couple of pages in the book, we will display the image and learn to slice the image into smaller tensors to visualize it:

Displaying the image
主站蜘蛛池模板: 霍邱县| 长春市| 余姚市| 镇坪县| 九龙县| 五指山市| 焦作市| 翼城县| 台江县| 霍林郭勒市| 永丰县| 江华| 柳江县| 宁海县| 遵义市| 讷河市| 肇源县| 仙桃市| 云阳县| 日喀则市| 宽甸| 睢宁县| 乐陵市| 府谷县| 吴旗县| 花莲市| 榆中县| 玛纳斯县| 辽宁省| 乌审旗| 临沧市| 独山县| 北流市| 通城县| 棋牌| 南丰县| 阿拉善右旗| 望奎县| 慈溪市| 阿鲁科尔沁旗| 固阳县|