日常trick

日常trick

  • numpy 矩阵正则化

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    import numpy as np
    from numpy import linalg as LA

    Mat = np.matrix([[1, 2], [3, 4]])
    print(Mat)
    '''
    [[1 2]
    [3 4]]
    '''
    norms = LA.norm(Mat, axis=1)
    print(norms)
    '''
    [ 2.23606798 5. ]
    '''
    Mat_norm = Mat / norms[:, np.newaxis]
    print(Mat_norm)
    '''
    [[ 0.4472136 0.89442719]
    [ 0.6 0.8 ]]
    '''
  • CmakeCache与Cmake冲突报错的时候,直接删除CmakeCache就好了

  • error while loading shared libraries: libevent-1.4.so.2 动态库找不到

    1. 如果共享库文件安装到了/lib或/usr/lib目录下, 那么需执行一下ldconfig命令
  • cmake :command not found

    在终端执行 命令:export PATH=/opt/cmake/bin:$PATH

  • JupyterNotebook 创建conda环境

    1
    2
    3
    conda install ipykernel
    source activate env_name
    python -m ipykernel install --user --name env_name --display-name "Python(env_name)"
  • Linux查看文件夹大小

    1
    du -sh *
  • 批量删除空文件夹

    1
    find -type d -empty | xargs -n 1 rm -rf
  • c++ argsort

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    template<typename T>
    vector<size_t> sort_indexes(const vector<T> &v)
    {

    // initialize original index locations
    vector<size_t> idx(v.size());
    iota(idx.begin(), idx.end(), 0);

    // sort indexes based on comparing values in v
    sort(idx.begin(), idx.end(),
    [&v](size_t i1, size_t i2) { return v[i1] > v[i2]; });

    return idx;
    }
  • c++: can’t have non-default parameters after your default parameters begin

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    (X) int
    get_result(caffe1s::Net<DType> *pNet, std::vector <FaceDetector::BoundingBox> res, Response &rsp, std::string &msg,
    const int topk, const float scaledetect, const int inW, const int inH, const int inC,
    const int frame_idx, const int64_t pts, const cv::Mat inputMat, const std::string model_dir,
    int num = 0, std::string savePath = "", const cv::Mat save_mat);

    (√)int
    get_result(caffe1s::Net<DType> *pNet, std::vector <FaceDetector::BoundingBox> res, Response &rsp, std::string &msg,
    const int topk, const float scaledetect, const int inW, const int inH, const int inC,
    const int frame_idx, const int64_t pts, const cv::Mat inputMat, const cv::Mat save_mat, const std::string model_dir,
    int num = 0, std::string savePath = "");
  • ls 按数字大小而非字典序排序

    1
    ls | xargs stat -c "%n" | sort -n
  • 进程假死跟踪

    1
    python -m trace --trace python_file_path
  • 多进程下载时进程假死问题

    1
    2
    3
    4
    5
    6
    import socket

    # Set the default timeout in seconds
    timeout = 20
    socket.setdefaulttimeout(timeout)
    ...