tensorflow 如何让程序在不将tf_func()移出循环的情况下结束?

9q78igpj  于 3个月前  发布在  其他
关注(0)|答案(2)|浏览(37)

问题类型

支持

你是否在TF nightly版本中复现了这个bug?

来源

源代码

Tensorflow版本

tf 2.11.0

自定义代码

OS平台和发行版

Windows 11

移动设备

  • 无响应*

Python版本

3.7.16

Bazel版本

  • 无响应*

GCC/编译器版本

  • 无响应*

CUDA/cuDNN版本

  • 无响应*

GPU型号和内存大小

  • 无响应*

当前行为?

Code doesn't work correctly.

独立代码以重现问题

import tensorflow as tf
import numpy as np

class test:
    def __init__(self):
        self.counter=None
    
    
    def sum_func(self):
        if np.sum(self.counter)==1875:
            return True
    
    
    @tf.function
    def tf_func(self):
        flag=self.sum_func()
        return flag
    
    
    def counter_func(self):
        while True:
            for i in range(1875):
                if i==0:
                    self.counter=np.array(1)
                else:
                    self.counter=np.append(self.counter,np.array(1))
                flag=self.tf_func()
                if flag==True:
                    return

t=test()
t.counter_func()

相关日志输出

  • 无响应*
svmlkihl

svmlkihl1#

我能够在 TF 2.11 中重现这个问题。请查看以下代码片段:

@tilakrayal
请问您能否调查一下这个问题?非常感谢。
drnojrws

drnojrws2#

实际上,tf_func()只被调用一次,但我想保留@tf.function。here

相关问题