从前面的教程中,你现在已经有了一个自定义的模型和数据加载器。你可以自由创建自己的优化器,并编写训练逻辑:可以使用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.SimpleTrainerDefaultTrainer().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
☆☆☆为方便大家查阅,小编已将Detectron2专栏文章统一整理到公众号底部菜单栏,同步更新中,关注公众号,点击左下方“文章”,如图: