Ask Your Question

Android OpenCV reverts to Caffe instead of Tensorflow DNN

asked 2019-12-31 03:54:36 -0500

aditya_mangalampalli gravatar image

Hello all, I was writing a fragment of an Android app which takes advantage of the OpenCV DNN module. However, I there are very strange errors which I keep receiving because I keep receiving this error for reading a network from Caffe instead of Tensorflow: CvException - cv::Exception: OpenCV(4.1.0) /build/master_pack_android/opencv/modules/dnn/src/caffe/caffe_io.cpp:1132: error: (-2:Unspecified error) FAILED: fs.is_open(). Can't open "src/main/java/org/firstinspires/ftc/teamcode/model.pbtxt" in function 'ReadProtoFromBinaryFile. This is especially strange considering that my code below does not use Caffe for anything. All the binary files are Tensorflow based and does not even import Caffe files whatsoever. Below is the code I used:

class NeuralNet
    private Net net;
    private String pbTxt = "src/main/java/org/firstinspires/ftc/teamcode/model.pb";
    private String pbFile = "src/main/java/org/firstinspires/ftc/teamcode/model.pbtxt";

    public Mat processFrame(Mat input)

        net = Dnn.readNetFromTensorflow(pbFile, pbTxt);
        system.addLine("[INFO]: Model successfully loaded!");

        return input;

Please keep in mind that this is just the initialization class for the DNN. The rest of the initializations are in other files. Please help me out because I have done whatever I could to troubleshoot the issue however there seems to be nothing wrong with the code in anyway because all it is doing is throwing the same error no matter whatever I try. Is Tensorflow DNN module not supported on Android?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2019-12-31 04:06:13 -0500

berak gravatar image

updated 2019-12-31 04:30:59 -0500

there is some code shared between tf and caffe importers, that's why you get the message from caffe_io.cpp.

but the error says, it could not open the pbtxt file (and probably the pb, too), most likely due to a wrong path.

try to put the files on sdcard or similar, not into your src folder, where it won't be accessible in the final apk

(i guess)

if you need to distribute the model files with your apk, see here how to copy it to some place, where opencv can read it

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2019-12-31 03:54:36 -0500

Seen: 90 times

Last updated: Dec 31 '19