当前位置:网站首页>Detectron2 outputs validation loss during training
Detectron2 outputs validation loss during training
2022-06-26 09:13:00 【G fruit】
Let me write it out front
The problem lies in GitHub Of detectron2 Of issues Put forward on , Someone solved ( As shown in the figure below )
Hint , Go to GitHub Upper issues Search for questions , Try to find 【closed】 Labeled , These are basically problems with solutions .
Just make a record here , For learning purposes only
Reference resources GitHub link :
How do I compute validation loss during training?
This implementation is very clever , Directly replace the training set with the verification set , Use the calculation of the original training set loss To do the calculation

Added package
from detectron2.engine import HookBase
from detectron2.data import build_detection_train_loader
import detectron2.utils.comm as comm
Function function
class ValidationLoss(HookBase):
def __init__(self, cfg, DATASETS_VAL_NAME):# Add one more DATASETS_VAL_NAME Parameters ( Small changes )
super().__init__()
self.cfg = cfg.clone()
self.cfg.DATASETS.TRAIN = DATASETS_VAL_NAME##
self._loader = iter(build_detection_train_loader(self.cfg))
def after_step(self):
data = next(self._loader)
with torch.no_grad():
loss_dict = self.trainer.model(data)
losses = sum(loss_dict.values())
assert torch.isfinite(losses).all(), loss_dict
loss_dict_reduced = {
"val_" + k: v.item() for k, v in
comm.reduce_dict(loss_dict).items()}
losses_reduced = sum(loss for loss in loss_dict_reduced.values())
if comm.is_main_process():
self.trainer.storage.put_scalars(total_val_loss=losses_reduced,
**loss_dict_reduced)
Usage method
os.makedirs(cfg.OUTPUT_DIR, exist_ok=True)
trainer = Trainer(cfg)
val_loss = ValidationLoss(cfg, cfg.DATASETS.VAL) ## Additional parameters
trainer.register_hooks([val_loss])
# swap the order of PeriodicWriter and ValidationLoss
trainer._hooks = trainer._hooks[:-2] + trainer._hooks[-2:][::-1]
trainer.resume_or_load(resume=False)
trainer.train()
Realization effect
total_val_loss
val_loss_cls
val_loss_box_reg

边栏推荐
- Yolov5 advanced 4 train your own data set
- Application of hidden list menu and window transformation in selenium
- [IVI] 15.1.2 system stability optimization (lmkd Ⅱ) psi pressure stall information
- MySQL cannot be found in the service (not uninstalled)
- Cookie session and token
- 浅谈一下Type-C接口发展历程
- 【C】青蛙跳台阶和汉诺塔问题(递归)
- 【C】 Frog jumping steps and Hanoi Tower problem (recursion)
- 运行时端的执行流程
- Machine learning (Part 2)
猜你喜欢

【C】 Frog jumping steps and Hanoi Tower problem (recursion)

Data warehouse (1) what is data warehouse and what are the characteristics of data warehouse
![[program compilation and pretreatment]](/img/c9/45353cf6578628ad44f149350873f5.png)
[program compilation and pretreatment]

Self learning neural network series - 8 feedforward neural networks

phpcms小程序插件4.0版正式上线

微信小程序如何转换成百度小程序

浅谈一下Type-C接口发展历程

外部排序和大小堆相关知识

Self taught neural network series - 9 convolutional neural network CNN

实践是成为网工最快的方法,网络工程师实战项目整理
随机推荐
Mongodb分片环境搭建和验证(redis期末大作业)
Yolov5进阶之一摄像头实时采集识别
Principe et application du micro - ordinateur à puce unique - Aperçu
ThreadLocal
Section IV HQL execution process
phpcms小程序接口新增万能接口get_diy.php
Machine learning (Part 2)
Baidu applet rich text parsing tool bdparse
[QNX Hypervisor 2.2用户手册]12.1 术语(一)
51 single chip microcomputer ROM and ram
直播回顾 | smardaten李鸿飞解读中国低/无代码行业研究报告:风向变了
phpcms v9手机访问电脑站一对一跳转对应手机站页面插件
Docker install redis
What is optimistic lock and what is pessimistic lock
Phpcms mobile station module implements custom pseudo static settings
Fast construction of neural network
Nacos registry structure and the principle of massive service registration and concurrent read-write source code analysis
Cookie session and token
Phpcms applet plug-in version 4.0 was officially launched
基于SSM的电脑商城