def __call__(self, *args):
if args in self.cache:
print("(%s) retrieving value from cache"%self.name)
return self.cache[args]
with tf.variable_scope(self.name, reuse=not self.first_time):
scope = tf.get_variable_scope().name
if self.first_time:
self.scope = scope
print("(%s) running function for the first time"%self.name)
else:
assert self.scope == scope, "Tried calling function with a different scope"
print("(%s) running function on new inputs"%self.name)
self.first_time = False
out = self._call(*args)
self.cache[args] = out
return out
评论列表
文章目录