Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

tensorflow model reading problem

Hello, instead of importing a darknet model(works) i want to try out a tensor flow model. Importing the model works - but the mat with the detection results is always empty. Is maybe my data corrupt(was hard to get the pbtxt file as the tensorflow zoo dont includes them and other way to generate failed for me)? Here my code:

    String basePath = "C:\\development\\models\\opencv_tensor\\ssd_mobilenet_v1_coco_11_06_2017\\";
    String model = basePath + "frozen_inference_graph.pb";
    String config = basePath + "ssd_mobilenet_v1_coco.pbtxt";
    String classes = basePath + "mscoco_label_map.txt";
    try {
        classNames = Files.readAllLines(Paths.get(classes));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    Mat img = imread("car.png");
    Mat blob = blobFromImage(img);

    net = readNetFromTensorflow(model, config);
    net.setInput(blob);

    Mat detectionMat = net.forward();
    System.err.println("detectionMat rows: " + detectionMat.rows());
    System.err.println("detectionMat: " + detectionMat.cols());

Any help is highly welcome. Greetings, Holger

tensorflow model reading problem

Hello, instead of importing a darknet model(works) i want to try out a tensor flow model. Importing the model works - but the mat with the detection results is always empty. Is maybe my data corrupt(was hard to get the pbtxt file as the tensorflow zoo dont includes them and other way to generate failed for me)? Here my code:

    String basePath = "C:\\development\\models\\opencv_tensor\\ssd_mobilenet_v1_coco_11_06_2017\\";
    String model = basePath + "frozen_inference_graph.pb";
    String config = basePath + "ssd_mobilenet_v1_coco.pbtxt";
    String classes = basePath + "mscoco_label_map.txt";
    try {
        classNames = Files.readAllLines(Paths.get(classes));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    Mat img = imread("car.png");
    Mat blob = blobFromImage(img);

    net = readNetFromTensorflow(model, config);
    net.setInput(blob);

    Mat detectionMat = net.forward();
    System.err.println("detectionMat rows: " + detectionMat.rows());
    System.err.println("detectionMat: " + detectionMat.cols());

Any help is highly welcome. Greetings, Holger

click to hide/show revision 3
retagged

updated 2018-04-30 22:54:00 -0600

berak gravatar image

tensorflow model reading problem

Hello, instead of darknet model(works) i want to try out a tensor flow model. Importing the model works - but the mat with the detection results is always empty. Is maybe my data corrupt(was hard to get the pbtxt file as the tensorflow zoo dont includes them and other way to generate failed for me)? Here my code:

    String basePath = "C:\\development\\models\\opencv_tensor\\ssd_mobilenet_v1_coco_11_06_2017\\";
    String model = basePath + "frozen_inference_graph.pb";
    String config = basePath + "ssd_mobilenet_v1_coco.pbtxt";
    String classes = basePath + "mscoco_label_map.txt";
    try {
        classNames = Files.readAllLines(Paths.get(classes));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    Mat img = imread("car.png");
    Mat blob = blobFromImage(img);

    net = readNetFromTensorflow(model, config);
    net.setInput(blob);

    Mat detectionMat = net.forward();
    System.err.println("detectionMat rows: " + detectionMat.rows());
    System.err.println("detectionMat: " + detectionMat.cols());

Any help is highly welcome. Greetings, Holger