Tensorflow serving variable file

661 Views Asked by At

I'm about to do tensorflow serving.

pb file and variable folder are created. but No file was created under the variable folder.

like this

    └── variables
        ├── variables.data-00000-of-00001
        └── variables.index

After further experimentation, I found that the file only occurs when output is output to tf.Variable.

for example

1) z = tf.Variable(3,dtype=tf.float32)

2) z = tf.constant(3,dtype=tf.float32)

1) is created the file but 2) is not created file

z is output variable

signature_def_map= {
                "serving_default": tf.saved_model.signature_def_utils.predict_signature_def( 
                    inputs= {"egg": x, "bacon":y},
                    outputs= {"spam": z})
            })

Is it right that I found out?

The above explanation is a test result as a simple example.

This is what I really want to do

sIdSorted = tf.gather(sId, indices[::-1])[0:5]
sess=tf.Session()
print sess.run(sIdSorted,feed_dict={userLat:37.12,userLon:127.2}) 

As a result of printing, it was output as follows. ['s7' 's1' 's2' 's3' 's4']

However, in this way, nothing is displayed in the variable folder.....

So I tried to output to tf.variable.

sIdSorted = tf.Variable(tf.gather(sId, indices[::-1])[0:5])

but This will output an error to the following.

initial_value must have a shape specified: Tensor("strided_slice_1:0", dtype=string)

so I tried it as follows.

sIdSorted = tf.Variable(tf.constant(tf.gather(sId, indices[::-1])[0:5],shape=[5])) 

but This will output an error to the following.

List of Tensors when single Tensor expected

I need your help. Thank you for reading.

**tensorflow version :1.3.0 python 2.x

1

There are 1 best solutions below

0
On

That is correct: only tf.Variables result in variable files being exported. Those files contain the actual values of the variables. The graph structure itself is stored in the saved_model.pb. That's where your gather (and any other ops) are. You should be able to serve the model.