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

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
主站蜘蛛池模板: 通河县| 安吉县| 巴林右旗| 西吉县| 宁远县| 兴安盟| 白银市| 许昌县| 若羌县| 金门县| 仪陇县| 汤原县| 喜德县| 图木舒克市| 三明市| 卓尼县| 沙湾县| 博客| 苏尼特左旗| 安远县| 化德县| 易门县| 内丘县| 阳泉市| 克什克腾旗| 淮安市| 孝义市| 碌曲县| 田林县| 高雄县| 六枝特区| 梧州市| 阜新市| 綦江县| 汤阴县| 涟水县| 临漳县| 晋宁县| 宁武县| 江油市| 土默特左旗|