Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing a model trained in skflow using the Tensorflow C++ API

Is it possible to execute a graph using the Tensorflow C++ API that does not have labeled input (or output) nodes? As far as I know, when training my model (using skflow in python, which I then later saved as a binary protobuf), I did not have labeled input/output nodes, yet I was able to restore the model and do predictions without difficulty in Python. When using the C++ API to execute a graph, the input Vectors are pairs of Strings and Tensors, where I'm assuming the String refers to the label of an input node. From the docs:

Session::Run(const std::vector< std::pair< string, Tensor > > &inputs,
const std::vector< string > &output_tensor_names,
const std::vector< string > &target_node_names,
std::vector< Tensor > *outputs)=0

Runs the graph with the provided input tensors and fills outputs for the endpoints specified in output_tensor_names. Runs to but does not return Tensors for the nodes in target_node_names.

Is there any way I can execute the graph without knowing the labels of my input/output nodes? Perhaps there's a way I can load the graph in Python, give the nodes labels, and then save it out as a protobuf again? Ideally I'd like to just pass in a vector which is applied to the input nodes and not have to worry about any labels.

like image 757
luna_ Avatar asked Mar 14 '23 10:03

luna_


2 Answers

In skflow all nodes already have labels and it just takes care of restoring them for you.

Default names are input:0 and output:0 for X and y respectively and then some custom names for predictions and loss depending on the model you have used.

The way to find out the names of predictions and probability nodes is to take a look at endpoints file in the directory you saved the model (if you used estimator.save(path) for saving).

It should look like this:

input:0

output:0

logistic_regression/softmax_classifier/Softmax

logistic_regression/softmax_classifier/xent:0

Where first two are names of the input/output nodes and second two are prediction and loss nodes.

like image 113
ilblackdragon Avatar answered Apr 27 '23 01:04

ilblackdragon


If you can "restore the model and do predictions without difficulty in Python", then you can find out the names/labels of the input nodes or tensors using their "name" property, search for ".name" in either:

https://www.tensorflow.org/versions/0.6.0/api_docs/python/framework.html#Operation or: https://www.tensorflow.org/versions/0.6.0/api_docs/python/framework.html#Tensor

All nodes have names/labels whether you have explicitly named them or not.

like image 23
Josh11b Avatar answered Apr 27 '23 02:04

Josh11b