Preprocessing the image on the server












1














How can I implement the resize function in this construction?
For example, in_image has shape = (845, 594, 3), but I want to resize this image to shape = (299, 299, 3)



def main(_):
with tf.Graph().as_default() as graph:
input_graph = FLAGS.input_graph
saved_model_dir = FLAGS.saved_model_dir
# Read in the export graph
with tf.gfile.FastGFile(input_graph, 'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
tf.import_graph_def(graph_def, name='')

# Define SavedModel Signature (inputs and outputs)
in_image = graph.get_tensor_by_name('input:0')
inputs = {'image_bytes': tf.saved_model.utils.build_tensor_info(in_image)}

out_classes = graph.get_tensor_by_name('InceptionV3/Predictions/Reshape_1:0')
outputs = {'prediction':
tf.saved_model.utils.build_tensor_info(out_classes)}

signature = tf.saved_model.signature_def_utils.build_signature_def(
inputs=inputs,
outputs=outputs,
method_name='tensorflow/serving/predict'
)

with tf.Session(graph=graph) as sess:
# Save out the SavedModel.
b = saved_model_builder.SavedModelBuilder(saved_model_dir)
b.add_meta_graph_and_variables(sess,
[tf.saved_model.tag_constants.SERVING],
signature_def_map={'serving_default':
signature})
b.save()

if __name__ == '__main__':
tf.app.run()









share|improve this question





























    1














    How can I implement the resize function in this construction?
    For example, in_image has shape = (845, 594, 3), but I want to resize this image to shape = (299, 299, 3)



    def main(_):
    with tf.Graph().as_default() as graph:
    input_graph = FLAGS.input_graph
    saved_model_dir = FLAGS.saved_model_dir
    # Read in the export graph
    with tf.gfile.FastGFile(input_graph, 'rb') as f:
    graph_def = tf.GraphDef()
    graph_def.ParseFromString(f.read())
    tf.import_graph_def(graph_def, name='')

    # Define SavedModel Signature (inputs and outputs)
    in_image = graph.get_tensor_by_name('input:0')
    inputs = {'image_bytes': tf.saved_model.utils.build_tensor_info(in_image)}

    out_classes = graph.get_tensor_by_name('InceptionV3/Predictions/Reshape_1:0')
    outputs = {'prediction':
    tf.saved_model.utils.build_tensor_info(out_classes)}

    signature = tf.saved_model.signature_def_utils.build_signature_def(
    inputs=inputs,
    outputs=outputs,
    method_name='tensorflow/serving/predict'
    )

    with tf.Session(graph=graph) as sess:
    # Save out the SavedModel.
    b = saved_model_builder.SavedModelBuilder(saved_model_dir)
    b.add_meta_graph_and_variables(sess,
    [tf.saved_model.tag_constants.SERVING],
    signature_def_map={'serving_default':
    signature})
    b.save()

    if __name__ == '__main__':
    tf.app.run()









    share|improve this question



























      1












      1








      1


      0





      How can I implement the resize function in this construction?
      For example, in_image has shape = (845, 594, 3), but I want to resize this image to shape = (299, 299, 3)



      def main(_):
      with tf.Graph().as_default() as graph:
      input_graph = FLAGS.input_graph
      saved_model_dir = FLAGS.saved_model_dir
      # Read in the export graph
      with tf.gfile.FastGFile(input_graph, 'rb') as f:
      graph_def = tf.GraphDef()
      graph_def.ParseFromString(f.read())
      tf.import_graph_def(graph_def, name='')

      # Define SavedModel Signature (inputs and outputs)
      in_image = graph.get_tensor_by_name('input:0')
      inputs = {'image_bytes': tf.saved_model.utils.build_tensor_info(in_image)}

      out_classes = graph.get_tensor_by_name('InceptionV3/Predictions/Reshape_1:0')
      outputs = {'prediction':
      tf.saved_model.utils.build_tensor_info(out_classes)}

      signature = tf.saved_model.signature_def_utils.build_signature_def(
      inputs=inputs,
      outputs=outputs,
      method_name='tensorflow/serving/predict'
      )

      with tf.Session(graph=graph) as sess:
      # Save out the SavedModel.
      b = saved_model_builder.SavedModelBuilder(saved_model_dir)
      b.add_meta_graph_and_variables(sess,
      [tf.saved_model.tag_constants.SERVING],
      signature_def_map={'serving_default':
      signature})
      b.save()

      if __name__ == '__main__':
      tf.app.run()









      share|improve this question















      How can I implement the resize function in this construction?
      For example, in_image has shape = (845, 594, 3), but I want to resize this image to shape = (299, 299, 3)



      def main(_):
      with tf.Graph().as_default() as graph:
      input_graph = FLAGS.input_graph
      saved_model_dir = FLAGS.saved_model_dir
      # Read in the export graph
      with tf.gfile.FastGFile(input_graph, 'rb') as f:
      graph_def = tf.GraphDef()
      graph_def.ParseFromString(f.read())
      tf.import_graph_def(graph_def, name='')

      # Define SavedModel Signature (inputs and outputs)
      in_image = graph.get_tensor_by_name('input:0')
      inputs = {'image_bytes': tf.saved_model.utils.build_tensor_info(in_image)}

      out_classes = graph.get_tensor_by_name('InceptionV3/Predictions/Reshape_1:0')
      outputs = {'prediction':
      tf.saved_model.utils.build_tensor_info(out_classes)}

      signature = tf.saved_model.signature_def_utils.build_signature_def(
      inputs=inputs,
      outputs=outputs,
      method_name='tensorflow/serving/predict'
      )

      with tf.Session(graph=graph) as sess:
      # Save out the SavedModel.
      b = saved_model_builder.SavedModelBuilder(saved_model_dir)
      b.add_meta_graph_and_variables(sess,
      [tf.saved_model.tag_constants.SERVING],
      signature_def_map={'serving_default':
      signature})
      b.save()

      if __name__ == '__main__':
      tf.app.run()






      python tensorflow tensorflow-serving






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 12 at 7:14









      Aqueous Carlos

      289213




      289213










      asked Nov 12 at 6:53









      A. Valiullin

      64




      64
























          1 Answer
          1






          active

          oldest

          votes


















          0














          I figured it out:



          def main(_):
          with tf.Graph().as_default() as graph:
          input_graph = FLAGS.input_graph
          saved_model_dir = FLAGS.saved_model_dir
          # Read in the export graph
          with tf.gfile.FastGFile(input_graph, 'rb') as f:
          graph_def = tf.GraphDef()
          graph_def.ParseFromString(f.read())
          tf.import_graph_def(graph_def, name='')

          serialized_tf_example = tf.placeholder(tf.string, name='b64')
          jpeg = preprocess_image(serialized_tf_example)

          out, = tf.import_graph_def(graph.as_graph_def(),
          input_map={'input:0': jpeg},
          return_elements = ['InceptionV3/Predictions/Reshape_1:0'])

          inputs = {'inputs': tf.saved_model.utils.build_tensor_info(serialized_tf_example)}
          outputs = {'prediction': tf.saved_model.utils.build_tensor_info(out)}

          signature = tf.saved_model.signature_def_utils.build_signature_def(
          inputs=inputs,
          outputs=outputs,
          method_name='tensorflow/serving/predict'
          )
          with tf.Session(graph=graph) as sess:
          # Save out the SavedModel.
          b = saved_model_builder.SavedModelBuilder(saved_model_dir)
          b.add_meta_graph_and_variables(sess,
          [tf.saved_model.tag_constants.SERVING],
          signature_def_map={'serving_default': signature})
          b.save()





          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53257165%2fpreprocessing-the-image-on-the-server%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            I figured it out:



            def main(_):
            with tf.Graph().as_default() as graph:
            input_graph = FLAGS.input_graph
            saved_model_dir = FLAGS.saved_model_dir
            # Read in the export graph
            with tf.gfile.FastGFile(input_graph, 'rb') as f:
            graph_def = tf.GraphDef()
            graph_def.ParseFromString(f.read())
            tf.import_graph_def(graph_def, name='')

            serialized_tf_example = tf.placeholder(tf.string, name='b64')
            jpeg = preprocess_image(serialized_tf_example)

            out, = tf.import_graph_def(graph.as_graph_def(),
            input_map={'input:0': jpeg},
            return_elements = ['InceptionV3/Predictions/Reshape_1:0'])

            inputs = {'inputs': tf.saved_model.utils.build_tensor_info(serialized_tf_example)}
            outputs = {'prediction': tf.saved_model.utils.build_tensor_info(out)}

            signature = tf.saved_model.signature_def_utils.build_signature_def(
            inputs=inputs,
            outputs=outputs,
            method_name='tensorflow/serving/predict'
            )
            with tf.Session(graph=graph) as sess:
            # Save out the SavedModel.
            b = saved_model_builder.SavedModelBuilder(saved_model_dir)
            b.add_meta_graph_and_variables(sess,
            [tf.saved_model.tag_constants.SERVING],
            signature_def_map={'serving_default': signature})
            b.save()





            share|improve this answer


























              0














              I figured it out:



              def main(_):
              with tf.Graph().as_default() as graph:
              input_graph = FLAGS.input_graph
              saved_model_dir = FLAGS.saved_model_dir
              # Read in the export graph
              with tf.gfile.FastGFile(input_graph, 'rb') as f:
              graph_def = tf.GraphDef()
              graph_def.ParseFromString(f.read())
              tf.import_graph_def(graph_def, name='')

              serialized_tf_example = tf.placeholder(tf.string, name='b64')
              jpeg = preprocess_image(serialized_tf_example)

              out, = tf.import_graph_def(graph.as_graph_def(),
              input_map={'input:0': jpeg},
              return_elements = ['InceptionV3/Predictions/Reshape_1:0'])

              inputs = {'inputs': tf.saved_model.utils.build_tensor_info(serialized_tf_example)}
              outputs = {'prediction': tf.saved_model.utils.build_tensor_info(out)}

              signature = tf.saved_model.signature_def_utils.build_signature_def(
              inputs=inputs,
              outputs=outputs,
              method_name='tensorflow/serving/predict'
              )
              with tf.Session(graph=graph) as sess:
              # Save out the SavedModel.
              b = saved_model_builder.SavedModelBuilder(saved_model_dir)
              b.add_meta_graph_and_variables(sess,
              [tf.saved_model.tag_constants.SERVING],
              signature_def_map={'serving_default': signature})
              b.save()





              share|improve this answer
























                0












                0








                0






                I figured it out:



                def main(_):
                with tf.Graph().as_default() as graph:
                input_graph = FLAGS.input_graph
                saved_model_dir = FLAGS.saved_model_dir
                # Read in the export graph
                with tf.gfile.FastGFile(input_graph, 'rb') as f:
                graph_def = tf.GraphDef()
                graph_def.ParseFromString(f.read())
                tf.import_graph_def(graph_def, name='')

                serialized_tf_example = tf.placeholder(tf.string, name='b64')
                jpeg = preprocess_image(serialized_tf_example)

                out, = tf.import_graph_def(graph.as_graph_def(),
                input_map={'input:0': jpeg},
                return_elements = ['InceptionV3/Predictions/Reshape_1:0'])

                inputs = {'inputs': tf.saved_model.utils.build_tensor_info(serialized_tf_example)}
                outputs = {'prediction': tf.saved_model.utils.build_tensor_info(out)}

                signature = tf.saved_model.signature_def_utils.build_signature_def(
                inputs=inputs,
                outputs=outputs,
                method_name='tensorflow/serving/predict'
                )
                with tf.Session(graph=graph) as sess:
                # Save out the SavedModel.
                b = saved_model_builder.SavedModelBuilder(saved_model_dir)
                b.add_meta_graph_and_variables(sess,
                [tf.saved_model.tag_constants.SERVING],
                signature_def_map={'serving_default': signature})
                b.save()





                share|improve this answer












                I figured it out:



                def main(_):
                with tf.Graph().as_default() as graph:
                input_graph = FLAGS.input_graph
                saved_model_dir = FLAGS.saved_model_dir
                # Read in the export graph
                with tf.gfile.FastGFile(input_graph, 'rb') as f:
                graph_def = tf.GraphDef()
                graph_def.ParseFromString(f.read())
                tf.import_graph_def(graph_def, name='')

                serialized_tf_example = tf.placeholder(tf.string, name='b64')
                jpeg = preprocess_image(serialized_tf_example)

                out, = tf.import_graph_def(graph.as_graph_def(),
                input_map={'input:0': jpeg},
                return_elements = ['InceptionV3/Predictions/Reshape_1:0'])

                inputs = {'inputs': tf.saved_model.utils.build_tensor_info(serialized_tf_example)}
                outputs = {'prediction': tf.saved_model.utils.build_tensor_info(out)}

                signature = tf.saved_model.signature_def_utils.build_signature_def(
                inputs=inputs,
                outputs=outputs,
                method_name='tensorflow/serving/predict'
                )
                with tf.Session(graph=graph) as sess:
                # Save out the SavedModel.
                b = saved_model_builder.SavedModelBuilder(saved_model_dir)
                b.add_meta_graph_and_variables(sess,
                [tf.saved_model.tag_constants.SERVING],
                signature_def_map={'serving_default': signature})
                b.save()






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 12 at 16:36









                A. Valiullin

                64




                64






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53257165%2fpreprocessing-the-image-on-the-server%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Florida Star v. B. J. F.

                    Danny Elfman

                    Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues