#include <tf_graph.h>
Definition at line 26 of file tf_graph.h.
Definition at line 118 of file tf_graph.cc.
121 std::cout <<
"tf::Graph::dtor: " <<
"Close failed." <<
std::endl;
tensorflow::Session * fSession
QTextStream & endl(QTextStream &s)
tf::Graph::Graph |
( |
const char * |
graph_file_name, |
|
|
const std::vector< std::string > & |
outputs, |
|
|
bool & |
success, |
|
|
int |
ninputs, |
|
|
int |
noutputs |
|
) |
| |
|
private |
Not-throwing constructor.
Definition at line 18 of file tf_graph.cc.
26 tensorflow::SessionOptions
options;
27 tensorflow::ConfigProto &
config = options.config;
28 config.set_inter_op_parallelism_threads(1);
29 config.set_intra_op_parallelism_threads(1);
30 config.set_use_per_session_threads(
false);
39 tensorflow::GraphDef graph_def;
47 size_t ng = graph_def.node().size();
78 for (
size_t n = 0;
n < ng; ++
n)
80 name = graph_def.node()[
n].name();
81 auto pos = name.find(
"/");
82 if (
pos != std::string::npos) { basename = name.substr(0,
pos); }
86 for (
const auto &
s : outputs)
88 if (name.find(
s) != std::string::npos) { found =
true;
break; }
92 if (!last.empty() && (basename !=
current))
104 std::cout <<
"Output nodes not found in the graph." <<
std::endl;
tensorflow::Session * fSession
std::vector< std::string > fOutputNames
std::vector< std::string > fInputNames
QTextStream & endl(QTextStream &s)
Not-throwing constructor.
Definition at line 18 of file tf_graph.cc.
23 tensorflow::SessionOptions
options;
24 tensorflow::ConfigProto &
config = options.config;
25 config.set_inter_op_parallelism_threads(1);
26 config.set_intra_op_parallelism_threads(1);
27 config.set_use_per_session_threads(
false);
36 tensorflow::GraphDef graph_def;
44 size_t ng = graph_def.node().size();
48 if (outputs.empty()) {
fOutputNames.push_back(graph_def.node()[ng - 1].name()); }
52 for (
size_t n = 0;
n < ng; ++
n)
54 name = graph_def.node()[
n].name();
55 auto pos = name.find(
"/");
56 if (
pos != std::string::npos) { basename = name.substr(0,
pos); }
60 for (
const auto &
s : outputs)
62 if (name.find(
s) != std::string::npos) { found =
true;
break; }
66 if (!last.empty() && (basename !=
current))
78 std::cout <<
"Output nodes not found in the graph." <<
std::endl;
tensorflow::Session * fSession
std::vector< std::string > fOutputNames
QTextStream & endl(QTextStream &s)
Definition at line 29 of file tf_graph.h.
32 std::unique_ptr<Graph> ptr(
new Graph(graph_file_name, outputs, success));
33 if (success) {
return ptr; }
34 else {
return nullptr; }
Graph(const char *graph_file_name, const std::vector< std::string > &outputs, bool &success, int ninputs, int noutputs)
Not-throwing constructor.
static std::unique_ptr<Graph> tf::Graph::create |
( |
const char * |
graph_file_name, |
|
|
const std::vector< std::string > & |
outputs = {} , |
|
|
int |
ninputs = 1 , |
|
|
int |
noutputs = 1 |
|
) |
| |
|
inlinestatic |
Definition at line 32 of file tf_graph.h.
32 {},
int ninputs = 1,
int noutputs = 1)
35 std::unique_ptr<Graph> ptr(
new Graph(graph_file_name, outputs, success, ninputs, noutputs));
36 if (success) {
return ptr; }
37 else {
return nullptr; }
Graph(const char *graph_file_name, const std::vector< std::string > &outputs, bool &success, int ninputs, int noutputs)
Not-throwing constructor.
Definition at line 99 of file tf_graph.cc.
101 if (x.empty() || x.front().empty()) {
return std::vector<float>(); }
103 long long int rows = x.size(), cols = x.front().size();
105 tensorflow::Tensor _x(tensorflow::DT_FLOAT, tensorflow::TensorShape({ 1, rows, cols, 1 }));
106 auto input_map = _x.tensor<
float, 4>();
108 for (
long long int r = 0;
r < rows; ++
r) {
109 const auto &
row = x[
r];
110 for (
long long int c = 0;
c < cols; ++
c) {
111 input_map(0,
r,
c, 0) =
row[
c];
117 else {
return std::vector<float>(); }
std::vector< float > run(const std::vector< std::vector< float > > &x)
Definition at line 154 of file tf_graph.cc.
156 std::vector< std::pair<std::string, tensorflow::Tensor> >
inputs = {
162 std::vector<tensorflow::Tensor>
outputs;
169 size_t samples = 0, nouts = 0;
170 for (
size_t o = 0; o < outputs.size(); ++o)
172 if (o == 0) { samples = outputs[o].dim_size(0); }
173 else if ((
int)samples != outputs[o].dim_size(0))
175 throw std::string(
"TF outputs size inconsistent.");
177 nouts += outputs[o].dim_size(1);
181 std::vector< std::vector< float > >
result;
182 result.resize(samples, std::vector< float >(nouts));
185 for (
size_t o = 0; o < outputs.size(); ++o)
187 auto output_map = outputs[o].tensor<
float, 2>();
189 size_t n = outputs[o].dim_size(1);
190 for (
size_t s = 0;
s < samples; ++
s) {
191 std::vector< float > & vs = result[
s];
192 for (
size_t i = 0; i <
n; ++i) {
193 vs[idx0 + i] = output_map(
s, i);
203 return std::vector< std::vector< float > >();
tensorflow::Session * fSession
std::vector< std::string > fOutputNames
QTextStream & endl(QTextStream &s)
Definition at line 129 of file tf_graph.cc.
133 if ((samples == 0) || x.empty() || x.front().empty() || x.front().front().empty() || x.front().front().front().empty())
136 if ((samples == -1) || (samples > (
long long int)x.size())) { samples = x.size(); }
139 rows = x.front().size(),
140 cols = x.front().front().size(),
141 depth = x.front().front().front().size();
143 std::vector< tensorflow::Tensor > _x;
148 _x.push_back(tensorflow::Tensor(tensorflow::DT_FLOAT, tensorflow::TensorShape({ samples, rows, cols, depth })));
149 auto input_map = _x[0].tensor<
float, 4>();
150 for (
long long int s = 0;
s < samples; ++
s) {
151 const auto & sample = x[
s];
152 for (
long long int r = 0;
r < rows; ++
r) {
153 const auto &
row = sample[
r];
154 for (
long long int c = 0;
c < cols; ++
c) {
155 const auto & col =
row[
c];
156 for (
long long int d = 0;
d < depth; ++
d) {
157 input_map(
s,
r,
c,
d) = col[
d];
166 for(
int i=0; i<depth; ++i){
167 _x.push_back(tensorflow::Tensor(tensorflow::DT_FLOAT, tensorflow::TensorShape({ samples, rows, cols, 1 })));
172 for(
int view=0; view<depth; ++view){
173 auto input_map = _x[view].tensor<
float, 4>();
174 for (
long long int s = 0;
s < samples; ++
s) {
175 const auto & sample = x[
s];
176 for (
long long int r = 0;
r < rows; ++
r) {
177 const auto &
row = sample[
r];
178 for (
long long int c = 0;
c < cols; ++
c) {
179 const auto & col =
row[
c];
180 long long int d = view;
181 input_map(
s,
r,
c, 0) = col[
d];
std::vector< float > run(const std::vector< std::vector< float > > &x)
Definition at line 193 of file tf_graph.cc.
195 std::vector< std::pair<std::string, tensorflow::Tensor> >
inputs;
209 std::vector<tensorflow::Tensor>
outputs;
218 for (
size_t o = 0; o < outputs.size(); ++o)
220 if (o == 0) { samples = outputs[o].dim_size(0); }
221 else if ((
int)samples != outputs[o].dim_size(0))
223 throw std::string(
"TF outputs size inconsistent.");
227 std::vector< std::vector< std::vector< float > > >
result;
228 result.resize(samples,
std::vector< std::vector< float > >(outputs.size()));
230 for (
size_t s = 0;
s < samples; ++
s)
232 for (
size_t o = 0; o < outputs.size(); ++o)
234 size_t n = outputs[o].dim_size(1);
235 auto output_map = outputs[o].tensor<
float, 2>();
237 result[
s][o].resize(outputs[o].dim_size(1));
239 std::vector< float > & vs = result[
s][o];
240 for (
size_t i = 0; i <
n; ++i)
242 vs[i] = output_map(
s, i);
252 return std::vector< std::vector< std::vector< float > > >();
tensorflow::Session * fSession
std::vector< std::string > fOutputNames
std::vector< std::string > fInputNames
QTextStream & endl(QTextStream &s)
tensorflow::Session * tf::Graph::fSession |
|
private |
int tf::Graph::n_inputs = 1 |
int tf::Graph::n_outputs = 1 |
The documentation for this class was generated from the following files: