Use Python-trained (keras) model in c/c++. See section work-around for c-work-around.
Compile Tensorflow from source (rev 1.0 or 1.2.1) following the instructions from
https://www.tensorflow.org/install/install_windows
(tensorflow already is installed via pip in python3, but I need to use it from c++, so installing from source seems mandatory)
(full logs are below in extra sections)
in msys2-shell, setting environment vars, activate python virt-env, doing bazel clean, ./configure,
bazel build --verbose_failures --config=opt //tensorflow/tools/pip_package:build_pip_package
I get this error:
ERROR: D:/user/sourcen/external/tensorflow-master-201707051514/
tensorflow-master-rev-1-2-1/tensorflow/core/BUILD:1415:1:
Executing genrule //tensorflow/core:version_info_gen failed:
bash.exe failed: error executing command
cd C:/users/user/appdata/local/temp/_bazel_user/chogfwdz/execroot/org_tensorflow
C:/tools/msys64/usr/bin/bash.exe
-c source external/bazel_tools/tools/genrule/genrule-setup.sh;
tensorflow/tools/git/gen_git_source.py
--generate tensorflow/tools/git/gen/spec.json
tensorflow/tools/git/gen/head
tensorflow/tools/git/gen/branch_ref
"bazel-out/host/genfiles/tensorflow/core/util/version_info.cc":
com.google.devtools.build.lib.shell.
BadExitStatusException: Process exited with status 3.
Fatal Python error: Py_Initialize: unable to load the file system codec
ImportError: No module named 'encodings'
Sorry, I am absolutely lost here, this message tells me nothing. Here some snippets from the files mentioned above, maybe somebody has a glue and gives me a hint for enlightment....
//tensorflow/core/BUILD:1415:1 tf_version_info_genrule()
cc_library(
name = "version_lib",
srcs = ["util/version_info.cc"],
hdrs = ["public/version.h"],
copts = tf_copts(),
)
bazel/.../genrule-setup.sh
set -e
set -u
set -o pipefail
//tensorflow/tools/git/gen_git_source.py
"""... creates symlinks from the internal git repository directory so
that the build system can see changes in the version state. ..."""
def parse_branch_ref(filename)...
def configure(src_base_path, debug=False)...
def get_git_version(git_base_path)...
def write_version_info(filename, git_version)...
def generate(arglist)...
def raw_generate(output_file)...
I suppose, that the wrong python version is used (not the virtualenv I activated) - there are several other python versions (2.7-32, 2.7-64, 3.5-32, 3.5-64) installed (which are needed otherwise).
What can I do to check, if bazel is using the right python (virtualenv)?
If bazel is using the wrong one, how can I change this?
If bazel is using the right version, how can I get more details about what is going wrong (and fix it)?
What further information are needed (environment variables)?
What can I do to improve the question to enable people to give advices? (please give comments, what is missing, wrong, unclear, too much)
I searched for "Fatal Python error: Py_Initialize: unable to load the file system codec ImportError: No module named 'encodings'"
tried to do the procedure below with a local admin account -> blocked by the company firewall
tried to set PYTHONPATH and PYTHONHOME, no effect.
export PYTHONHOME=/D/bin/Python64-3-Anaconda/envs/python64-35
export PYTHONPATH=/D/bin/Python64-3-Anaconda/envs/python64-35: /D/bin/Python64-3-Anaconda/envs/python64-35/lib/site-packages: /d/bin/Python64-3-Anaconda/envs/python64-35/libs
try to set up another virtualenv (as admin)
try to install tensorflow via cmake
This is what I did after starting msys2:
In TF 1.0, I did a work-around for the first problem I faced (download failure of numeric_min_js). After some IRC talk & lots of tries - finally I commented out one line in /tensorflow-rev1-0/tensorflow/tensorboard/bower/BUILD (see below).
So now ./configure script (TF 1.0) runs without errors (warnings about http_proxy can be ignored, as I 've been told on IRC and on some URLs I googled). Below I added full logs of the full build-attempt.
My Python virtual-env is in
d:/bin/Python64-3-Anaconda/envs/python64-35/python.exe,
As library-path I used:
D:/bin/Python64-3-Anaconda/envs/python64-35/lib/site-packages.
.../tensorflow-rev1-0/tensorflow/tensorboard/bower/BUILD
filegroup(
name = "bower",
srcs = [
...
# "@numericjs_numeric_min_js//file", # by rg20170710
...
user@CRPC0815 MSYS ~
$ cd /d/user/Sourcen/external/tensorflow-rev1-0/
start msys2-shell:
$ c:/tools/msys64/msys2_shell.cmd
set the environment variables
user@CRPC0815 MSYS ~
$ source d:/user/00-Projekte/VrVis/env-cuda-python64-3--1.sh
activate virtual-env
$ cd /d/bin/Python64-3-Anaconda/
$ source activate python64-35
goto sources
$ cd /d/user/Sourcen/external/tensorflow-rev1-0
(python64-35)
user@CRPC0815 MSYS /d/user/Sourcen/external/tensorflow-rev1-0
$
(python64-35)
user@CRPC0815 MSYS /d/user/Sourcen/external/tensorflow-rev1-0
$ bazel clean
WARNING: ignoring http_proxy in environment.
....................
INFO: Starting clean (this may take a while). Consider using --async if the clean takes more than several minutes.
(python64-35)
user@CRPC0815 MSYS /d/user/Sourcen/external/tensorflow-rev1-0
$ ./configure
Please specify the location of python.
[Default is /D/bin/Python64-3-Anaconda/envs/python64-35/python]:
Please specify optimization flags to use during compilation [Default is -march=native]:
Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N]
No XLA support will be enabled for TensorFlow
Found possible Python library paths:
D:\bin\Python64-3-Anaconda\envs\python64-35\lib\site-packages
D:\bin\Python64-3-Anaconda\envs\python64-35
Please input the desired Python library path to use.
Default is [D:\bin\Python64-3-Anaconda\envs\python64-35\lib\site-packages]
Using python library path: D:\bin\Python64-3-Anaconda\envs\python64-35\lib\site-packages
Junction created for util\python\python_include <<===>> D:\bin\Python64-3-Anaconda\envs\python64-35\include
Junction created for util\python\python_lib <<===>> D:\bin\Python64-3-Anaconda\envs\python64-35\lib\site-packages
Junction created for third_party\py\numpy\numpy_include <<===>> D:\bin\Python64-3-Anaconda\envs\
python64-35\lib\site-packages\numpy\core\include
Do you wish to build TensorFlow with CUDA support? [y/N]
No CUDA support will be enabled for TensorFlow
Configuration finished
WARNING: ignoring http_proxy in environment.
INFO: All external dependencies fetched successfully.
$ bazel build --verbose_failures --config=opt //tensorflow/tools/pip_package:build_pip_package
WARNING: ignoring http_proxy in environment.
INFO: Found 1 target...
ERROR: D:/user/sourcen/external/tensorflow-rev1-0/tensorflow/core/BUILD:1227:1:
Executing genrule //tensorflow/core:version_info_gen failed:
bash.exe failed:
error executing command
cd C:/users/user/appdata/local/temp/_bazel_user/hnxszhzu/execroot/org_tensorflow
SET PATH=C:\tools\msys64\usr\bin;C:\tools\msys64\bin;
D:\bin\Python64-3-Anaconda\envs\python64-35;
D:\bin\Python64-3-Anaconda\envs\python64-35\Library\mingw-w64\bin;
D:\bin\Python64-3-Anaconda\envs\python64-35\Library\usr\bin;
D:\bin\Python64-3-Anaconda\envs\python64-35\Library\bin;
D:\bin\Python64-3-Anaconda\envs\python64-35\Scripts;
C:\tools\msys64\usr\bin;
D:\user\bin\BLAS;
D:\bin\TDM-GCC-64\bin;
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\bp2qlotc.p22\NativeBinaries\x86;
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;
C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64_x86\;
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\;
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64\;
C:\Program Files (x86)\MSBuild\14.0\bin;
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin;
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\libnvvp;
C:\Program Files\NVIDIA GPU Computing Toolkit\cuDNN\bin;
C:\Program Files\NVIDIA GPU Computing Toolkit\cuDNN\lib;
C:\Program Files\TortoiseGit\bin;
C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;
C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;
C:\ProgramData\Oracle\Java\javapath;
C:\Qt\Qt5.7.0\5.7\msvc2015;
C:\WINDOWS;
C:\WINDOWS\System32\Wbem;
C:\WINDOWS\System32\WindowsPowerShell\v1.0\;
C:\WINDOWS\system32;
D:\user\bin\MinGW\msys\1.0\bin;
D:\user\bin\MinGW\msys\1.0\sbin;
D:\user\bin\MinGW\msys\1.0\sbin\awk;
D:\bin\CMake\bin;
D:\bin\Git\bin;
[...]
D:\bin\Python64-3-Anaconda\envs\python64-35\DLLs;
D:\bin\Python64-3-Anaconda\envs\python64-35\Lib;
D:\bin\Python64-3-Anaconda\envs\python64-35\libs;
D:\bin\Slik-Subversion-1-9-2\bin;
D:\bin\SubversionColabnet\bin;
D:\bin\TDM-GCC-64\bin;
C:\tools\msys64\usr\local\bin;
C:\tools\msys64\usr\bin;
C:\tools\msys64\usr\bin;
C:\tools\msys64\opt\bin;
C:\Windows\System32;
C:\Windows;
C:\Windows\System32\Wbem;
C:\Windows\System32\WindowsPowerShell\v1.0\;
C:\tools\msys64\usr\bin\site_perl;
C:\tools\msys64\usr\bin\vendor_perl;
C:\tools\msys64\usr\bin\core_perl
C:/tools/msys64/usr/bin/bash.exe -c source external/bazel_tools/tools/genrule/genrule-setup.sh;
tensorflow/tools/git/gen_git_source.py
--generate tensorflow/tools/git/gen/spec.json
tensorflow/tools/git/gen/head
tensorflow/tools/git/gen/branch_ref
"bazel-out/host/genfiles/tensorflow/core/util/version_info.cc":
com.google.devtools.build.lib.
shell.BadExitStatusException: Process exited with status 3.
Fatal Python error: Py_Initialize: unable to load the file system codec
ImportError: No module named 'encodings'
Current thread 0x0000628c (most recent call first):
Target //tensorflow/tools/pip_package:build_pip_package failed to build
INFO: Elapsed time: 5,500s, Critical Path: 0,41s
(the same as in TF 1.0)
$ source d:/user/00-Projekte/VrVis/env-cuda-python64-3--1.sh
$ cd /d/bin/Python64-3-Anaconda/
$ source activate python64-35
$ cd /d/user/Sourcen/external/tensorflow-master-201707051514/tensorflow-master-rev-1-2-1/
$ bazel clean
WARNING: ignoring http_proxy in environment.
INFO: Starting clean (this may take a while). Consider using --async if the clean takes more than several minutes
$ ./configure
WARNING: ignoring http_proxy in environment.
You have bazel 0.5.2- installed.
Please specify the location of python.
[Default is /D/bin/Python64-3-Anaconda/envs/python64-35/python]:
Found possible Python library paths:
D:\bin\Python64-3-Anaconda\envs\python64-35
D:\bin\Python64-3-Anaconda\envs\python64-35\lib\site-packages
Please input the desired Python library path to use.
Default is [D:\bin\Python64-3-Anaconda\envs\python64-35]
D:/bin/Python64-3-Anaconda/envs/python64-35/lib/site-packages
Do you wish to build TensorFlow with MKL support? [y/N]
No MKL support will be enabled for TensorFlow
Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified
[Default is -march=native]:
Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N]
No XLA support will be enabled for TensorFlow
Do you wish to build TensorFlow with VERBS support? [y/N]
No VERBS support will be enabled for TensorFlow
Do you wish to build TensorFlow with CUDA support? [y/N]
No CUDA support will be enabled for TensorFlow
Do you wish to build TensorFlow with MPI support? [y/N]
MPI support will not be enabled for TensorFlow
Configuration finished
(python64-35)
user@CRPC0815 MSYS /d/user/Sourcen/external/tensorflow-master-201707051514/tensorflow-master-rev-1-2-1
$ bazel build --verbose_failures --config=opt //tensorflow/tools/pip_package:build_pip_package
WARNING: ignoring http_proxy in environment.
INFO: Found 1 target...
ERROR: D:/user/sourcen/external/tensorflow-master-201707051514/tensorflow-master-rev-1-2-1/tensorflow/core/BUILD:1415:1:
Executing genrule //tensorflow/core:version_info_gen failed:
bash.exe failed:
error executing command
cd C:/users/user/appdata/local/temp/_bazel_user/chogfwdz/execroot/org_tensorflow
SET PATH=C:\tools\msys64\usr\bin;
C:\tools\msys64\bin;
C:\tools\msys64\usr\bin;
D:\user\bin\BLAS;
D:\bin\TDM-GCC-64\bin;
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\bp2qlotc.p22\NativeBinaries\x86;
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;
C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64_x86\;
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\;
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64\;
C:\Program Files (x86)\MSBuild\14.0\bin;
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin;
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\libnvvp;
C:\Program Files\NVIDIA GPU Computing Toolkit\cuDNN\bin;
C:\Program Files\NVIDIA GPU Computing Toolkit\cuDNN\lib;
C:\Program Files\TortoiseGit\bin;
C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;
C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;
C:\ProgramData\Oracle\Java\javapath;
C:\Qt\Qt5.7.0\5.7\msvc2015;
C:\WINDOWS;
C:\WINDOWS\System32\Wbem;
C:\WINDOWS\System32\WindowsPowerShell\v1.0\;
C:\WINDOWS\system32;
D:\BaslerPylon5\Runtime\Win32\;
D:\BaslerPylon5\Runtime\x64\;
D:\user\bin\MinGW\msys\1.0\bin;
D:\user\bin\MinGW\msys\1.0\sbin;
D:\user\bin\MinGW\msys\1.0\sbin\awk;
D:\bin\CMake\bin;
D:\bin\Git\bin;
D:\bin\Python64-3-Anaconda\envs\python64-35;
D:\bin\Python64-3-Anaconda\envs\python64-35\Library\bin;
D:\bin\Python64-3-Anaconda\envs\python64-35\Scripts;
D:\bin\Python64-3-Anaconda\envs\python64-35\DLLs;
D:\bin\Python64-3-Anaconda\envs\python64-35\Lib;
D:\bin\Python64-3-Anaconda\envs\python64-35\libs;
D:\bin\Slik-Subversion-1-9-2\bin;
D:\bin\SubversionColabnet\bin;
D:\bin\TDM-GCC-64\bin;
D:\bin\gnuplot\bin;
D:\user\bin;
.
C:/tools/msys64/usr/bin/bash.exe -c source external/bazel_tools/tools/genrule/genrule-setup.sh;
tensorflow/tools/git/gen_git_source.py
--generate tensorflow/tools/git/gen/spec.json
tensorflow/tools/git/gen/head tensorflow/tools/git/gen/branch_ref
"bazel-out/host/genfiles/tensorflow/core/util/version_info.cc":
com.google.devtools.build.lib.shell.
BadExitStatusException: Process exited with status 3.
Fatal Python error: Py_Initialize: unable to load the file system codec
ImportError: No module named 'encodings'
Current thread 0x000036e8 (most recent call first):
Target //tensorflow/tools/pip_package:build_pip_package failed to build
INFO: Elapsed time: 5,413s, Critical Path: 0,52s
Meanwhile I found a work-around for deploying Tensorflow (Keras) Models (win7/win10) without need of bazel/cmake/sources....:
create lib from dll via vs2015 command prompt:
dumpbin /exports xxx.dll > xxx.def
pywrap_tensorflow_internal.lib
extract gpu lib from Python pywrap_tensorflow_internal.lib
maybe use gpu-options (python -> c):
python code
gpu_options = tensorflow.GPUOptions(allow_growth=True)
config = tensorflow.ConfigProto(gpu_options=gpu_options)
serialized = config.SerializeToString()
[int(i) for i in serialized]
c-code for gpu-options:
TF_SessionOptions* sess_opts = TF_NewSessionOptions();
// tensorflow.GPUOptions(allow_growth=True) ...
uint8_t configProtoGPU[] = { 50, 2, 32, 1};
size_t configProtoGPUlen = sizeof(configProtoGPU) / sizeof(uint8_t);
TF_SetConfig(sess_opts, configProtoGPU, configProtoGPUlen, status);
User contributions licensed under CC BY-SA 3.0