当前位置:网站首页>Explanation of CNN circular training | pytorch series (XXII)
Explanation of CNN circular training | pytorch series (XXII)
2022-07-28 02:52:00 【51CTO】
writing |AI_study

The original title :CNN Training Loop Explained - Neural Network Code Project
- Prepare the data
- Build a model
- Training models
- Build training loop
- Analysis of the results of the model
Single batch Training
We can put individual batch The training code is summarized as follows :
Output
One thing you'll notice is that , Every time you run this code, you get different results . This is because the model is created at the top every time , We know from previous articles that the weight of the model is randomly initialized .
Now let's see how to modify this code to use all of the batch, So we can use the whole training set to train .
all batch Training for (epoch)
Now? , To train all the batches available in our data loader , We need to make some changes and add an extra line of code :
We're going to create one for Loop to iterate all of batch Handle , Instead of getting a single batch Handle .
Because our training focus is on 60,000 Samples , So we're going to have 60,000 / 100 = 600 Sub iteration . For this reason , We're going to remove... From the loop print sentence , And track the total losses and the total number of correct predictions that were finally printed .
About this 600 One thing to note about the next iteration is , At the end of the loop , Our weights will be updated 600 Time . If we improve batch_size This number will go down if we lower batch_size This number will go up .
Last , Before we get to loss Tensor calls backward() After method , We know that gradients will be calculated and added to the network parameters grad Properties of the . on this account , We need to zero these gradients . We can use the zero_grad() Method to achieve this .
We're ready to run this code . This time the code will take longer , It's going to be because of the loop 600 Batches .
We got the result , We can see 60000 The correct total is 42104.
There is only one epoch( A complete data transfer ) after , It's already very good . Even if we make one epoch, We still need to remember , Weights have been updated 600 Time , It depends on our batch size . If you allow batch_batch It's bigger , such as 10,000, Then the weight will only be updated 6 Time , It's not going to be very good either .
Multiple epoch Of Training
To execute multiple epoch, All we have to do is put this code into for In circulation . We will also put epoch Add a number to print In the sentence .
After running this code , We get every one of them epoch Result :
We can see that the number of correct values has increased , and loss Less .
Complete training loop
Put all these together , We can put the Internet 、 Optimizer and train_loader Extracted from the training cycle unit .
optimizer = optim.Adam(network.parameters(), lr=0.01)
And then there's the visualization
We should now have a good understanding of the training cycle and how to use it PyTorch To build them .PyTorch The cool thing is , We can be like debugging forward() Function to debug the training loop code like that .
In the next article , We'll see how to get predictions for each sample in the training set , And use these predictions to create a confusion matrix . See you next class !
The content of the article is carefully studied , My level is limited , Translation cannot be perfect , But it really took a lot of effort , I hope you can move your sexy hands , Share a circle of friends , Support me ^_^
The original English link is :
https://deeplizard.com/learn/video/XfYmia3q2Ow




边栏推荐
- app 自动化 环境搭建(一)
- 基于FPGA的64位8级流水线加法器
- Email security report in the second quarter: email attacks have soared fourfold, and well-known brands have been used to gain trust
- Deep residual learning for image recognition shallow reading and Implementation
- 【英雄哥七月集训】第 27天:图
- Gbase8s how to delete data in a table with a foreign key relationship
- 修改MySQL密码的四种方法(适合初学者)
- How to simply realize the function of menu dragging and sorting
- 数据中台夯实数据基础
- [image hiding] digital image information hiding system based on DCT, DWT, LHA, LSB, including various attacks and performance parameters, with matlab code
猜你喜欢

【TA-霜狼_may-《百人计划》】图形3.5 Early-z 和 Z-prepass

Today in history: the father of database passed away; Apple buys cups code; IBM chip Alliance

Constant power wireless charging based on stm32

POC模拟攻击利器 —— Nuclei入门(一)

Usage of delegate

入职华为od一个月的感受

Is it you who are not suitable for learning programming?
![[image defogging] image defogging based on dark channel and non-mean filtering with matlab code](/img/39/6266eb14deac9f38b7e95f7291067e.png)
[image defogging] image defogging based on dark channel and non-mean filtering with matlab code

怎么简单实现菜单拖拽排序的功能

【LeetCode】13. Linked List Cycle·环形链表
随机推荐
Arm32进行远程调试
D multi production single consumption
unordered_ The hash function of map and the storage mode of hash bucket
JVM tuning -xms -xmx -xmn -xss
Gbase8s how to delete data in a table with a foreign key relationship
Canvas from getting started to persuading friends to give up (graphic version)
Digital twin agriculture - Smart agriculture rice processing plant has changed from "watching the sky to eat" to "knowing the sky to work"
Special network technology virtual host PHP version setting
ERD online 4.0.0 free private deployment scheme
特征值和特征向量
[signal processing] weak signal detection in communication system based on the characteristics of high-order statistics with matlab code
Center-based 3D Object Detection and Tracking(基于中心的3D目标检测和跟踪 / CenterPoint)论文笔记
mysql: error while loading shared libraries: libtinfo.so. 5 solutions
When iPhone copies photos to the computer, the device connection often fails and the transmission is interrupted. Here's the way
Interpretation of cesium3dtilesets using customshader and examples of Omni effects
ps 简单使用
How do you use the jar package sent by others (how to use the jar package sent by others)
How to simply realize the function of menu dragging and sorting
写英文IEEE论文的技巧
Flutter God operation learning (full level introduction)