[英]strange behavior of tensorflow decorator @tf.function
有人可以解释这段代码的行为:
class Count:
def __init__(self):
self.count=0
def increment(self):
self.count+=1
tf.print(self.count)
class SurCount:
def __init__(self,count):
self.count=count
@tf.function
def step(self):
self.count.increment()
def start(self):
for i in range(10):
self.step()
count=Count()
surCount=SurCount(count)
surCount.start()
返回 1,1,1,1,1...(计数器不增加)。
下一个代码有效:它返回 1,2,3,...
class SurCount:
def __init__(self,count):
self.count=count
@tf.function
def start(self):
for i in range(10):
self.count.increment()
count=Count()
surCount=SurCount(count)
surCount.start()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.