【问题标题】:How can I get layer type in pycaffe?如何在 pycaffe 中获取图层类型?
【发布时间】:2017-06-19 03:19:26
【问题描述】:

是否有可能在 pycaffe 中获取每一层的类型(例如:卷积、数据等)? 我搜索了提供的示例,但找不到任何东西。目前我正在使用图层名称来完成我的工作,这是非常糟糕和限制性的。

【问题讨论】:

    标签: neural-network deep-learning caffe pycaffe


    【解决方案1】:

    很简单!

    import caffe
    net = caffe.Net('/path/to/net.prototxt', '/path/to/weights.caffemodel', caffe.TEST)
    
    # get type of 5-th layer
    print "type of 5-th layer is ", net.layers[5].type
    

    要在图层名称和索引之间进行映射,您可以使用这个简单的技巧:

    idx = list(net._layer_names).index('my_layer')
    print "The index of \'my_layer\' is ", idx, " and the type is ", net.layers[idx].type
    

    【讨论】:

    • 当我想使用您的第二个 sn-p 代码来映射图层名称及其索引时,我收到“ValueError: 'data' is not in list'”。怎么了?
    • @Coderx7 你的网络中可能没有名为"data" 的层吗?
    • 我在一个 for 循环中使用它,它直接从网络读取层名称:paste.ee/p/Z1RZg 我目前正在这样做:paste.ee/p/g4Llm
    • @Coderx7 你混淆了blob 名称和layer 名称:blob 名称是"top"/"bottom"s 的参数,而图层名称是"name" 的参数。例如,您可能有一个名为"data""Data" 产生blob "data""label"。因此,您有一个名为 "label"blob,但没有具有该名称的层。
    • @Coderx7 您可能会发现this answer 中的python 函数有助于理解blob 和层之间的区别以及如何正确访问它们。
    猜你喜欢
    • 2017-10-14
    • 2018-04-08
    • 2023-03-21
    • 2018-09-23
    • 1970-01-01
    • 1970-01-01
    • 2018-07-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多