- Deep Learning with PyTorch
- Vishnu Subramanian
- 188字
- 2021-06-24 19:16:26
Optimize the neural network
We started with random weights to predict our targets and calculate loss for our algorithm. We calculate the gradients by calling the backward function on the final loss variable. This entire process repeats for one epoch, that is, for the entire set of examples. In most of the real-world examples, we will do the optimization step per iteration, which is a small subset of the total set. Once the loss is calculated, we optimize the values with the calculated gradients so that the loss reduces, which is implemented in the following function:
def optimize(learning_rate):
w.data -= learning_rate * w.grad.data
b.data -= learning_rate * b.grad.data
The learning rate is a hyper-parameter, which allows us to adjust the values in the variables by a small amount of the gradients, where the gradients denote the direction in which each variable (w and b) needs to be adjusted.
Different optimizers, such as Adam, RmsProp, and SGD are already implemented for use in the torch.optim package. We will be making use of these optimizers in later chapters to reduce the loss or improve the accuracy.
- 電腦軟硬件維修大全(實例精華版)
- Linux運維之道(第2版)
- 計算機組裝與維修技術
- VCD、DVD原理與維修
- 基于Apache Kylin構建大數據分析平臺
- 計算機組裝與維護(第3版)
- Creating Flat Design Websites
- 筆記本電腦維修實踐教程
- RISC-V處理器與片上系統設計:基于FPGA與云平臺的實驗教程
- 電腦組裝與維護即時通
- 筆記本電腦芯片級維修從入門到精通(圖解版)
- 觸摸屏應用技術從入門到精通
- Building Machine Learning Systems with Python
- Angular 6 by Example
- Corona SDK Mobile Game Development:Beginner's Guide