我正在学习最新版本的 Tensorflow (2.0),并尝试运行一个简单的代码来分割矩阵。使用装饰器@tf.function 我做了以下类:
class Data:
def __init__(self):
pass
def back_to_zero(self, input):
time = tf.slice(input, [0,0], [-1,1])
new_time = time - time[0][0]
return new_time
@tf.function
def load_data(self, inputs):
new_x = self.back_to_zero(inputs)
print(new_x)
因此,当使用 numpy 矩阵运行代码时,我无法检索数字。
time = np.linspace(0,10,20)
magntiudes = np.random.normal(0,1,size=20)
x = np.vstack([time, magntiudes]).T
d = Data()
d.load_data(x)
输出:
Tensor("sub:0", shape=(20, 1), dtype=float64)
我需要以 numpy 格式获取此张量,但 TF 2.0 没有使用 run() 或 eval() 方法的类 tf.Session。
感谢您为我提供的任何帮助!