detectron2使用总结 |使用detectron2构造 Faster RCNN 和 Mask RCNN 进行目标检测

模型的初始化

detectron2中模型的结构由 cfg 参数决定,而 cfg 的内容来自 configs 中的配置文件。

cfg.merge_from_file(model_zoo.get_config_file("COCO-Detection/faster_rcnn_R_50_FPN_1x.yaml"))

meta_arch = cfg.MODEL.META_ARCHITECTURE 得到的是一个网络模型的类名。
构造过程调用的函数依次为 build_model(cfg) -> meta_arch这个类的 from_config(cls, cfg) 函数 -> meta_arch这个类的 __init__() 函数。其中,from_config 函数的返回值将传递给 __init__ 函数。

  meta_arch = cfg.MODEL.META_ARCHITECTURE
  model = META_ARCH_REGISTRY.get(meta_arch)(cfg)

如果将看网络模型的结构和前向过程,需要先查看 meta_arch 的内容,然后到 detectron2/modeling/meta_arch 这个文件夹下找到 meta_arch 这个类。

猜你喜欢

转载自blog.csdn.net/A_Student10000/article/details/140188044