废话少说,直接上代码:
def tensor_to_numpy(x):
tmp = x
with tf.Session() as sess:
print(tmp)
arr = tmp.eval()
# print(b)
# print(arr)
return arr
#然后调用该函数即可,如:
array = tensor_to_numpy(x)
不得不说,习惯了Pytorch后突然改用Tensorflow太不习惯了,Tensorflow版本不兼容真是个硬伤,搞完这个赶紧转Torch吧。