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

Python

NumPy

1. np.where

std::vector> np_where(cv::Mat img_bin, int val)
{
    std::vector> res;
    std::vector res_row;
    std::vector 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(row, col);
            pixel = img_bin.ptr(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的功能)