tfgo icon indicating copy to clipboard operation
tfgo copied to clipboard

Create mapping from model for model.Exec

Open Arnold1 opened this issue 5 years ago • 4 comments

Hi,

Is there a way to automatically create the mapping for the Placeholder (e.g. Placeholder_1) to the input name (e.g. Height) from the model?

Also is there a way to automatically read the "prob_out" from the model?

[]tf.Output and map[tf.Output]*tf.Tensor are both used for model.Exec:

height, _ := tf.NewTensor([1]int64{"Height"})
width, _ := tf.NewTensor([1]int64{"Width"})

results := model.Exec([]tf.Output{
    model.Op("prob_out", 0),
}, map[tf.Output]*tf.Tensor{
   model.Op("Placeholder_1", 0): height,
   model.Op("Placeholder_2", 0): width,
})

Thanks.

Arnold1 avatar Feb 17 '20 07:02 Arnold1

Hi @Arnold1 at the moment there isn't a way to do these things automatically, but it should be easy to add some helper function. However, you will have to manually write the input names of your tensors anyway (since although present in the SavedModels file, you are the only one that knows how to map a name e.g. "Placeholder_1" to a meaningful tf.Tensor e.g. height).

galeone avatar Feb 18 '20 16:02 galeone

@galeone ok, any idea how Tensorflow serving is able to figure it out - maybe there is a way to do it similar? does this mapping have an official name - for input and output tensors?

Arnold1 avatar Feb 20 '20 02:02 Arnold1

Can we tell placeholders from regular operations? I mean those operations that we get from Graph.Operations()?

ninedraft avatar Nov 19 '20 09:11 ninedraft

Yes I guess we can look for the string "placeholder_" in the op.Name (if this is an existing attribute, I don't remember correctly right now).

But this is not general, since during the graph creation phase I can rename the input placeholders as I want, thus the search for the name will fail.

galeone avatar Nov 19 '20 10:11 galeone