Session #4
- Tensor Attributes
- Inputs / Outputs represented by tensors
- Scalar, Vector, Matrix (Used in maths)
- Number (Zero Index), Array (One Index), 2D-Array (Two Index)
- Tensors are multi-dimensional arrays
- Tensor Attributes, Rank, Axes, Shape
- Rank - Refers to the number of dimensions present in tensor, How many indices required to access an element
- Shape - Length of each axes, Shape allows visualizing tensor
- Image Input - to CNN as tensor
- Axes from Right to left
- [? A0,? A1,? A2,? A3]
- Height / Width on last axes
- [?,?,H,W]
- Color Channels
- [?,C,H,W]
- Three Indexes for Color Channel
- First Axes - Batch Size (Batches of samples)
- [3,1,28,80
- Batch of 3 images
- Single Color Channel
- Height, Width 28,28
- Three channel output for three layers
- Data to Tensors
- torch.tensor class
- Top level torch package
- Tensors contain data of uniform type
- Computation depend on type and device
- Computation has to be with same datatypes and same devices
- matching CPU and GPU versions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
import numpy as np | |
t = torch.Tensor() | |
type(t) | |
#type of data contained in tensor | |
print(t.dtype) | |
print(t.device) | |
print(t.layout) | |
#strided | |
#data loaded in memory | |
data = np.array([1,2,3]) | |
type(data) | |
#specify cpu or gpu | |
device = torch.device('cuda:0') | |
data = np.array([1,2,3]) | |
torch.Tensor(data) | |
torch.as_tensor(data) | |
torch.from_numpy(data) | |
#Identity matrix | |
torch.eye(2) | |
#zeros functions | |
#Rank 2 tensor | |
torch.zeros(2,2) | |
torch.ones(2,2) | |
torch.rand(2,2) |
Happy Mastering DL!!!
No comments:
Post a Comment