• Detectron2 获取网络中间层结果的途径


    Partially execute a model:

    Sometimes you may want to obtain an intermediate tensor inside a model, such as the input of certain layer, the output before post-processing. Since there are typically hundreds of intermediate tensors, there isn’t an API that provides you the intermediate result you need. You have the following options:

    1. Write a (sub)model. Following the tutorial, you can rewrite a model component (e.g. a head of a model), such that it does the same thing as the existing component, but returns the output you need.

    2. Partially execute a model. You can create the model as usual, but use custom code to execute it instead of its forward(). For example, the following code obtains mask features before mask head.

      images = ImageList.from_tensors(...)  # preprocessed input tensor
      model = build_model(cfg)
      model.eval()
      features = model.backbone(images.tensor)
      proposals, _ = model.proposal_generator(images, features)
      instances, _ = model.roi_heads(images, features, proposals)
      mask_features = [features[f] for f in model.roi_heads.in_features]
      mask_features = model.roi_heads.mask_pooler(mask_features, [x.pred_boxes for x in instances])
      

        

    3. Use forward hooks. Forward hooks can help you obtain inputs or outputs of a certain module. If they are not exactly what you want, they can at least be used together with partial execution to obtain other tensors.

    All options require you to read documentation and sometimes code of the existing models to understand the internal logic, in order to write code to obtain the internal tensors.




    如果这篇文章帮助到了你,你可以请作者喝一杯咖啡

  • 相关阅读:
    Atlassian In Action-Jira之核心配置(二)
    mybatis的插入与批量插入的返回ID的原理
    Atlassian In Action-Jira之指导思想(一)
    Atlassian In Action
    如何进行软件技术管理?
    [simple-orm-mybaits]基于Mybatis的ORM封装介绍
    Java利用Mybatis进行数据权限控制
    给大家推荐一个Java学习和面试的GitHub项目
    立志
    一勤天下无难事
  • 原文地址:https://www.cnblogs.com/sddai/p/14412014.html
Copyright © 2020-2023  润新知