(-215:断言失败) 1 <= blobs.size() && blobs.size() <= 2
(-215:Assertion failed) 1 <= blobs.size() && blobs.size() <= 2
我正在尝试使用 OpenCV v.3.4.3
导入我自己的预训练 Caffe
Googlenet
模型,其中我 运行 在训练后进行 Caffe
测试使用模型部署文件,一切正常。但是,当使用图像 blob 向 OpenCv
网络(加载后)提供异常时,我得到一个异常。
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
提前致谢!
我在这里解决了这个问题:
https://github.com/opencv/opencv/issues/12578#issuecomment-422304736
"there is no loss3/classifier_retrain from Caffe-deploy-model.prototxt
in Caffe-train-val-model.prototxt. If you tried to run this model
several times in Caffe you'll get different outputs for the same input
because Caffe fills missed weights randomly."
版权所有 (github.com/dkurt)
我正在尝试使用 OpenCV v.3.4.3
导入我自己的预训练 Caffe
Googlenet
模型,其中我 运行 在训练后进行 Caffe
测试使用模型部署文件,一切正常。但是,当使用图像 blob 向 OpenCv
网络(加载后)提供异常时,我得到一个异常。
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
提前致谢!
我在这里解决了这个问题: https://github.com/opencv/opencv/issues/12578#issuecomment-422304736
"there is no loss3/classifier_retrain from Caffe-deploy-model.prototxt in Caffe-train-val-model.prototxt. If you tried to run this model several times in Caffe you'll get different outputs for the same input because Caffe fills missed weights randomly."
版权所有 (github.com/dkurt)