(-215:声明失败)1 <= blobs.size()&& blobs.size()<= 2

时间:2018-09-18 07:09:35

标签: opencv tensorflow caffe opencv3.0 javacv

我正在尝试使用Caffe导入自己的经过预先训练的Googlenet OpenCV v.3.4.3模型,在使用模型部署文件进行训练后,我在运行Caffe测试一切都很好。但是,在向OpenCv网(在加载后)中添加图像Blob时,出现异常。

OpenCv代码:

Net net = Dnn.readNetFromCaffe("deploy.prototxt","bvlc_googlenet.caffemodel");
Mat image = Imgcodecs.imread(input.getAbsolutePath(), Imgcodecs.IMREAD_COLOR);
Mat blob = Dnn.blobFromImage(image);
System.out.println(image);
System.out.println(blob);
net.setInput(blob);
Mat result = net.forward().reshape(1);

输出错误:

Mat [ 24*15*CV_8UC3, isCont=true, isSubmat=false, nativeObj=0x1bcd0740, dataAddr=0x1a9d1880 ]
Mat [ -1*-1*CV_32FC1, isCont=true, isSubmat=false, nativeObj=0x1bcd0eb0, dataAddr=0x1a4e4340 ]
Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: OpenCV(3.4.3) Z:\build tools\opencv-3.4.3\modules\dnn\src\layers\fully_connected_layer.cpp:73: error: (-215:Assertion failed) 1 <= blobs.size() && blobs.size() <= 2 in function 'cv::dnn::FullyConnectedLayerImpl::FullyConnectedLayerImpl'
]
    at org.opencv.dnn.Net.forward_1(Native Method)
    at org.opencv.dnn.Net.forward(Net.java:62)
    at test.OpenCVTests.main(OpenCVTests.java:54)

Caffe-train-val-model.prototxt Caffe-deploy-model.prototxt

谢谢!

1 个答案:

答案 0 :(得分:0)

这个问题在这里为我解决了: https://github.com/opencv/opencv/issues/12578#issuecomment-422304736

  

” Caffe-deploy-model.prototxt中没有loss3 / classifier_retrain   在Caffe-train-val-model.prototxt中。如果您尝试运行此模型   在Caffe中几次,相同的输入将获得不同的输出   因为Caffe会随机填充错过的重量。”

版权(github.com/dkurt)