美文网首页
C++实现Python/NumPy/PyTorch的功能

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

作者: 几时见得清梦 | 来源:发表于2020-04-09 14:49 被阅读0次

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再进行模型转换

相关文章

网友评论

      本文标题:C++实现Python/NumPy/PyTorch的功能

      本文链接:https://www.haomeiwen.com/subject/dkjcmhtx.html