C++实现Python/NumPy/PyTorch的功能

Python

NumPy

1. np.where

std::vector<std::vector<int>> np_where(cv::Mat img_bin, int val)
{
    std::vector<std::vector<int>> res;
    std::vector<int> res_row;
    std::vector<int> res_col;
    uchar pixel;

    for (int row = 0; row < img_bin.rows; row++)
    {
        for (int col = 0; col < img_bin.cols; col++)
        {
            //pixel = img_bin.at<uchar>(row, col);
            pixel = img_bin.ptr<uchar>(row)[col];
            if (pixel == val)
            {
                res_row.push_back(row);
                res_col.push_back(col);
            }

        }
    }
    res.push_back(res_row);
    res.push_back(res_col);

    return res;
}

PyTorch

1. softmax

没有必要,可以在网络最后加上softmax再进行模型转换
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容