Where are array_ops.h and other C++ headers? - c++

I'm writing a C++ application in TensorFlow 1.6. I'm able to run Python files with no problems and have compiled the C++ examples that also run just fine, so I think I've set up TensorFlow correctly.
I've started a new project that builds with no errors using plain C++. I'm now trying to construct Placeholder(), the docs say I need to #include <array_ops.h>, but it can't be located during compile. I did sudo find / -name "array_ops.h" and the only match was a file in ~/.cache/bazel.
Is there an extra build/configure step needed to install the C++ header files referred to in the docs?
Solved
This is a bug in the documentation for 1.6. The #includes listed in the API are not needed for calling some (many?) constructors.

Related

Building LibreSSL for use in a C++ project

I am trying to write a C++ project using libressl. I have built the package and followed the instructions here however I have been unable to locate the header files (or any files from the make install actually) for the project.
I am fairly new to C++ development and I am not a professional programmer so there is a good chance I am doing this completely wrong. Is it even possible to use LibreSSL as a C++ library and if so what steps would I need to take to do so?

can I use cmake/make to compile all and only the cpp/hpp files I used?

One of many nice features of java is that if I type javac x.java, it will compile the classes in x.java and any other classes mentioned in x, and recursively look for other required classes. I can then find the .class files, put them in a jar and I have a minimal executable for x. How would I do the same for c++? I expect I need to do it with cmake, but "minimal" does not seem to be in the modern vocabulary.
I am trying to get opencv4 running on a raspberry pi - lots of guides on the web; primarily targeting python and the rest don't work in my experience. OpenCV is classic bloatware and the solution is to automate the build process rather than simplify it.
I feel I ought to be able to start with a relevant example application and run, for example:
g++ facedetect.cpp
then (manually) compile the missing bits.
There are however missing .hpp files that are constructed by the cmake/make process and the only option seems to be to build the entire edifice first.
OpenCV4 is a CMake based project. No need to combine the classes and source files etc, that is what CMake is doing for you! You can just use this guide which has every step written out for you.

Using tensorflow in C++ on Windows

I know there are ways of using Tensorflow in C++ they even have a documentation for it but I can seem to be able to get the library for it. I've checked the build from source instructions but it seems to builds a pip package rather than a library I can link to my project. I also found a tutorial but when I tried it out I ran out of memory and my computer crashed. My question is, how can I actually get the C++ library to work on my project? I do have these requirements, I have to work on windows with Visual Studio in C++. What I would love to is if I could get a pre-compiled DLL that I could just link but I haven't found such a thing and I'm open to other alternatives.
I can't comment so I am writing this as an answer.
If you don't mind using Keras, you could use the package frugally deep. I haven't seen a library myself either, but I came across frugally deep and it seemed easy to implement. I am currently trying to use it, so I cannot guarantee it will work.
You could check out neural2D from here:
https://github.com/davidrmiller/neural2d
It is a neural network implementation without any dependent libraries (all written from scratch).
I would say that the best option is to use cppflow, an easy wrapper that I created to use Tensorflow from C++ easily.
You won't need to install anything, just download the TF C API, and place it somewhere in your computer. You can take a look to the docs to see how to do it, and how to use the library.
The answer seems to be that it is hard :-(
Try this to start. You can follow the latest instructions for building from source on Windows up to the point of building the pip package. But don't do that - do this/these instead:
bazel -config=opt //tensorflow:tensorflow.dll
bazel -config=opt //tensorflow:tensorflow.lib
bazel -config=opt tensorflow:install_headers
That much seems to work fine. The problems really start when you try to use Any of the header files - you will probably get compilation errors, at least with TF version >= 2.0. I have tried:
Build the label_image example (instructions in the readme.md file)
It builds and runs fine on Windows, meaning all the headers and source are there somewhere
Try incorporating that source into Windows console executable: runs into compiler errors due to conflicts with std::min & std::max, probably due to Windows SDK.
Include c_api.h in a Windows console application: won't compile.
Include TF-Lite header files: won't compile.
There is little point investing the lengthy compile time in the first two bazel commands if you can't get the headers to compile :-(
You may have time to invest in resolving these errors; I don't. At this stage Tensorflow lacks sufficient support for Windows C++ to rely on it, particularly in a commercial setting. I suggest exploring these options instead:
If TF-Lite is an option, watch this
Windows ML/Direct ML (requires conversion of TF models to ONNX format)
CPPFlow
Frugally Deep
Keras2CPP
UPDATE: having explored the list above, I eventually found the following worked best in my context (real-time continuous item recognition):
convert models to ONNX format (use tf2onnx or keras2onnx
use Microsoft's ONNX runtime
Even though Microsoft recommends using DirectML where milliseconds matter, the performance of ONNX runtime using DirectML as an execution provider means we can run a 224x224 RGB image through our Intel GPU in around 20ms, which is quick enough for us. But it was still hard finding our way to this answer

Solving DL4J compilation error

I am trying to download DL4J source without error.
https://github.com/deeplearning4j/deeplearning4j
I cloned https://github.com/deeplearning4j/deeplearning4j.git
and imported using existing Maven project in Eclipse.
Tons of dependencies are downloaded but it's bombarded with errors.
Anyone who knows which branch version is free of compile error?
The site says 0.9.1 is most stable version, but it still generates errors.
So there's a few things here:
No major open source project in today's day and age operates without a build system. This can be maven,gradle,sbt,..
You ignored all of our docs about building from source and the like. You don't need to do that. Use the build system like it's intended.
My suggestion here:
Learn what the rest of the java world did and use maven:
Our quick start is here: http://deeplearning4j.org/quickstart
Follow our examples for the latest versions:
https://github.com/deeplearning4j/dl4j-examples
Chances are you do not need to build from source (this involves 5 other projects you probably do not want to do that) - but if you absolutely must be prepared to use c++ among other things.
The guide for that can be found here:
https://deeplearning4j.org/devguide

Using OpenSSL's CMS implementation in C++

So my project today has been to create a C++ class that consolidates a lot of our commonly used crypto tasks. Got lots of things working but ran into a bit of a snag here. For reference, I'm using XCode 3.2.5 on OS 10.6.5.
I'm attempting to utilize some of OpenSSL's CMS functions. OpenSSL's MAN Page for one of the functions I'm trying to use mentions it was included in version 0.9.8. That's the version XCode let me import without having to do anything out of the ordinary (Target -> General -> Add Linked Library). Yet with that added XCode tells me it can't find openssl/cms.h.
So thinking maybe there's some disparity between the OS X version 0.9.8 and the one on OpenSSLs page, I downloaded the source for 1.0.0c and built it. After it was built, I added libcrypto.a and libssl.a to my project as linked libraries and added "some/dirs/openssl-1.0.0c/include/**" as a header search path. Now it can find openssl/cms.h but I get a linking error on any CMS function I call.
Has anyone done this successfully? Any help would be appreciate.
Thanks!
So what I ended up doing was to create a new SDK and calling,
./Configure darwin64-x86_64-cc --prefix=/path/to/sdk/usr --openssldir=/System/Library/OpenSSL enable-cms shared
To update the version of OpenSSL included in that SDK. That's seemed to work.