当前位置:网站首页>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

边栏推荐
- Talk about the development of type-C interface
- dedecms小程序插件正式上线,一键安装无需任何php或sql基础
- Notes on setting qccheckbox style
- 关于小程序tabbar不支持传参的处理办法
- phpcms小程序插件教程网站正式上线
- Principle and application of single chip microcomputer -- Overview
- Docker install redis
- uniapp用uParse实现解析后台的富文本编辑器的内容及修改uParse样式
- Yolov5 advanced III training environment
- Pytorch build progression
猜你喜欢
随机推荐
Phpcms V9 background article list adds one click push to Baidu function
关于小程序tabbar不支持传参的处理办法
Yolov5 advanced level 2 installation of labelimg
[qnx hypervisor 2.2 user manual]12.2 terminology (II)
cookie session 和 token
MySQL cannot be found in the service (not uninstalled)
Self taught programming series - 4 numpy arrays
百度小程序富文本解析工具bdParse
Yolov5 advanced 4 train your own data set
Principle and application of single chip microcomputer -- Overview
Chargement à chaud du fichier XML de l'arbre de comportement
如何利用最少的钱,快速打开淘宝流量入口?
直播回顾 | smardaten李鸿飞解读中国低/无代码行业研究报告:风向变了
Li Kou 399 [division evaluation] [joint query]
[300+ continuous sharing of selected interview questions from large manufacturers] column on interview questions of big data operation and maintenance (I)
Unity webgl publishing cannot run problem
上下架和橱窗推荐如何设置,优化过程需要注意的地方
Yolov5进阶之二安装labelImg
phpcms小程序接口新增万能接口get_diy.php
[QNX Hypervisor 2.2用户手册]12.1 术语(一)









