moving towards a tflow example
This commit is contained in:
1 parent
7c42e75ddd
commit
59369e1b2b
13 files changed
+171
-187
No files matched your search
Vendored
+40
@@ -108,6 +108,46 @@
|
||||
"/home/bts/spark/": "${workspaceRoot}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "TFTest ",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "/home/bts/spark/build/ninja_debug/sdk/examples/tf_test",
|
||||
"args": [
|
||||
],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "/home/bts/spark/build/ninja_debug/sdk/examples/",
|
||||
"environment": [],
|
||||
"externalConsole": true,
|
||||
"MIMode": "gdb",
|
||||
"preLaunchTask": "",
|
||||
"logging": {
|
||||
"engineLogging": false
|
||||
},
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Enable pretty-printing for gdb",
|
||||
"text": "enable pretty-printer",
|
||||
"ignoreFailures": true
|
||||
},
|
||||
{
|
||||
"description": "Skip STL",
|
||||
"text": "skip -gfi /usr/include/c++/7/bits/*.h",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
],
|
||||
"pipeTransport": {
|
||||
"pipeCwd": "${workspaceRoot}",
|
||||
"pipeProgram": "c:\\program files\\git\\usr\\bin\\ssh.exe",
|
||||
"pipeArgs": [
|
||||
"bts@sparkvm"
|
||||
],
|
||||
"debuggerPath": "/usr/bin/gdb"
|
||||
},
|
||||
"sourceFileMap": {
|
||||
"/home/bts/spark/": "${workspaceRoot}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Spreader Tests",
|
||||
"type": "cppdbg",
|
||||
|
||||
+4
-1
@@ -34,7 +34,7 @@ if (WIN32)
|
||||
else ()
|
||||
# so that sparkd looks for libspark.so in its directory
|
||||
set (CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
|
||||
set (CMAKE_INSTALL_RPATH ".")
|
||||
set (CMAKE_INSTALL_RPATH ".:./lib")
|
||||
|
||||
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} \
|
||||
-fPIC -Wall -pedantic -Wextra -Werror \
|
||||
@@ -58,6 +58,9 @@ else ()
|
||||
COMMAND mkdir ARGS -p ${CMAKE_BINARY_DIR}/server/plugins
|
||||
COMMAND ln ARGS -sf ${CMAKE_BINARY_DIR}/sdk/examples/order_plugin_example.so ${CMAKE_BINARY_DIR}/server/plugins/
|
||||
COMMAND ln ARGS -sf ${CMAKE_BINARY_DIR}/sdk/examples/ai_order_plugin_example.so ${CMAKE_BINARY_DIR}/server/plugins/
|
||||
COMMAND mkdir -p ${CMAKE_BINARY_DIR}/server/lib
|
||||
COMMAND ln ARGS -sf ${EXTERNALS_ROOT}/lib/libtensorflow.so ${CMAKE_BINARY_DIR}/server/lib/
|
||||
COMMAND ln ARGS -sf ${EXTERNALS_ROOT}/lib/libtensorflow_framework.so ${CMAKE_BINARY_DIR}/server/lib/
|
||||
COMMENT "Creating server runtime layout"
|
||||
DEPENDS sparkd data_files_dir)
|
||||
|
||||
|
||||
+1
-1
Submodule externals updated: c0486ec0f5...d026c5ed2e.
@@ -55,15 +55,16 @@ g++ -isystem ../externals/include \
|
||||
tf_test.cpp \
|
||||
../tensorflow/tfexecute.cpp \
|
||||
../tensorflow/tfloader.cpp \
|
||||
../tensorflow/tfstatus.cpp \
|
||||
-Wl,-rpath,. \
|
||||
-Wl,-rpath,.. \
|
||||
-Wl,-rpath,../lib \
|
||||
-L ../lib \
|
||||
-l spark \
|
||||
-L ../externals/lib \
|
||||
-l tensorflow \
|
||||
-l tensorflow_framework \
|
||||
-l tensorflow-core \
|
||||
-l nsync \
|
||||
-lpthread \
|
||||
-llttng-ust \
|
||||
-ldl
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
#include "tensorflow/core/platform/env.h"
|
||||
#include "tensorflow/core/public/session.h"
|
||||
#include "../tensorflow/tfstatus.h"
|
||||
#include "../tensorflow/tfloader.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
using namespace tensorflow;
|
||||
using namespace tensorflow::c;
|
||||
|
||||
int main()
|
||||
{
|
||||
Session* session;
|
||||
Status status = NewSession(SessionOptions(), &session);
|
||||
if (!status.ok()) {
|
||||
cout << status.ToString() << "\n";
|
||||
return 1;
|
||||
}
|
||||
cout << "Session successfully created.\n";
|
||||
TF_Session* session = nullptr;
|
||||
TFStatus status = bts::ml::create_tf_session(session);
|
||||
if (!status.ok()) {
|
||||
cout << status.code << "\n";
|
||||
return 1;
|
||||
}
|
||||
cout << "Session successfully created.\n";
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
/* Copyright 2016 Google Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==============================================================================*/
|
||||
|
||||
#ifndef TENSORFLOW_SERVING_SERVABLES_TENSORFLOW_SAVED_MODEL_BUNDLE_FACTORY_H_
|
||||
#define TENSORFLOW_SERVING_SERVABLES_TENSORFLOW_SAVED_MODEL_BUNDLE_FACTORY_H_
|
||||
|
||||
#include "tensorflow/cc/saved_model/loader.h"
|
||||
#include "tensorflow/core/lib/core/status.h"
|
||||
#include "tensorflow/core/platform/macros.h"
|
||||
#include "tensorflow_serving/servables/tensorflow/session_bundle_config.pb.h"
|
||||
|
||||
namespace tensorflow {
|
||||
namespace serving {
|
||||
|
||||
/// A factory that creates SavedModelBundles from SavedModel or SessionBundle
|
||||
/// export paths.
|
||||
///
|
||||
/// The emitted sessions only support Run(), and although not enforced it is
|
||||
/// expected that the client will only make non-mutating Run() calls. (If this
|
||||
/// restriction, which we've added as a safety measure, is problematic for your
|
||||
/// use-case please contact the TensorFlow Serving team to discuss disabling
|
||||
/// it.)
|
||||
///
|
||||
/// If the config calls for batching, the emitted sessions automatically batch
|
||||
/// Run() calls behind the scenes, using a SharedBatchScheduler owned by the
|
||||
/// factory. The 'config.num_batch_threads' threads are shared across all
|
||||
/// session instances created by this factory. However, each session has its own
|
||||
/// dedicated queue of size 'config.max_enqueued_batches'.
|
||||
///
|
||||
/// The factory can also estimate the resource (e.g. RAM) requirements of a
|
||||
/// SavedModelBundle based on the SavedModel (i.e. prior to loading the
|
||||
/// session).
|
||||
///
|
||||
/// This class is thread-safe.
|
||||
class SavedModelBundleFactory {
|
||||
public:
|
||||
/// Instantiates a SavedModelBundleFactory using a config.
|
||||
///
|
||||
/// @param config Config with initialization options.
|
||||
/// @param factory Newly created factory if the returned Status is OK.
|
||||
static Status Create(const SessionBundleConfig& config,
|
||||
std::unique_ptr<SavedModelBundleFactory>* factory);
|
||||
|
||||
/// Instantiates a bundle from a given export or SavedModel path.
|
||||
///
|
||||
/// @param path Path to the model.
|
||||
/// @param bundle Newly created SavedModelBundle if the returned Status is
|
||||
/// OK.
|
||||
Status CreateSavedModelBundle(const string& path,
|
||||
std::unique_ptr<SavedModelBundle>* bundle);
|
||||
|
||||
/// Estimates the resources a SavedModel bundle will use once loaded, from its
|
||||
/// export path.
|
||||
///
|
||||
/// @param path Path to the model.
|
||||
/// @param estimate Output resource usage estimates. Different kinds of
|
||||
/// resources (e.g. CPU, RAM, etc.) may get populated.
|
||||
// Status EstimateResourceRequirement(const string& path,
|
||||
// ResourceAllocation* estimate) const;
|
||||
|
||||
// const SessionBundleConfig& config() const { return config_; }
|
||||
|
||||
private:
|
||||
// using Batcher = SharedBatchScheduler<BatchingSessionTask>;
|
||||
|
||||
// SavedModelBundleFactory(const SessionBundleConfig& config,
|
||||
// std::shared_ptr<Batcher> batch_scheduler);
|
||||
|
||||
// const SessionBundleConfig config_;
|
||||
|
||||
// // A shared batch scheduler. One queue is used for each session this factory
|
||||
// // emits. If batching is not configured, this remains null.
|
||||
// std::shared_ptr<Batcher> batch_scheduler_;
|
||||
|
||||
TF_DISALLOW_COPY_AND_ASSIGN(SavedModelBundleFactory);
|
||||
};
|
||||
|
||||
} // namespace serving
|
||||
} // namespace tensorflow
|
||||
|
||||
#endif // TENSORFLOW_SERVING_SERVABLES_TENSORFLOW_SAVED_MODEL_BUNDLE_FACTORY_H_
|
||||
@@ -0,0 +1,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace tensorflow
|
||||
{
|
||||
namespace c
|
||||
{
|
||||
#include "tensorflow/c/c_api.h"
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,5 @@
|
||||
#include "tfexecute.h"
|
||||
|
||||
#include "tensorflow/core/public/session.h"
|
||||
#include "tensorflow/cc/saved_model/loader.h"
|
||||
|
||||
using namespace tensorflow;
|
||||
using std::vector;
|
||||
|
||||
@@ -11,17 +8,17 @@ namespace bts
|
||||
namespace ml
|
||||
{
|
||||
|
||||
tensorflow::Status execute(const tensorflow::SavedModelBundle& bundle,
|
||||
const vector<std::pair<std::string, tensorflow::Tensor> >& inputs,
|
||||
const vector<std::string>& output_tensor_names,
|
||||
const vector<std::string>& target_node_names,
|
||||
vector<tensorflow::Tensor>* outputs)
|
||||
{
|
||||
tensorflow::RunMetadata* run_metadata = nullptr;
|
||||
tensorflow::RunOptions run_options;
|
||||
Status status = bundle.session->Run(run_options, inputs, output_tensor_names, target_node_names, outputs, run_metadata);
|
||||
return status;
|
||||
}
|
||||
// tensorflow::Status execute(const tensorflow::SavedModelBundle& bundle,
|
||||
// const vector<std::pair<std::string, tensorflow::Tensor> >& inputs,
|
||||
// const vector<std::string>& output_tensor_names,
|
||||
// const vector<std::string>& target_node_names,
|
||||
// vector<tensorflow::Tensor>* outputs)
|
||||
// {
|
||||
// tensorflow::RunMetadata* run_metadata = nullptr;
|
||||
// tensorflow::RunOptions run_options;
|
||||
// Status status = bundle.session->Run(run_options, inputs, output_tensor_names, target_node_names, outputs, run_metadata);
|
||||
// return status;
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "tfstatus.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "tensorflow/core/platform/env.h"
|
||||
|
||||
|
||||
namespace tensorflow
|
||||
{
|
||||
@@ -15,10 +16,10 @@ namespace bts
|
||||
namespace ml
|
||||
{
|
||||
|
||||
tensorflow::Status execute(const tensorflow::SavedModelBundle& bundle,
|
||||
const std::vector<std::pair<std::string, tensorflow::Tensor> >& inputs,
|
||||
const std::vector<std::string>& output_tensor_names,
|
||||
const std::vector<std::string>& target_node_names,
|
||||
std::vector<tensorflow::Tensor>* outputs);
|
||||
// tensorflow::c::TFStatus execute(const tensorflow::c::TF_Session& session,
|
||||
// const std::vector<std::pair<std::string, tensorflow::c::TF_Tensor> >& inputs,
|
||||
// const std::vector<std::string>& output_tensor_names,
|
||||
// const std::vector<std::string>& target_node_names,
|
||||
// std::vector<tensorflow::Tensor>* outputs);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,10 @@
|
||||
#include "tfloader.h"
|
||||
#include "lib/utils/helper_macros.h"
|
||||
#include <vector>
|
||||
|
||||
|
||||
//no c++ yet
|
||||
//no c++ api yet
|
||||
//https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/label_image/main.cc
|
||||
#include "tensorflow/cc/saved_model/loader.h"
|
||||
|
||||
using namespace tensorflow;
|
||||
using namespace tensorflow::c;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
@@ -15,7 +13,44 @@ namespace bts
|
||||
{
|
||||
namespace ml
|
||||
{
|
||||
|
||||
tensorflow::c::TFStatus create_tf_session(TF_Session*& session)
|
||||
{
|
||||
TF_Graph* graph = TF_NewGraph();
|
||||
TF_SessionOptions* options = TF_NewSessionOptions();
|
||||
TF_Status* status = TF_NewStatus();
|
||||
session = TF_NewSession(graph, options, status);
|
||||
TFStatus stat(*status);
|
||||
TF_DeleteStatus(status);
|
||||
return stat;
|
||||
}
|
||||
|
||||
tensorflow::c::TFStatus load_tf_model(const std::string& export_dir, const std::unordered_set<std::string>& tags,
|
||||
TF_Session*& session)
|
||||
{
|
||||
vector<char*> ctags;
|
||||
for(auto& t : tags)
|
||||
ctags.push_back(const_cast<char*>(t.c_str()));
|
||||
|
||||
TF_SessionOptions* session_options = TF_NewSessionOptions();
|
||||
TF_Buffer* run_options = nullptr;
|
||||
TF_Buffer* meta_graph_def = TF_NewBuffer(); //TODO get the protos here
|
||||
TF_Graph* graph = TF_NewGraph();
|
||||
TF_Status* status = TF_NewStatus();
|
||||
session = TF_LoadSessionFromSavedModel(session_options, run_options, export_dir.c_str(), &ctags[0], ctags.size(),
|
||||
graph, meta_graph_def, status);
|
||||
TFStatus stat(*status);
|
||||
|
||||
TF_DeleteSessionOptions(session_options);
|
||||
TF_DeleteBuffer(run_options);
|
||||
TF_DeleteBuffer(meta_graph_def);
|
||||
TF_DeleteStatus(status);
|
||||
return stat;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// tensorflow::Status load_tf_model(const std::string& export_dir, const std::unordered_set<string>& tags, SavedModelBundle* const bundle)
|
||||
// {
|
||||
// tensorflow::SessionOptions session_options; //defaults
|
||||
@@ -42,34 +77,4 @@ namespace ml
|
||||
// stat = factory->CreateSavedModelBundle(export_dir, bundle);
|
||||
// }
|
||||
// return stat;
|
||||
// }
|
||||
|
||||
tensorflow::c::TFStatus load_tf_model(const std::string& export_dir, const std::unordered_set<std::string>& tags,
|
||||
TF_Session** session)
|
||||
{
|
||||
vector<char*> ctags;
|
||||
for(auto& t : tags)
|
||||
ctags.push_back(const_cast<char*>(t.c_str()));
|
||||
|
||||
TF_SessionOptions* session_options = TF_NewSessionOptions();
|
||||
TF_Buffer* run_options = nullptr;
|
||||
TF_Buffer* meta_graph_def = TF_NewBuffer(); //TODO get the protos here
|
||||
TF_Graph* graph = TF_NewGraph();
|
||||
TF_Status* status = TF_NewStatus();
|
||||
*session = TF_LoadSessionFromSavedModel(session_options, run_options, export_dir.c_str(), &ctags[0], ctags.size(),
|
||||
graph, meta_graph_def, status);
|
||||
std::string msg(TF_Message(status));
|
||||
TF_Code code = TF_GetCode(status);
|
||||
TFStatus stat;
|
||||
stat.error = msg;
|
||||
stat.code = code;
|
||||
|
||||
TF_DeleteSessionOptions(session_options);
|
||||
TF_DeleteBuffer(run_options);
|
||||
TF_DeleteBuffer(meta_graph_def);
|
||||
TF_DeleteStatus(status);
|
||||
return stat;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
// }
|
||||
@@ -1,38 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "tensorflow/core/platform/env.h"
|
||||
#include "tfstatus.h"
|
||||
#include <unordered_set>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
|
||||
namespace tensorflow
|
||||
{
|
||||
struct SavedModelBundle;
|
||||
namespace c
|
||||
{
|
||||
#include "tensorflow/c/c_api.h"
|
||||
struct TFStatus
|
||||
{
|
||||
std::string error;
|
||||
TF_Code code;
|
||||
bool ok() { return (int)code == 0; }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace bts
|
||||
{
|
||||
namespace ml
|
||||
{
|
||||
///call Status.ok() for a boolean
|
||||
// tensorflow::Status load_tf_model(const std::string& export_dir, const std::unordered_set<std::string>& tags,
|
||||
// tensorflow::SavedModelBundle* const bundle);
|
||||
// tensorflow::Status load_tf_model(const std::string& export_dir, const std::unordered_set<std::string>& tags,
|
||||
// std::unique_ptr<tensorflow::SavedModelBundle>* bundle);
|
||||
|
||||
|
||||
tensorflow::c::TFStatus create_tf_session(tensorflow::c::TF_Session*& session);
|
||||
tensorflow::c::TFStatus load_tf_model(const std::string& export_dir, const std::unordered_set<std::string>& tags,
|
||||
tensorflow::c::TF_Session** session);
|
||||
tensorflow::c::TF_Session*& session);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#include "tfstatus.h"
|
||||
|
||||
namespace tensorflow
|
||||
{
|
||||
namespace c
|
||||
{
|
||||
|
||||
TFStatus::TFStatus(TF_Status& stat)
|
||||
{
|
||||
std::string msg(TF_Message(&stat));
|
||||
this->error = msg;
|
||||
this->code = TF_GetCode(&stat);
|
||||
}
|
||||
|
||||
bool TFStatus::ok() const
|
||||
{
|
||||
return (int)code == 0;
|
||||
}
|
||||
|
||||
|
||||
}}
|
||||
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "tfapi.h"
|
||||
|
||||
|
||||
namespace tensorflow
|
||||
{
|
||||
namespace c
|
||||
{
|
||||
struct TFStatus
|
||||
{
|
||||
TFStatus(TF_Status&);
|
||||
bool ok() const;
|
||||
|
||||
std::string error;
|
||||
TF_Code code;
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user