zoukankan      html  css  js  c++  java
  • caffe2: Ops, Helper Function 以及 brew 介绍。

    OpsHelper Funtions 以及 Brewcaffe2中用来表示神经网络 layer的三个重要概念。下面我们对三者进行介绍。


    1. Ops

    Opsoperators的缩写,代表Op的集合。FC Op 是全连接层 (与上一层所有神经元链接,与下一层所有神经元链接)Op,可以通过下面的方式创建FC Op


    model.net.FC([blob_in, weights, bias], blob_out)


    或者使用下面的方式进行layer复制:


    model.net.Copy(blob_in, blob_out)

    2.Helper Function
    使用Op来新建layer还是挺麻烦的,因为我们需要手动初始化此layerw以及b
    model = model_helper.ModelHelper(name="train")
    # initialize your weight
    weight = model.param_init_net.XavierFill(
        [],
        blob_out + '_w',
        shape=[dim_out, dim_in],
        **kwargs, # maybe indicating weight should be on GPU here
    )
    # initialize your bias
    bias = model.param_init_net.ConstantFill(
        [],
        blob_out + '_b',
        shape=[dim_out, ],
        **kwargs,
    )
    # finally building FC
    model.net.FC([blob_in, weights, bias], blob_out, **kwargs)
    Helper
    Function可以帮助我们解决wb初始化,layer定义等问题,所以我们可以使用helper
    function来创建layer
    fcLayer = fc(model, blob_in, blob_out, **kwargs) 
    
    

    3. brew

    brewHelper Fucntion的集合,对于创建layer来说比Helper Function更简单。对于创建FC layer 来说我们可以通过一句brew命令:


    brew.fc(model, blob_in, blob_out, ...)

    看起来好像和Helper Function差不多,但是对于更加复杂的模型来说brew更加简单。


    4. 自定义Helper Function

    我们可以通过下面的方式自定义HF

     

    def my_super_layer(model, blob_in, blob_out, **kwargs):
    """
       100x faster, awesome code that you'll share one day.
    """
    
    brew.Register(my_super_layer)
    brew.my_super_layer(model, blob_in, blob_out)

     

     

     

  • 相关阅读:
    leepcode题目解析4
    Python爬虫6-利用ProxyHandler设置代理服务器
    Python爬虫5-利用usergent伪装访问方式
    Python爬虫4-URLError与HTTPError
    Python爬虫3-parse编码与利用parse模拟post请求
    中间件
    跨域
    ORM中的锁和事务
    cookie和session
    之Ajax
  • 原文地址:https://www.cnblogs.com/SongHaoran/p/7654828.html
Copyright © 2011-2022 走看看