Skip to content

Commit a563e66

Browse files
Merge branch 'master' into r0.16
2 parents 4fcdd3e + fee1b0c commit a563e66

30 files changed

+431
-282
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ if (NOT USE_PRE_BUILT_NGRAPH)
234234
ExternalProject_Add(
235235
ext_ngraph
236236
GIT_REPOSITORY https://github.com/NervanaSystems/ngraph
237-
GIT_TAG v0.22.0
237+
GIT_TAG v0.23.0-rc.2
238238
CMAKE_ARGS
239239
-DNGRAPH_DISTRIBUTED_ENABLE=${NGRAPH_DISTRIBUTED_ENABLE}
240240
-DNGRAPH_INSTALL_PREFIX=${NGRAPH_ARTIFACTS_DIR}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ The installation prerequisites are the same as described in the TensorFlow
6969

7070
git clone https://github.com/tensorflow/ngraph-bridge.git
7171
cd ngraph-bridge
72-
git checkout v0.16.0-rc0
72+
git checkout v0.16.0-rc1
7373

7474

7575
2. Run the following Python script to build TensorFlow, nGraph and the bridge. Please use Python 3.5:

bazel/WORKSPACE

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ tf_configure(
2525
http_archive(
2626
name = "ngraph",
2727
build_file = "//:bazel/ngraph.BUILD",
28-
sha256 = "",
29-
strip_prefix = "ngraph-0.22.0",
28+
sha256 = "1a1182f639506d472a22cefff53c9bdd536f2feacb633f66ad6a72fb5354ee06",
29+
strip_prefix = "ngraph-0.23.0-rc.2",
3030
urls = [
31-
"https://mirror.bazel.build/github.com/NervanaSystems/ngraph/archive/v0.22.0.tar.gz",
32-
"https://github.com/NervanaSystems/ngraph/archive/v0.22.0.tar.gz"
31+
"https://mirror.bazel.build/github.com/NervanaSystems/ngraph/archive/v0.23.0-rc.2.tar.gz",
32+
"https://github.com/NervanaSystems/ngraph/archive/v0.23.0-rc.2.tar.gz"
3333
],
3434
)
3535

@@ -86,4 +86,4 @@ http_archive(
8686
"http://mirror.tensorflow.org/github.com/intel/mkl-dnn/releases/download/v0.18/mklml_lnx_2019.0.3.20190220.tgz",
8787
"https://github.com/intel/mkl-dnn/releases/download/v0.18/mklml_lnx_2019.0.3.20190220.tgz",
8888
],
89-
)
89+
)

bazel/ngraph.BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ cc_library(
6565
],
6666
exclude = [
6767
"src/ngraph/ngraph.cpp",
68+
"src/ngraph/serializer_stub.cpp"
6869
]),
6970
deps = [
7071
":ngraph_headers",

bazel/tbb.BUILD

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ genrule(
3838
set -e
3939
WORK_DIR=$$PWD
4040
DEST_DIR=$$PWD/$(@D)
41-
export PATH=$$(dirname $(AR)):$$PATH
42-
export CXXFLAGS=$(CC_FLAGS)
43-
export NM=$(NM)
44-
export AR=$(AR)
4541
cd $$(dirname $(location :Makefile))
4642

4743
#TBB's build needs some help to figure out what compiler it's using

build_ngtf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def main():
5353
'''
5454

5555
# Component versions
56-
ngraph_version = "v0.22.0"
56+
ngraph_version = "v0.23.0-rc.2"
5757
tf_version = "v1.14.0"
5858

5959
# Command line parser options
@@ -492,7 +492,7 @@ def main():
492492
link_src = os.path.join(artifacts_location,
493493
"tensorflow/tensorflow/python")
494494
link_dst = os.path.join(artifacts_location, "tensorflow/python")
495-
command_executor(['ln', '-s', link_src, link_dst], verbose=True)
495+
command_executor(['ln', '-sf', link_src, link_dst], verbose=True)
496496

497497
# Run a quick test
498498
install_ngraph_tf(venv_dir, os.path.join(artifacts_location, ng_tf_whl))

build_tf.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,14 @@ def main():
4545

4646
assert not os.path.isdir(
4747
arguments.output_dir), arguments.output_dir + " already exists"
48-
os.mkdir(arguments.output_dir)
48+
os.makedirs(arguments.output_dir)
4949
os.chdir(arguments.output_dir)
5050
assert not is_venv(
5151
), "Please deactivate virtual environment before running this script"
5252

53+
assert not is_venv(
54+
), "Please deactivate virtual environment before running this script"
55+
5356
venv_dir = './venv3/'
5457

5558
install_virtual_env(venv_dir)
@@ -63,11 +66,21 @@ def main():
6366
# Build TensorFlow
6467
build_tensorflow(venv_dir, "tensorflow", 'artifacts', arguments.target_arch,
6568
False)
66-
shutil.copytree('./tensorflow/tensorflow/python',
67-
'./artifacts/tensorflow/python')
68-
print('To build ngraph-bridge using this prebuilt tensorflow, use:')
69-
print('./build_ngtf.py --use_tensorflow_from_location ' +
70-
os.path.abspath(arguments.output_dir))
69+
70+
# Build TensorFlow C++ Library
71+
build_tensorflow_cc("tensorflow", 'artifacts', arguments.target_arch, False)
72+
73+
pwd = os.getcwd()
74+
artifacts_dir = os.path.join(pwd, 'artifacts/tensorflow')
75+
os.chdir("tensorflow")
76+
77+
copy_tf_to_artifacts(artifacts_dir, None)
78+
79+
print('\033[1;35mTensorFlow Build finished\033[0m')
80+
81+
print('When building ngraph-bridge using this prebuilt tensorflow, use:')
82+
print('\033[3;34mpython3 build_ngtf.py --use_tensorflow_from_location ' +
83+
os.path.abspath(arguments.output_dir) + '\033[1;0m')
7184

7285

7386
if __name__ == '__main__':

examples/cpp/infer_multiple_networks/inference_engine.cc

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,28 +40,30 @@ extern tf::Status LoadGraph(const string& graph_file_name,
4040
std::unique_ptr<tf::Session>* session,
4141
const tf::SessionOptions& options);
4242

43-
extern tf::Status ReadTensorFromImageFile(const string& file_name,
43+
extern tf::Status ReadTensorFromImageFile(const std::vector<string>& file_names,
4444
const int input_height,
4545
const int input_width,
4646
const float input_mean,
4747
const float input_std, bool use_NCHW,
48+
const int input_channels,
4849
std::vector<tf::Tensor>* out_tensors);
4950

5051
namespace infer_multiple_networks {
5152

5253
InferenceEngine::InferenceEngine(const string& name, const string& backend)
5354
: m_name(name) {}
54-
Status InferenceEngine::Load(const string& network, const string& image_file,
55+
Status InferenceEngine::Load(const string& network,
56+
const std::vector<string>& image_files,
5557
int input_width, int input_height,
5658
float input_mean, float input_std,
5759
const string& input_layer,
5860
const string& output_layer, bool use_NCHW,
59-
bool preload_images) {
61+
bool preload_images, int input_channels) {
6062
// Load the network
6163
TF_CHECK_OK(CreateSession(network, m_session));
6264

6365
// Save the input related information
64-
m_image_file = image_file;
66+
m_image_files = image_files;
6567
m_input_width = input_width;
6668
m_input_height = input_height;
6769
m_input_mean = input_mean;
@@ -70,6 +72,7 @@ Status InferenceEngine::Load(const string& network, const string& image_file,
7072
m_output_layer = output_layer;
7173
m_use_NCHW = use_NCHW;
7274
m_preload_images = preload_images;
75+
m_input_channels = input_channels;
7376

7477
// Preload the image is requested
7578
if (m_preload_images) {
@@ -79,8 +82,8 @@ Status InferenceEngine::Load(const string& network, const string& image_file,
7982
tf::ngraph_bridge::BackendManager::SetBackendName("CPU");
8083
std::vector<tf::Tensor> resized_tensors;
8184
TF_CHECK_OK(ReadTensorFromImageFile(
82-
m_image_file, m_input_height, m_input_width, m_input_mean, m_input_std,
83-
m_use_NCHW, &resized_tensors));
85+
m_image_files, m_input_height, m_input_width, m_input_mean, m_input_std,
86+
m_use_NCHW, m_input_channels, &resized_tensors));
8487
m_image_to_repeat = resized_tensors[0];
8588
tf::ngraph_bridge::BackendManager::SetBackendName(current_backend);
8689
}
@@ -131,8 +134,8 @@ void InferenceEngine::ThreadMain() {
131134

132135
std::vector<tf::Tensor> resized_tensors;
133136
TF_CHECK_OK(ReadTensorFromImageFile(
134-
m_image_file, m_input_height, m_input_width, m_input_mean,
135-
m_input_std, m_use_NCHW, &resized_tensors));
137+
m_image_files, m_input_height, m_input_width, m_input_mean,
138+
m_input_std, m_use_NCHW, m_input_channels, &resized_tensors));
136139

137140
m_image_to_repeat = resized_tensors[0];
138141
tf::ngraph_bridge::BackendManager::SetBackendName(current_backend);
@@ -150,7 +153,6 @@ void InferenceEngine::ThreadMain() {
150153
std::vector<Tensor> outputs;
151154
TF_CHECK_OK(m_session->Run({{m_input_layer, resized_tensor}},
152155
{m_output_layer}, {}, &outputs));
153-
154156
infer_event.Stop();
155157

156158
ngraph::Event::write_trace(infer_event);

examples/cpp/infer_multiple_networks/inference_engine.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <memory>
2424
#include <string>
2525
#include <thread>
26+
#include <vector>
2627

2728
#include "tensorflow/core/lib/core/status.h"
2829
#include "tensorflow/core/public/session.h"
@@ -44,10 +45,11 @@ class InferenceEngine {
4445
InferenceEngine(const string& name, const string& backend);
4546
~InferenceEngine();
4647

47-
Status Load(const string& network, const string& image_file, int input_width,
48-
int input_height, float input_mean, float input_std,
49-
const string& input_layer, const string& output_layer,
50-
bool use_NCHW, bool preload_images);
48+
Status Load(const string& network, const std::vector<string>& image_files,
49+
int input_width, int input_height, float input_mean,
50+
float input_std, const string& input_layer,
51+
const string& output_layer, bool use_NCHW, bool preload_images,
52+
int input_channels);
5153

5254
Status Start();
5355
Status Start(const std::function<void(int)>& step_callback);
@@ -64,7 +66,7 @@ class InferenceEngine {
6466
std::function<void(int)> m_step_callback{nullptr};
6567

6668
// Image related info
67-
string m_image_file;
69+
std::vector<string> m_image_files;
6870
int m_input_width;
6971
int m_input_height;
7072
float m_input_mean;
@@ -73,6 +75,7 @@ class InferenceEngine {
7375
string m_output_layer;
7476
bool m_use_NCHW;
7577
bool m_preload_images;
78+
int m_input_channels;
7679
Tensor m_image_to_repeat;
7780
};
7881

examples/cpp/infer_multiple_networks/main.cc

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ void PrintVersion() {
8989
}
9090

9191
int main(int argc, char** argv) {
92+
// parameters below need to modified as per model
9293
string image = "grace_hopper.jpg";
94+
int batch_size = 1;
95+
// Vector size is same as the batch size, populating with single image
96+
vector<string> images(batch_size, image);
9397
string graph = "inception_v3_2016_08_28_frozen.pb";
9498
string labels = "";
9599
int input_width = 299;
@@ -100,7 +104,7 @@ int main(int argc, char** argv) {
100104
string output_layer = "InceptionV3/Predictions/Reshape_1";
101105
bool use_NCHW = false;
102106
bool preload_images = true;
103-
107+
int input_channels = 3;
104108
int iteration_count = 10;
105109

106110
std::vector<tf::Flag> flag_list = {
@@ -137,27 +141,27 @@ int main(int argc, char** argv) {
137141
return -1;
138142
}
139143

140-
// const char* backend = "CPU";
141-
// if (SetNGraphBackend(backend) != tf::Status::OK()) {
142-
// std::cout << "Error: Cannot set the backend: " << backend << std::endl;
143-
// return -1;
144-
// }
144+
const char* backend = "CPU";
145+
if (SetNGraphBackend(backend) != tf::Status::OK()) {
146+
std::cout << "Error: Cannot set the backend: " << backend << std::endl;
147+
return -1;
148+
}
145149

146150
std::cout << "Component versions\n";
147151
PrintVersion();
148152

149153
infer_multiple_networks::InferenceEngine infer_engine_1("engine_1", "CPU:0");
150-
TF_CHECK_OK(infer_engine_1.Load(graph, image, input_width, input_height,
151-
input_mean, input_std, input_layer,
152-
output_layer, use_NCHW, preload_images));
154+
TF_CHECK_OK(infer_engine_1.Load(
155+
graph, images, input_width, input_height, input_mean, input_std,
156+
input_layer, output_layer, use_NCHW, preload_images, input_channels));
153157
infer_multiple_networks::InferenceEngine infer_engine_2("engine_2", "CPU:0");
154-
TF_CHECK_OK(infer_engine_2.Load(graph, image, input_width, input_height,
155-
input_mean, input_std, input_layer,
156-
output_layer, use_NCHW, preload_images));
158+
TF_CHECK_OK(infer_engine_2.Load(
159+
graph, images, input_width, input_height, input_mean, input_std,
160+
input_layer, output_layer, use_NCHW, preload_images, input_channels));
157161
infer_multiple_networks::InferenceEngine infer_engine_3("engine_3", "CPU:0");
158-
TF_CHECK_OK(infer_engine_3.Load(graph, image, input_width, input_height,
159-
input_mean, input_std, input_layer,
160-
output_layer, use_NCHW, preload_images));
162+
TF_CHECK_OK(infer_engine_3.Load(
163+
graph, images, input_width, input_height, input_mean, input_std,
164+
input_layer, output_layer, use_NCHW, preload_images, input_channels));
161165

162166
bool engine_1_running = true;
163167
infer_engine_1.Start([&](int step_count) {

0 commit comments

Comments
 (0)