tensorflow model reading problem

asked 2018-04-30 20:42:47 -0600

holger gravatar image

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

berak gravatar image

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

edit retag flag offensive close merge delete

Comments

output is

-1
-1
holger gravatar imageholger ( 2018-04-30 20:46:10 -0600 )edit

I dont resize the image like i did for darknet as i dont know the training dimension - could this be a problem?

holger gravatar imageholger ( 2018-04-30 20:54:47 -0600 )edit

pbtxt for model - https://github.com/opencv/opencv_extr...

model http://download.tensorflow.org/models...

Using the pbtx from the archive results in Unknown enumeration value of "DT_RESOURCE" for field "type" I think the tensor models are not versioned and are too new. And using the pbtxt from open cv i have the problem described. Bad luck for me.

holger gravatar imageholger ( 2018-04-30 21:20:19 -0600 )edit

With what tensor version / how was that open cv ssd_mobilenet_v1_coco.pbtxt created?

holger gravatar imageholger ( 2018-04-30 21:31:48 -0600 )edit

have a look here on how to process that kind of 4d tensor in java.

(rows() and cols() will always be -1, if the Mat has more than 2 dimensions. that's NOT an error)

also, pbtxt files are not mandatory for most tensorflow models.

berak gravatar imageberak ( 2018-04-30 22:53:15 -0600 )edit

thx again berak - have/want to go visit people today - after that i ill check . Anyway i currently think opencv is best on cpu :-). Also "btxt files are not mandatory for most tensorflow models" - i hope this work for me - will check.

holger gravatar imageholger ( 2018-05-01 04:32:50 -0600 )edit