【问题标题】:Preprocessing the image on the server在服务器上预处理图像
【发布时间】:2019-04-16 22:16:17
【问题描述】:

如何在这个结构中实现调整大小功能? 比如in_imageshape = (845, 594, 3),但是我想把这张图片调整为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


    【解决方案1】:

    我想通了:

    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()
    

    【讨论】:

      猜你喜欢
      • 2010-09-13
      • 2011-02-04
      • 1970-01-01
      • 2019-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多