Tensorflow serving 推理调用的函数不是call而是自定义的函数,那怎么调用serving的接口?

调用代码如下, 求求各位大佬救救孩子


@tf.function(
            experimental_relax_shapes=True,
            input_signature=[
                tf.TensorSpec(shape, dtype=tf.float32),
                tf.TensorSpec([None, 1], dtype=tf.int32),
            ]
        )
        def recognize_tflite(features, length):
            logits = self.call(features, training=False)

            probs = tf.nn.softmax(logits)
            decoded = tf.keras.backend.ctc_decode(
                y_pred=probs, input_length=tf.squeeze(length, -1), greedy=True
            )[0][0]
            return [decoded]
1 Like

@snowkylin @huan @dpinthinker 来救救孩子 :wink:

已解决.
需要在save model 时指定签名.

# 指定默认签名为 recognize_pb
recognize_pb = am_model.recognize_pb.get_concrete_function(tf.TensorSpec([None, None, 1], dtype=tf.float32),
                                                               tf.TensorSpec([None, 1], dtype=tf.int32))
# 然后保存模型
tf.saved_model.save(am.model, 'tools/serving_model30/1/', signatures=recognize_pb)
1 Like