Soft work second job code practice

2.1Pytorch Basic Exercise





transpose()Only operate two dimensions at a time

Function Returns the input matrixinputThe transposition. Exchange dimensiondim0anddim1

  • NPut (Tensor) – Enter a tensive, required
  • DIM0 (int) – Transposed first dimension, default 0, optional
  • DIM1 (int) – Secondary, default 1, optional



One is a uniform distribution, one is a standard normal distribution.

2.2 Spiral Data Classification

Linux systemwgetis a tool for downloading a file

(1) Tensor and Numpy are matrices, the difference is that the former can run on the GPU, which can only be on the CPU;

(2) Tensor and Numpy are very convenient to transform each other, and the type is also compatible.

device=torch.device("cpu")Representative Use CPU, anddevice=torch.device("cuda")The represented GPU is used.

When we specify the device, we need to load the model to the corresponding device, and it needs to be the model into the corresponding device.




Some of the neural network structure is partially improved, and a hidden layer is added between the input and output layers, and the RELU activation function has been added, which constitutes a simple 3-layer neural network, input-hidden layer-output, but this is enough to achieve Very good nonlinearity.