PDA

View Full Version : Linking pb file to the Qt program.



comvis
29th July 2019, 13:40
Hello Qt devs. I have a pb file generated from TensorFlow, I linked that pb file to OpenCV in my program successfully in my computer. However, when I copy the deployed folder with the pb file inside to another machine the pb file doesn't work but OpenCV works fine. How do I link that file to my program?

anda_skoa
1st August 2019, 20:32
How do you "link" the file to OpenCV?

Cheers,
_

d_stranz
2nd August 2019, 01:04
How do you "link" the file to OpenCV?

Especially since AFAIK OpenCV is a set of libraries like Qt, and not a stand-alone application.

ChrisW67
2nd August 2019, 08:50
However, when I copy the deployed folder with the pb file inside to another machine the pb file doesn't work but OpenCV works fine. How do I link that file to my program?
You are probably either:

not copying all the relevant run-time dependencies necessary for QT/OpenCV/Tensorflow to ingest and handle a protocol buffer file or,
assuming the current working directory of the program is somewhere it is not and addressing the procotol buffer file with an unqualified name "realcool.pb" (i.e. the file open fails).

It may be something else, but we cannot see your system.

comvis
3rd August 2019, 12:35
You are probably either:

not copying all the relevant run-time dependencies necessary for QT/OpenCV/Tensorflow to ingest and handle a protocol buffer file or,
assuming the current working directory of the program is somewhere it is not and addressing the procotol buffer file with an unqualified name "realcool.pb" (i.e. the file open fails).

It may be something else, but we cannot see your system.



pbFile = "tensorflowfile.pb";
#pbFile = "./tensorflowfile.pb";
#pbFile = "C:/Users/Computer/Documents/Program/release/tensorflowfile.pb";
#pbFile = ":/file/release/tensorflowfile.pb";
using namespace cv;

neural_net=dnn::readNet(pbFile.toStdString());

neural_net.setPreferableBackend(dnn::DNN_BACKEND_O PENCV);

neural_net.setPreferableTarget(dnn::DNN_TARGET_CPU );

The third code only works when I ran my program inside my machine and I understand that since it is the absolute directory of my pb file.
After I deployed the release, I ran all three "pbFile" then copied the release folder with the pb file inside and all dlls needed including opencv_411world.dll. Launched the program well but when I clicked the button which run the function containing neural_net nothing happenned. Even adding the pb file to the resource didn't solve.

ChristianEhrlicher
3rd August 2019, 14:31
You can get the path of your executable with QCoreApplication::applicationDirPath() so creating a full path to your file should be easy when you put it beside our exectuable.

anda_skoa
3rd August 2019, 16:40
The third code only works when I ran my program inside my machine and I understand that since it is the absolute directory of my pb file.

Yes, correct.

And the first two are relative paths, the program will look for these in the current working directory.
The current working directory is very often not the program's installation location.

As ChristianErlicher wrote, you can create a path relative to the executable.



Even adding the pb file to the resource didn't solve.

Well, not if you pass the resource path to a non-Qt library, it won't understand this type of path.
For this kind of usage the resource data needs to be first extracted into a real file, e.g. using QTemporaryFile::createNativeFile().

Cheers,
_