- numpy.argsort()函数是将x中的元素从小到大排列,提取其对应的index(索引号)
>>> x = np.array([3, 1, 2])
>>> np.argsort(x) #按升序排列
array([1, 2, 0])
>>> np.argsort(-x) #按降序排列
array([0, 2, 1])
-
C++ constant string initialization - “Incomplete type not allowed” error:
You need to explicitly specify the size of the arrays (if you want to use a C-style array) in your class initialization:Cause: When you declare an array without an explicit size, the compiler thinks that it is a flexible array, which is a C-style only feature. It seems to be allowed in C++ as a non-standard g++ extension.
class DataFilter
{
// ...
float firstVect[3] = {0.0f,0.0f,0.0f};
int initialized = 0;
int normalNumberOfDigits[3]= {0,0,0};
// ...
};
- vector of C-style array: first call [] then vector.
const std::vector<std::pair<int, int>> mapIdx[2] = {
{ //COCO
{ 31,32 },{ 39,40 },{ 33,34 },{ 35,36 },{ 41,42 },{ 43,44 },
{ 19,20 },{ 21,22 },{ 23,24 },{ 25,26 },{ 27,28 },{ 29,30 },
{ 47,48 },{ 49,50 },{ 53,54 },{ 51,52 },{ 55,56 },{ 37,38 },
{ 45,46 }
},
{ // BODY25
}
};
//to get coco's mapIdx -> mapIdx[0][17]
std::vector<std::pair<int, int>> pr = {
{0,1}, {14,15}, {22,23}, {16,17}, {18,19},
{24,25}, {26,27}, {6,7}, {2,3}, {4,5},
{8,9}, {10,11}, {12,13}, {30,31}, {32,33},
{36,37}, {34,35}, {38,39}, {20,21}, {28,29},
{40,41}, {42,43}, {44,45},
{46,47}, {48,49}, {50,51}
};
for (int i = 0; i < pr.size(); i++)
{
std::pair<int, int> tmp = pr[i];
std::cout << " {" << tmp.first + 26 << ", " << tmp.second + 26 << "},";
}
- mobile net TensorFlow 转 Caffe 要注意stride=2而且filter size=3时的情况,因为Caffe是symmetric pad,而TensorFlow是asymmetric pad。所以要使weight完全对应,有两种方法,一种pad 0 到 weights 的左边和上边,另一种是pad 0 到feature map的左边和上边,然后加2个slice layer去crop掉。
TensorFlow:padding:'same'(zero pad) or 'valid'(no pad)
padding = ‘VALID’
out_height = ceil((in_height – filter_height + 1) / strides[1]) (结果向上取整)
padding = ‘SAME'
out_height = ceil(in_height / strides[1]) (结果向上取整)
Caffe
out_height = floor((in_height - filter_height + 2pad)/strides) +1
- C++ 创建函数,:后面,赋值变量时,可简写成()
//Definition for singly-linked list.
struct ListNode {
int val;
ListNode *next;
ListNode(int x) : val(x), next(NULL) {}
};
- a->b 的含義是 (*a).b
a 是指针,b是a指向的object的成员。(*a)则是指向的object。
new 申请内存空间返回地址(malloc() 是 C standard library)。*p是p地址的值,prehead是值;p是pointer,&prehead是prehead的地址。
直接使用&prehead时,&prehead是reference,必须初始化。
太特么复杂了,记住别用&来做新建变量就行了…新建的都是reference
// ListNode preHead = ListNode(0);
// ListNode *p = &preHead;
// ListNode *p = new ListNode(0);
ListNode * p;
p = new ListNode(0);
ListNode &preHead = *p;
cout << "p->next: " << p->next << "\n";
cout << "(&preHead).next: " << (*p).next << "\n";
cout << "preHead.next: " <<preHead.next << "\n";
cout << "(&preHead)->next: " << (&preHead)->next << "\n";
-
int* a, b;
你以为是int* a; int* b;
但实际上是
int* a; int b; -
pip google module problem:
真正缺的不是google module,而是protobuf module,所以:
>> python -c 'from caffe2.python import workspace; print(workspace.NumCudaDevices())'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/icduser/anaconda3/lib/python3.7/site-packages/caffe2/python/__init__.py", line 2, in <module>
from caffe2.proto import caffe2_pb2
File "/home/icduser/anaconda3/lib/python3.7/site-packages/caffe2/proto/__init__.py", line 11, in <module>
from caffe2.proto import caffe2_pb2, metanet_pb2, torch_pb2
File "/home/icduser/anaconda3/lib/python3.7/site-packages/caffe2/proto/caffe2_pb2.py", line 6, in <module>
from google.protobuf.internal import enum_type_wrapper
ModuleNotFoundError: No module named 'google'
>>conda install protobuf
- Android assets problem:
新版的Android assets folder需要右击new dir,location默认app/src/main/assets,否则会有java.io.FileNotFoundException
- VS2015 加 CUDA 9.0 加 Python35 版的 Caffe 用 cmake 编译,提示:找不到boost lib,
更改cmake的folder里的Dependencies.cmake:把所有boost的版本都改成1.61。
原因:pre-build的1.55版boost,不支持 VS2015 加 CUDA 9.0 加 Python35,改成用pre-build的1.61版就OK。