(1) Pytorch - numerical processing
Reference to Li Mu "hands-on learning deep learning" series as well as online blogs of various big brother information, thank you for sharing, such as error correction, such as invasion and deletion.
Numerical processing in torch
Numerical processing is one of the deep learningextremely importantpart of the tensor, the tensor is the basic unit for subsequent processing and computation. A tensor represents an array of values that may have multiple dimensions. A tensor with one axis corresponds to a vector in mathematics;
Tensors with two axes correspond to mathematical matrices; tensors with more than two axes have no special mathematical name.
Creation and initialization
Without further ado let's get straight to the code:
# Tensor definition
x = (12)
y = ((2, 3, 4)) #define all-zero/all-one tensor
z = (3, 4) # normal distribution random definition of tensor elements
# Change tensor shape
(3, 4)
(-1, 4) # Automatic calculation of the shape can be achieved by -1
The tensor also supports direct + - * / and even == operators. We can also link tensors together on a given axis, as shown in the following code.
X = (12)
dtype=torch.float32).reshape((3,4))
Y = ([[2.0, 1, 4, 3], [1, 2, 3, 4], [4, 3, 2, 1]])
((X, Y), dim=0), ((X, Y), dim=1)
The running effect is shown in the figure:
Sum all elements of tensor:()
Indexing and Slicing
The indexing and slicing principles in torch are basically the same as in python, so I won't go into details, if the Python foundation is not good, you can take a look at another Python blog on my homepage.
Moreover, tensors defined by numpy and torch are easily converted to each other:
A = ()
B = (A)
Calculus, linear algebra and probability theory
The mathematical operations designed into calculus, linear algebra and probability theory are also a very important part of deep learning - after all, engineering is science at the end. This piece of content is more, the author is still organizing, later to make up (digging hole ing).
Data preprocessing
So far we can finally really get started with deep learning, and data preprocessing is also the first step in building our model for training.
Pandasis a commonly used data analysis and processing expansion package in python.
Datasetis a class in Pytorch that encapsulates the loading logic of a dataset so that it can be efficiently loaded by the DataLoader.
Transformeris a toolset for image preprocessing. It has more applications in computer vision.
We'll get to that in the next section.linear neural networkIn the actual combat will be involved, encountered specific api will also do to explain, we do not have to be tough to remember all the api at the beginning, specific problems specific understanding is good.