detectron2 训练教程

作者|facebookresearch
编译|Flin
来源|Github

训练

从前面的教程中,你现在可能已经有了一个自定义模型和数据加载器。

你可以自由创建自己的优化器,并编写训练逻辑:使用PyTorch通常很容易,并且使研究人员可以看到整个训练逻辑更清晰并具有完全控制权。
tools/plain_train_net.py中提供了一个这样的示例。
(tools/plain_train_net.py:https://github.com/facebookresearch/detectron2/blob/master/tools/plain_train_net.py)

我们还提供了标准化的”trainer”抽象,最小hook系统(https://detectron2.readthedocs.io/modules/engine.html#detectron2.engine.HookBase) ,这有助于简化标准的训练类型。

你可以使用 SimpleTrainer().train() ,它为单次成本单优化器单数据源训练提供了最小的抽象。内置train_net.py脚本使用 DefaultTrainer().train(),它包含一个人们可能希望选择的更多标准默认行为。这也意味着它不太可能支持你在研究过程中可能想要的一些非标准行为。
– SimpleTrainer().train():
https://detectron2.readthedocs.io/modules/engine.html#detectron2.engine.SimpleTrainer
– DefaultTrainer().train()
https://detectron2.readthedocs.io/modules/engine.html#detectron2.engine.defaults.DefaultTrainer

要自定义训练循环,你可以从tools/plain_train_net.py开始,或查看DefaultTrainer的源代码,并用新参数或新hook覆盖其某些行为。

指标记录

在训练过程中,将使用集中式EventStorage记录指标。你可以使用以下代码对其进行访问并记录指标:
(EventStorage:https://detectron2.readthedocs.io/modules/utils.html#detectron2.utils.events.EventStorage)

from detectron2.utils.events import get_event_storage

# 在模型中:
if self.training:
  value = #根据输入计算值
  storage = get_event_storage()
  storage.put_scalar("some_accuracy", value)

有关更多详细信息,请参阅其文档。

原文链接:https://detectron2.readthedocs.io/tutorials/training.html

未经允许不得转载,请联系zhouas@hotmail.com获取授权:目标检测 » detectron2 训练教程

赞 (0) 打赏

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

微信扫一扫打赏

鄂ICP备18005284号