Coder Social home page Coder Social logo

Comments (4)

jsxyhelu avatar jsxyhelu commented on June 27, 2024

There is Python code that can be run for "u2net_human_seg. Onnx"

   # Inference
    net.setInput(blob)
    d0 = net.forward()
    # Norm
    pred = normPred(d0[:, 0, :, :])

There are problems in rewriting to C + +. My code is like this

    Mat inputBlob = blobFromImages(src, 1.0/255.0, Size(320, 320),Scalar(), true, false);
    net.setInput(inputBlob);
    Mat prob = net.forward();

The error echo is:

“[ INFO:0] global E:\Gitee\opencv_2021\opencv\modules\dnn\src\onnx\onnx_importer.cpp (395) cv::dnn::dnn4_v20201117::ONNXImporter::populateNet DNN/ONNX: loading ONNX v6 model produced by 'pytorch':1.8. Number of nodes = 1055, inputs = 1, outputs = 7
OpenCV(4.5.1-dev) Error: Assertion failed (total(os[i]) > 0) in cv::dnn::dnn4_v20201117::Net::Impl::getLayerShapesRecursively, file E:\Gitee\opencv_2021\opencv\modules\dnn\src\dnn.cpp, line 3520”

I tried to do some research, but I can't find the reason. I hope I can help with C + + calling. Thanks!

from opencv_zoo.

fengyuentau avatar fengyuentau commented on June 27, 2024

Can you provide the related cpp files so that I can help debugging?

from opencv_zoo.

jsxyhelu avatar jsxyhelu commented on June 27, 2024

OK,cpp code is simple


#include <iostream>
#include "opencv2/dnn.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/objdetect.hpp"
using namespace cv;
using namespace std;
using namespace cv::dnn;

int main(int argc, char ** argv)
{
	Net net = readNetFromONNX("e:/template/u2net_human_seg.onnx");
	Mat src = imread("e:/template/lena.jpg");
	if (net.empty()) {
		printf("read  model data failure...\n");
		return -1;
	}
	Mat inputBlob = blobFromImages(src, 1.0/255.0, Size(320, 320),Scalar(), true, false);
	net.setInput(inputBlob);
	Mat prob = net.forward();
	//ERROR
	/*
	[ INFO:0] global E:\Gitee\opencv_2021\opencv\modules\dnn\src\onnx\onnx_importer.cpp (395) cv::dnn::dnn4_v20201117::ONNXImporter::populateNet DNN/ONNX: loading ONNX v6 model produced by 'pytorch':1.8. Number of nodes = 1055, inputs = 1, outputs = 7
OpenCV(4.5.1-dev) Error: Assertion failed (total(os[i]) > 0) in cv::dnn::dnn4_v20201117::Net::Impl::getLayerShapesRecursively, file E:\Gitee\opencv_2021\opencv\modules\dnn\src\dnn.cpp, line 3520”
	*/
	return 0;
}

I think this is the same as this Python code

    net = cv.dnn.readNet(args.model)
    input_size = 320 # fixed
    # build blob using OpenCV
    img = cv.imread(args.input)
    blob = cv.dnn.blobFromImage(img, scalefactor=(1.0/255.0), size=(input_size, input_size), swapRB=True)
    # Inference
    net.setInput(blob)
    d0 = net.forward()

from opencv_zoo.

ztxc avatar ztxc commented on June 27, 2024

hello, Is your problem solved?

from opencv_zoo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.