Python 3.x 如何在tensorflow中导入tensor_形状

Python 3.x 如何在tensorflow中导入tensor_形状,python-3.x,tensorflow,Python 3.x,Tensorflow,我在Python3.6 64位环境中使用tensorflow cpu 2.1。我使用 from tensorflow.python.framework import tensor_shape 导入tensor_形状,但在我的环境中,tensorflow.python.framework是无法解析的导入 我也试过了 from tensorflow import tensor_shape ,这也不起作用 有人知道如何在tensorflow cpu 2.1和python 3.6中导入tensor_

我在Python3.6 64位环境中使用tensorflow cpu 2.1。我使用

from tensorflow.python.framework import tensor_shape
导入tensor_形状,但在我的环境中,tensorflow.python.framework是无法解析的导入

我也试过了

from tensorflow import tensor_shape
,这也不起作用

有人知道如何在tensorflow cpu 2.1和python 3.6中导入tensor_形状吗?非常感谢

更新:我下载的代码使用

tf.random_uniform(tensor_shape.scalar(), minval=1.0, maxval=resize_scale)

,这就是导入tensor_形状模块的原因。

要获取tensor形状,只需使用以下行(注意,函数是
tf.shape
而不是
tensor_形状

#From official documentation
import tensorflow as tf
t = tf.constant([[[1, 1, 1], [2, 2, 2]], [[3, 3, 3], [4, 4, 4]]])
tf.shape(t)

可以使用以下方法导入张量_形状:

     from tensorflow_core.python.framework import tensor_shape

谢谢,但是代码只调用tensor_shape.scalar(),似乎tensor_shape不用于获取张量的形状。