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"*/); 

and prototxt file : # name: " nin_imagenet " # 与 caffe 的 prototxt 相比,下五行发生了变化
通道数 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
4

1 回答 1

1

我认为这是因为您处理的是 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
于 2018-02-05T08:25:00.893 回答