在tensorflow中将稀疏张量密集形状转换为整数值
如果我想得到tensorflow中法线张量的形状,并将值存储在一个列表中,我将使用以下方法在tensorflow中将稀疏张量密集形状转换为整数值,tensorflow,machine-learning,deep-learning,Tensorflow,Machine Learning,Deep Learning,如果我想得到tensorflow中法线张量的形状,并将值存储在一个列表中,我将使用以下方法 a_shape=[a.shape[0].value , a.shape[1].value] 如果我没弄错的话,使用.value将张量中的元素转换为实数 对于稀疏张量,我键入以下内容 a_sparse_shape=[a.dense_shape[0].value, a.dense_shape[1].value] 但是,我收到了错误消息 “'Tensor'对象没有属性'value'” 有人有其他解决方案吗?
a_shape=[a.shape[0].value , a.shape[1].value]
如果我没弄错的话,使用.value将张量中的元素转换为实数
对于稀疏张量,我键入以下内容
a_sparse_shape=[a.dense_shape[0].value, a.dense_shape[1].value]
但是,我收到了错误消息
“'Tensor'对象没有属性'value'”
有人有其他解决方案吗?是的,有一种替代方案:
import tensorflow as tf
tensor = tf.random_normal([2, 2, 2, 3])
tensor_shape = tensor.get_shape().as_list()
print(tensor_shape)
# [2, 2, 2, 3]
对于稀疏张量也一样:
sparse_tensor = tf.SparseTensor(indices=[[0,0], [1, 1]],
values=[1, 2],
dense_shape=[2, 2])
sparse_tensor_shape = sparse_tensor.get_shape().as_list()
print(sparse_tensor_shape)
# [2, 2]
你对tensorflow的看法是什么
a.shape
也可以在version=1.13
上使用稀疏张量正常运行。