tfgo
tfgo copied to clipboard
Create mapping from model for model.Exec
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.
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 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?
Can we tell placeholders from regular operations? I mean those operations that we get from Graph.Operations()?
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.