- Deep Learning with PyTorch
- Vishnu Subramanian
- 148字
- 2021-06-24 19:16:23
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
推薦閱讀
- 筆記本電腦使用、維護(hù)與故障排除實(shí)戰(zhàn)
- Istio入門與實(shí)戰(zhàn)
- Linux KVM虛擬化架構(gòu)實(shí)戰(zhàn)指南
- 電腦軟硬件維修大全(實(shí)例精華版)
- 電腦常見故障現(xiàn)場(chǎng)處理
- 3ds Max Speed Modeling for 3D Artists
- 電腦維護(hù)365問
- Camtasia Studio 8:Advanced Editing and Publishing Techniques
- Practical Machine Learning with R
- OpenGL Game Development By Example
- BeagleBone Robotic Projects
- FPGA實(shí)驗(yàn)實(shí)訓(xùn)教程
- 可編程邏輯器件項(xiàng)目開發(fā)設(shè)計(jì)
- UML精粹:標(biāo)準(zhǔn)對(duì)象建模語言簡(jiǎn)明指南(第3版)
- Advanced Machine Learning with R