2

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?

Jason Ren
  • 125
  • 1
  • 1
  • 7
  • BTW, the sample code in tutorial is doing something like c/s online prediction. but I want to use it in my C++ project. – Jason Ren Sep 10 '17 at 08:54
  • The documentation on https://github.com/tensorflow/tensorflow/blob/master/tensorflow/docs_src/programmers_guide/saved_model.md should answer this question – Alexandre Passos Sep 11 '17 at 21:05
  • 1
    Possible duplicate of [How to import an saved Tensorflow model train using tf.estimator and predict on input data](https://stackoverflow.com/questions/46098863/how-to-import-an-saved-tensorflow-model-train-using-tf-estimator-and-predict-on) – rhaertel80 Sep 13 '17 at 14:58
  • Answer for loading into C++ here: https://stackoverflow.com/questions/46098863/how-to-import-an-saved-tensorflow-model-train-using-tf-estimator-and-predict-on/46139198?noredirect=1#comment79297585_46139198 – rhaertel80 Sep 13 '17 at 14:58

0 Answers0