我期待修改TensorFlow及其ANN功能,用於我的大部分代碼都在C++中的計算力學目的。包含TensorFlow .h文件時,是否可以在不使用Bazel的情況下使用C++進行編譯?如果是這樣,我真的很感激一個例子(到目前爲止還沒有能夠找到任何在線)。 謝謝使用TensorFlow編譯C++代碼而不使用Bazel
編輯:我做了,但我無法關注。讓我舉一個例子,也許我們可以從那裏開始。我使用Ubuntu 16.10,gcc(Ubuntu 6.2.0-5ubuntu12)6.2.0 20161005和Python 2.7.12+。我已經從源代碼安裝了bazel,並且還有克隆的TF庫(〜/ Desktop/tensorflow)。以從(https://www.tensorflow.org/api_guides/cc/guide)稍微修改的例子中,我在example.cc:
#include "tensorflow/cc/client/client_session.h"
#include "tensorflow/cc/ops/standard_ops.h"
#include "tensorflow/core/framework/tensor.h"
#include <iostream>
int main() {
using namespace tensorflow;
using namespace tensorflow::ops;
using namespace std;
Scope root = Scope::NewRootScope();
// Matrix A = [3 2; -1 0]
auto A = Const(root, { {3.f, 2.f}, {-1.f, 0.f}});
// Vector b = [3 5]
auto b = Const(root, { {3.f, 5.f}});
// v = Ab^T
auto v = MatMul(root.WithOpName("v"), A, b, MatMul::TransposeB(true));
std::vector<Tensor> outputs;
ClientSession session(root);
// Run and fetch v
TF_CHECK_OK(session.Run({v}, &outputs));
// Expect outputs[0] == [19; -3]
LOG(INFO) << outputs[0].matrix<float>();
return 0;
cout<<"compiled correctly!"<<endl;
}
它位於〜/桌面/ tensorflow/tensorflow /立方厘米/例子。我的BUILD文件 - 也是在〜/桌面/ tensorflow/tensorflow/CC /例子 - 上寫着:
cc_binary(
name = "example",
srcs = ["example.cc"],
deps = [
"//tensorflow/cc:cc_ops",
"//tensorflow/cc:client_session",
"//tensorflow/core:tensorflow",
],
)
我嘗試使用來自〜/桌面/ tensorflow編譯:
bazel build tensorflow/cc/example/...
這是我得到:
INFO: Found 1 target...
Target //tensorflow/cc/example:example up-to-date:
bazel-bin/tensorflow/cc/example/example
INFO: Elapsed time: 0.381s, Critical Path: 0.00s
然後,當我去到〜/桌面/ tensorflow /巴澤勒斌/ tensorflow/CC /例子並運行:
./example
我得到:
2017-07-27 09:58:39.906578: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2017-07-27 09:58:39.906628: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2017-07-27 09:58:39.906636: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2017-07-27 09:58:39.906641: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
2017-07-27 09:58:39.906646: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
2017-07-27 09:58:39.907751: I tensorflow/cc/example/example.cc:22] 19
-3
任何幫助將是非常感激,因爲我試圖環繞此我的手。感謝您的耐心。
你見過https://github.com/tensorflow/tensorflow/issues/2412嗎? – MSalters
請參閱修改。在鏈接之後,我不確定如何將libtensorflow.so合併到我正在嘗試執行的操作中。 – user147813
32位?這沒有幫助。 – MSalters