OpenCV cv::dnn::Net::getBlob return dnn::Blob::matRefConst 有行 == -1 和列 == -1
OpenCV cv::dnn::Net::getBlob return dnn::Blob::matRefConst has rows == -1 and cols == -1
屏幕截图:getBlob 返回的错误结果:
这里是添加代码:
resize(img, img, Size(224, 224));
dnn::Blob inputBlob = dnn::Blob::fromImages(img);
net.setBlob(".data", inputBlob);
net.forward();
dnn::Blob prob = net.getBlob( "loss1"/*"prob"*/);
和原型文件:
# 名称:"nin_imagenet"
# 与 caffe 的 prototxt 相比,接下来的五行发生了变化
# 我删除具有 top 的图层:"data"
input: "data" # 输入名字
input_dim: 1 # 批量大小
input_dim: 3 #通道数
input_dim:224#宽度
input_dim: 224 # 高度
# unchaged text
# ...
# another changed compared to caffe's prototxt
# i delete layers who has **bottom: "label"**
layers {
name: "loss1"
type: SOFTMAX
bottom: "fc81"
top: "loss1"
}
# changed below
我认为这是因为你处理的是 4D blob,而不是矩阵,大小存储在大小数组中(见下面的例子)。
尝试使用此代码片段提取平面:
//-------------------------------------------------------
// Extract plane with defined n and c from nchw blob
//-------------------------------------------------------
void mtcnn::extractPlane(Mat &src, int n, int ch, Mat &dst)
{
const int rows = src.size[2];
const int cols = src.size[3];
dst = cv::Mat::zeros(rows, cols, CV_32FC1);
for (int row = 0; row < rows; row++)
{
const float *ptrsrc = src.ptr<float>(n, ch, row);
float *ptrdst = dst.ptr<float>(row);
for (int col = 0; col < cols; col++)
{
ptrdst[col] = ptrsrc[col];
}
}
}
希望您使用类似这样的东西来设置输入数据:
inputBlob = blobFromImage(img, 0.0078125, Size(ws, hs), Scalar(127.5, 127.5, 127.5)); //Convert Mat to batch of images
p_net.setInput(inputBlob, "data"); //set the network input
屏幕截图:getBlob 返回的错误结果:
这里是添加代码:
resize(img, img, Size(224, 224));
dnn::Blob inputBlob = dnn::Blob::fromImages(img);
net.setBlob(".data", inputBlob);
net.forward();
dnn::Blob prob = net.getBlob( "loss1"/*"prob"*/);
和原型文件:
# 名称:"nin_imagenet"
# 与 caffe 的 prototxt 相比,接下来的五行发生了变化
# 我删除具有 top 的图层:"data"
input: "data" # 输入名字
input_dim: 1 # 批量大小
input_dim: 3 #通道数
input_dim:224#宽度
input_dim: 224 # 高度
# unchaged text
# ...
# another changed compared to caffe's prototxt
# i delete layers who has **bottom: "label"**
layers {
name: "loss1"
type: SOFTMAX
bottom: "fc81"
top: "loss1"
}
# changed below
我认为这是因为你处理的是 4D blob,而不是矩阵,大小存储在大小数组中(见下面的例子)。 尝试使用此代码片段提取平面:
//-------------------------------------------------------
// Extract plane with defined n and c from nchw blob
//-------------------------------------------------------
void mtcnn::extractPlane(Mat &src, int n, int ch, Mat &dst)
{
const int rows = src.size[2];
const int cols = src.size[3];
dst = cv::Mat::zeros(rows, cols, CV_32FC1);
for (int row = 0; row < rows; row++)
{
const float *ptrsrc = src.ptr<float>(n, ch, row);
float *ptrdst = dst.ptr<float>(row);
for (int col = 0; col < cols; col++)
{
ptrdst[col] = ptrsrc[col];
}
}
}
希望您使用类似这样的东西来设置输入数据:
inputBlob = blobFromImage(img, 0.0078125, Size(ws, hs), Scalar(127.5, 127.5, 127.5)); //Convert Mat to batch of images
p_net.setInput(inputBlob, "data"); //set the network input