将数据馈入Tensorflow 2.0中的已部署模型

时间:2019-11-19 20:58:53

标签: tensorflow tensorflow-serving tensorflow2.0

我正在检查Tensorflow 2.0的新功能,发现placeholder已过时。现在可以直接使用python对象了。

# Define the SummatorModule that sum the submitted value with the previously
# submitted one
class SummatorModule(tf.Module):
    def __init__(self):
        super(SummatorModule, self).__init__()
        self.a = tf.Variable(tf.zeros(shape=(1, 1)), name='a')

    @tf.function
    def __call__(self, x):
        self.a.assign(self.a + x)
        return self.a

您将在这里看到:self.a.assign(self.a + x),我将self.a(以命名 Variable)和{{1}假设在后台将其转换为未命名 x)。

我可以通过以下方式在python中使用此模块:

Variable

让我们假设将此模型部署到应用程序中;因此我需要将数据输入模型中,但是由于summator = SummatorModule() print(summator(number)) print(summator(number)) 没有名称,因此无法像以前使用x一样进行操作。那么如何在Tensorflow 2.0中将数据馈入已部署的模型中?

可能甚至TF 2.0服务器API也已更改,但是我找不到任何有关它的信息;我希望你能消除我的疑虑。

1 个答案:

答案 0 :(得分:0)

新的save_model包含输入/输出的签名。实际上Tensorflow 2.0 C API尚未发布,但可能是解析元数据并获取这些信息的一种方式。

相关问题