我正在检查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
(它是一个[[named Variable
])与x
相加(我假设在幕后将其转换为未命名 Variable
)。
summator = SummatorModule()
print(summator(number))
print(summator(number))
假设我将这个模型部署到应用程序中;因此我需要将数据输入模型中,但是由于x
没有名称,因此无法像以前使用placeholder
一样进行操作。那么如何在Tensorflow 2.0中将数据馈入已部署的模型中?甚至可能是TF 2.0服务器API也已更改,但是我找不到任何有关它的信息;我希望您能消除我的疑虑。