簡體   English   中英

使用Python層時,Caffe Blob中的num和count參數有什么區別?

[英]What is the difference between the `num` and `count` parameters in a Caffe blob when using a Python layer?

歐幾里德損失實施例用於在來自Caffe一個Python層,存在的使用bottom[0].num以及bottom[0].count

看起來兩者的含義完全相同。

在Caffe blob.hpp中 ,具有定義如下的相同名稱的函數:

inline int count() const { return count_; }

inline int num() const { return LegacyShape(0); }

似乎count_跟蹤blob中元素的數量,這似乎也是num()返回的值。

是這樣嗎 我可以互換使用嗎?

根據這些Caffe文檔num是“不建議使用的舊式形狀訪問器num:請改用shape(0)”。

另一方面, count是所有維度的乘積。

因此, num為您提供了許多元素,每個元素可能具有多個通道,高度和寬度。 count是值的總計數。 他們僅應同意shape每個尺寸均為1 shape(0)除外shape(0)

@Kundor已經給出了很好的答案。 我將放置一個代碼段,並將其輸出到這里,供那些仍然有困惑的人使用。 如您所見, count()方法更像是大步前進,並且num()height() width()顯示尺寸。

#include <vector>
#include <iostream>
#include <caffe/blob.hpp>

using namespace std;
using namespace caffe;

int main(int argc, char *argv[])
{
    Blob<float> blob;
    cout << "size: " << blob.shape_string() << endl;

    blob.Reshape(1, 2, 3, 4);

    cout << "size: " << blob.shape_string() << endl;

    auto shape_vec = blob.shape();
    cout << "shape dimension: " << shape_vec.size() << endl;
    cout << "shape[0] " << shape_vec[0] << endl;
    cout << "shape[1] " << shape_vec[1] << endl;
    cout << "shape[2] " << shape_vec[2] << endl;
    cout << "shape[3] " << shape_vec[3] << endl;

    cout << "shape(0) " << blob.shape(0) << endl;
    cout << "shape(1) " << blob.shape(1) << endl;
    cout << "shape(2) " << blob.shape(2) << endl;
    cout << "shape(3) " << blob.shape(3) << endl;
    // cout << "shape(4) " << blob.shape(4) << endl;

    cout << "cout() test \n";
    cout << "num_axes() " << blob.num_axes() << endl; // 4
    cout << "cout() " << blob.count() << endl; // 24
    cout << "cout(0) " << blob.count(0) << endl; // 24
    cout << "cout(1) " << blob.count(1) << endl; // 24
    cout << "cout(2) " << blob.count(2) << endl; // 12
    cout << "cout(3) " << blob.count(3) << endl; // 4
    cout << "cout(4) " << blob.count(4) << endl;
    // cout << "cout(5) " << blob.count(5) << endl; // start_axis <= end_axis(5 vs. 4)

    // legacy interface
    cout << "num() " << blob.num() << endl;
    cout << "channels() " << blob.channels() << endl;
    cout << "height() " << blob.height() << endl;
    cout << "width() " << blob.width() << endl;

    return 0;
}

輸出:

size: (0)
size: 1 2 3 4 (24)
shape dimension: 4
shape[0] 1
shape[1] 2
shape[2] 3
shape[3] 4
shape(0) 1
shape(1) 2
shape(2) 3
shape(3) 4
cout() test
num_axes() 4
cout() 24
cout(0) 24
cout(1) 24
cout(2) 12
cout(3) 4
cout(4) 1
num() 1
channels() 2
height() 3
width() 4

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM