因 net.forward 上的斷言失敗而崩潰,我無(wú)法在其他任何地方解決/找到。認(rèn)為這個(gè)問(wèn)題看起來(lái)很相似,并試圖通過(guò)修復(fù)/問(wèn)題發(fā)現(xiàn)。然而,重新開(kāi)始討論和試驗(yàn)表明它可能不一樣。我最初使用的是 3.4.3,它以某種方式不支持相同的 Mat 類(lèi)型。現(xiàn)在更新到 3.4.7,可以確認(rèn) blob 大小沒(méi)問(wèn)題(從圖像生成)。還嘗試了其他各種 prototxt 和 caffemodels,但現(xiàn)在懷疑問(wèn)題出在那里(如果文件沒(méi)問(wèn)題就可以工作,否則網(wǎng)絡(luò)加載失?。?。關(guān)鍵代碼應(yīng)該是這樣的:// Load a network.public void onCameraViewStarted(int width, int height) {? ? String proto = getPath("deploy.prototxt", this);? ? String weights = getPath("MobileNetSSD_deploy.caffemodel", this);? ? net = Dnn.readNetFromCaffe(proto, weights);? ? Log.i(TAG, "Network loaded successfully");}public Mat onCameraFrame(CvCameraViewFrame inputFrame) {? ? // Get a new frame? ? Mat frame = inputFrame.rgba();? ? Imgproc.cvtColor(frame, frame, Imgproc.COLOR_RGBA2RGB);? ? // Forward image through network.? ? Mat blob = Dnn.blobFromImage(frame, 0.007843,? ? ? ? ? ? new Size(300, 300),? ? ? ? ? ? new Scalar(127.5, 127.5, 127.5));? ? net.setInput(blob);? ? Mat detections = net.forward(); //***215 ASSERTION FAILED occurs***? ? int cols = frame.cols();? ? int rows = frame.rows();? ? detections = detections.reshape(1, (int)detections.total() / 7);? ? for (int i = 0; i < detections.rows(); ++i) {? ? ? ? double confidence = detections.get(i, 2)[0];? ? ? ? if (confidence > 0.2) {? ? ? ? ? ? int classId = (int)detections.get(i, 1)[0];? ? ? ? ? ? int left? ?= (int)(detections.get(i, 3)[0] * cols);? ? ? ? ? ? int top? ? = (int)(detections.get(i, 4)[0] * rows);? ? ? ? ? ? int right? = (int)(detections.get(i, 5)[0] * cols);? ? ? ? ? ? int bottom = (int)(detections.get(i, 6)[0] * rows);? ? ? ? }? ? }? ? return frame;}完整的錯(cuò)誤信息是cv::Exception: OpenCV(3.4.7) /build/3_4_pack-android/opencv/modules/dnn/src/layers/batch_norm_layer.cpp:39: 錯(cuò)誤: (-215:斷言失敗) blobs.size() >= 2 在函數(shù) 'cv::dnn::BatchNormLayerImpl::BatchNormLayerImpl(const cv::dnn::experimental_dnn_34_v13::LayerParams&)'我希望它不會(huì)崩潰。框架應(yīng)該沒(méi)問(wèn)題(圖像已加載),網(wǎng)絡(luò)不是空的,網(wǎng)絡(luò)中的層看起來(lái)也很好(已檢查,因?yàn)樵?java 中使用 caffe 存在一些差異)。任何幫助表示贊賞!
1 回答

溫溫醬
TA貢獻(xiàn)1752條經(jīng)驗(yàn) 獲得超4個(gè)贊
幀格式應(yīng)該是 BGR,而不是 RGB!這意味著
Imgproc.cvtColor(frame,?frame,?Imgproc.COLOR_RGBA2BGR);
添加回答
舉報(bào)
0/150
提交
取消