获取Tensor维度的两种方法:

Tensor.get_shape()

返回TensorShape对象,

如果需要确定的数值而把TensorShape当作list使用,肯定是不行的。

需要调用TensorShape的as_list()方法,

需要调用TensorShape.as_list()方法来获取维度数值。

来实践一下:

import tensorflow as tf
a = tf.zeros(shape=[10,20])
b = a.get_shape()
c = b.as_list()
print(b)
print(c)

输出结果:

(10, 20)
[10, 20]

Tensorflow.shape()

返回Tensor对象,需要调用Session.run()方法来获取维度数值。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-05
  • 2022-01-03
  • 2022-12-23
  • 2022-12-23
  • 2021-10-16
猜你喜欢
  • 2022-12-23
  • 2021-11-05
  • 2022-12-23
  • 2022-12-23
  • 2022-03-08
  • 2022-12-23
  • 2021-10-06
相关资源
相似解决方案