[英]What is the difference between the `num` and `count` parameters in a Caffe blob when using a Python layer?
@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.