当前位置:网站首页>Monitoring loss functions using visdom
Monitoring loss functions using visdom
2022-06-11 18:23:00 【Yalin melon seeds】
problem
The loss function needs to be monitored Loss When did the training converge .
solve
pip
pip3 install visdom
Visdom
function :
python3 -m visdom.server
then , open http://localhost:8097/ that will do .
Python
Last , stay Python Just bury points in the program .
def cifar10_go():
# Instantiate a window
viz = Visdom(port=8097)
# Initialization window information
viz.line([0.], [0.], win='train_loss', opts=dict(title='train loss'))
transform = transforms.Compose([
transforms.RandomResizedCrop((224, 224)),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])
cifar10_dataset = torchvision.datasets.CIFAR10(root='./data',
train=False,
transform=transform,
target_transform=None,
download=True)
dataloader = DataLoader(dataset=cifar10_dataset, # Incoming dataset , Necessary parameters
batch_size=32, # Output batch size
shuffle=True, # Whether the data is disturbed
num_workers=4) # Number of processes , 0 Indicates that only the main process
model = MyCNN()
# Cross entropy loss function
criterion = nn.CrossEntropyLoss()
# Define optimizer
optimizer = torch.optim.SGD(model.parameters(), lr=1e-4, weight_decay=1e-2, momentum=0.9)
# Let's start training
start = time.time() # Time begins
for epoch in range(3): # Set the number of times to train on all data
for i, data in enumerate(dataloader):
# data It's the one we got batch size Size data
inputs, labels = data # Get the input data and its corresponding category results respectively
# First pass zero_grad() The function clears the gradient , Otherwise PyTorch Each calculation of the gradient will add up , If it is not cleared, the gradient calculated for the second time is equal to the gradient calculated for the first time plus the gradient calculated for the second time
optimizer.zero_grad()
# Get the output of the model , That is, the effect learned by the current model
outputs = model(inputs)
# Get the loss function of the real category of output results and data
loss = criterion(outputs, labels)
print('Epoch {}, Loss {}'.format(epoch + 1, loss))
# We're done loss Then back gradient propagation , After this process, the gradient will be recorded in the variable
loss.backward()
# Use the calculated gradient to optimize
optimizer.step()
# Update the listening information
viz.line([loss.item()], [i], win='train_loss', update='append')
end = time.time() # End of the timing
print(' Use your time : {:.5f} s'.format(end - start))
# Save model training results
torch.save(model, './MyCNN_model_23.pth')
Here is the last example :《PyTorch Use CIFAR-10 Data for training 》.
effect

Reference resources :
边栏推荐
- 力扣32题最长有效括号
- ACL 2022:评估单词多义性不再困扰?一种新的基准“DIBIMT”
- 10 ways to reset any user password
- System learning typescript (V) - joint type
- 排序的循环链表
- 谈谈远程工作 | 社区征文
- [c language] output the students within the specified score range with the structure
- 新项目 搭建环境方法
- Spring 2021 daily question [end of week4]
- 学习使用LSTM和IMDB评论数据进行情感分析训练
猜你喜欢

SISO decoder for a general (n,n-1) SPC code(补充章节3)

使用mysql判断日期是星期几
![[Golang]力扣Leetcode - 292. Nim 游戏(数学)](/img/82/54c3f6be9d08687b42cba0487380f0.png)
[Golang]力扣Leetcode - 292. Nim 游戏(数学)

Network Security Threat Intelligence System
MySQL/Redis 常见面试题汇总

SQL报错注入1

“LSTM之父”新作:一种新方法,迈向自我修正的神经网络
![[C语言]用结构体按分数高低降序输出学生的姓名和分数](/img/41/b9dba88941560b296f4d7153b7c684.png)
[C语言]用结构体按分数高低降序输出学生的姓名和分数
![[not forgetting the original intention and forging ahead] 2021 Zhongchuang Suanli new year conference and anniversary celebration](/img/ae/9a0c300f2dcb03b05d737f14b0955f.jpg)
[not forgetting the original intention and forging ahead] 2021 Zhongchuang Suanli new year conference and anniversary celebration
![[c language] output students' names and scores in descending order of scores with structures](/img/41/b9dba88941560b296f4d7153b7c684.png)
[c language] output students' names and scores in descending order of scores with structures
随机推荐
DataNode的启动流程
安全领域常规术语
async导致函数结果出乎意料,改变原来代码的意图;await is only valid in async functions and the top level bodies of modules
关于keil中,while循环条件不成立却无法跳出的问题
最长严格递增子序列
Oracle高级数据库复习
使用mysql判断日期是星期几
Common operations of Visio
Reading summary of nacos2.x source code
[C语言]用结构体按分数高低降序输出学生的姓名和分数
labelme进行图片数据标注
【无标题】
ISCSI详解(四)——ISCSI服务端配置实战
力扣34在排序数组中查找元素的第一个和最后一个位置
Retrofit source code analysis
viso的常见操作
求字符串中最大的 3 位相同数字
v-for循环遍历
如何学习和自学
[c language] output the students within the specified score range with the structure