I've trained a GAN with tensorflow and now I want to use it in my c++ project. My GAN is something like this(input and output are both images):
image = tf.placeholder(tf.float32, shape=[BATCH_SIZE, 3, SIZE, SIZE])
input = 2*((tf.cast(image, tf.float32)/255.)-.5) #0~255 to -1~1
output = GAN(input) #GAN is my network including many modules
And I've noticed that there is a saved_model
tools can save my model into a saved_model.pb
which I can use directly in C++.
My code to do so is like this:
tensor_input_info = tf.saved_model.utils.build_tensor_info(input)
tensor_output_info = tf.saved_model.utils.build_tensor_info(output)
gan_signature = (
tf.saved_model.signature_def_utils.build_signature_def(
inputs={'image': tensor_input_info},
outputs={'result': tensor_output_info},
method_name='gan'
)
)
legacy_init_op = tf.group(tf.tables_initializer(), name='legacy_init_op')
builder.add_meta_graph_and_variables(
session, [tf.saved_model.tag_constants.SERVING],
signature_def_map={
'my_gan':gan_signature
},
legacy_init_op=legacy_init_op)
builder.save()
Here I am not sure about key in dict.In this code I used "image" as the key to my input but I don't know if it is right.Even so I got a saved_model.pb
successfully.
And now I don't know what to do,how can I use it in my C++ project?