代码之家  ›  专栏  ›  技术社区  ›  Austin

tensorflow.keras公司tensorflow服务预处理中的预处理器?

  •  0
  • Austin  · 技术社区  · 7 年前

    我正在转换tensorflow.keras公司估计量的模型及其应用 estimator.export_saved_mode(serving_input_receiver_fn=serving_input_receiver_fn) 让我的模型准备好为TensorFlow服务。这是我的 serving_input_receiver_fn 看起来像:

    def image_preprocessing(image):   
        image = tf.expand_dims(image, 0)
        image = tf.image.resize_bilinear(image, [HEIGHT, WIDTH], align_corners=False)
        image = tf.squeeze(image, axis=[0])
        image = tf.cast(image, dtype=tf.uint8)
        return image
    
    def serving_input_receiver_fn():
        def prepare_image(image_str_tensor):
            image = tf.image.decode_jpeg(image_str_tensor, channels=CHANNELS)
            return image_preprocessing(image)
    
        input_ph = tf.placeholder(tf.string, shape=[None], name='image_binary')
        images_tensor = tf.map_fn(prepare_image, input_ph, back_prop=False, dtype=tf.uint8)
        images_tensor = tf.image.convert_image_dtype(images_tensor, dtype=tf.float32)
    
        return tf.estimator.export.ServingInputReceiver(
            {model.input_names[0]: images_tensor},
            {'image_bytes': input_ph})
    

    是否有方法继续将uint8作为输入,但将其转换为float32,然后应用tensorflow.keras公司预处理功能,如 tensorflow.keras.applications.xception.preprocess_input ?

    我不知道如何根据平均值/标准差tensorflow.keras.应用模型。在添加上述内容之前,我的模型接受了numpy数组的json序列化列表,并且我会在客户端对它们进行规范化。既然它接受uint8 base64编码字节字符串,我不知道如何将keras规范化移到这个函数。

    1 回复  |  直到 7 年前
        1
  •  0
  •   sdcbr    7 年前

    如果您要在github上查找Xception的Keras实现, you'll notice that it uses the general imagenet preprocessing function 在回购协议中,大多数其他预先培训的模型都使用这种方法。这个函数应该在numpy数组以及Keras/TensorFlow张量上工作。因此,您应该能够导入它并将其添加到 image_preprocessing 功能。

    现在还不清楚你为什么要 tf.uint8 . 我希望预处理函数如下所示:

    def image_preprocessing(im):
        im = tf.expand_dims(im, 0)
        im = tf.image.resize_bilinear(im, [HEIGHT, WIDTH], align_corners=False)
        im = tf.squeeze(im, axis=[0])
        im = preprocess_input(im)
        return im
    
    推荐文章