opencv - 为 Caffe 缩放 OpenCV Mat

标签 opencv machine-learning neural-network deep-learning caffe

我一直在关注 Caffe MINST example并尝试使用 C++ 部署训练模型的测试,我使用 OpenCV 读取图像。在示例中,他们提到了他们如何针对训练和测试图像

scale the incoming pixels so that they are in the range [0,1). Why 0.00390625? It is 1 divided by 256.

我听说 Caffe 中有一个 DataTransformer 类可以用来缩放图像,但是如果我将 OpenCV Mat 对象中的每个像素乘以 0.00390625 是否会得到相同的结果?

最佳答案

这个想法是对的。但请记住在缩放之前将您的 OpenCV Mats 转换为 float 或 double 类型。

类似于:

cv::Mat mat; // assume this is one of your images (grayscale)

/* convert it to float */
mat.convertTo(mat, CV_32FC1); // use CV_32FC3 for color images

/* scaling here */
mat = mat * 0.00390625;

更新 #1:转换和缩放也可以简单地在一行中完成,即

cv::Mat mat; // assume this is one of your images (grayscale)

/* convert and scale here */
mat.convertTo(mat, CV_32FC1, 0.00390625);

关于opencv - 为 Caffe 缩放 OpenCV Mat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32216638/

相关文章:

machine-learning - 使用 prototxt 在 caffe 中进行标签平滑,无需数据重新生成

python - OpenCV中的KLT跟踪器无法与Python一起正常使用

c++ - 如何消除直线

c++ - 为什么 OpenCV KdTree 在 C++ 中总是返回相同的最近邻居?

c++ - OpenCV我应该使用智能指针来防止内存泄漏

python-3.x - 使用 Spacy 进行命名实体识别的交叉验证

machine-learning - 名称错误 :name 'cross_validation' is not defined

machine-learning - 检查输入 : expected conv2d_27_input to have 4 dimensions, 但获得形状为 (55000, 28, 28) 的数组时出错

matlab - Matlab 中的特征包和神经网络

python - 10折交叉验证python单变量回归