17、Tensorflow:tf.shape(xxx) vs. xxx.get_shape()
2018-01-15 18:28
465 查看
tf.shape(xxx) 和 xxx.get_shape()比较
相同点:都可以得到tensor xxx 的尺寸
不同点:tf.shape(xxx)中xxx数据的类型可以是tensor,list,array;而xxx.get_shape()中的xxx的数据类型必须是tensor,且返回的是一个tuple.可以通过xxx.get_shape().as_list()得到一个list。
例如:
2
3
4
5
输出:
2
3
注意:dtype=int32是tf.shape()这个op的输出类型,默认为tf.int32。
相同点:都可以得到tensor xxx 的尺寸
不同点:tf.shape(xxx)中xxx数据的类型可以是tensor,list,array;而xxx.get_shape()中的xxx的数据类型必须是tensor,且返回的是一个tuple.可以通过xxx.get_shape().as_list()得到一个list。
例如:
x= tf.truncated_normal([32, 32, 3], dtype=tf.float32) print(tf.shape(x)) print(x.get_shape()) print(x.get_shape().as_list())1
2
3
4
5
输出:
Tensor("Shape:0", shape=(3,), dtype=int32) (32, 32, 3) [32, 32, 3]1
2
3
注意:dtype=int32是tf.shape()这个op的输出类型,默认为tf.int32。
相关文章推荐
- tensorflow学习之路(4):tf.shape(xxx) vs. xxx.get_shape()
- Tensorflow -tf.shape(a)和a.get_shape()
- TensorFlow教程——获取Tensor的维度(tf.shape(x)、x.shape和x.get_shape()的区别)
- TensorFlow 学习:tensor.get_shape() 与 tf.shape(a)
- tf.reshape和tf.Tensor.get_shape()
- TensorFlow学习--tf.add_to_collection与tf.get_collection使用
- tensorflow学习笔记--tf.get_variable、tf.Variable
- tensorflow学习——tf.get_collection(), tf.identity()
- tf.shape()与tf.get_shape()
- 【tensorflow】scope的使用以及tf.Variable()和tf.get_variable()的区别
- tensorflow里的tf.contrib.framework.get_global_step()
- TensorFlow 学习(一)—— tf.get_variable() vs tf.Variable(),tf.name_scope() vs tf.variable_scope()
- 简单Tensorflow线性拟合类及tf.get_variable()使用示例
- tensorflow共享变量, tf.get_variable() 和 tf.Varibele()的区别
- 【tensorflow 学习】tf.get_variable()和tf.Variable()的区别
- tensorflow的共享变量,tf.Variable(),tf.get_variable(),tf.Variable_scope(),tf.name_scope()联系与区别:
- tf.shape和get_shape()
- tensorflow学习笔记(九):tf.shape()与tensor.get_shape()
- [Tensorflow]Sharing Variables 共享权值【tf.get_variable 和 tf.variable_scope】
- TensorFlow 学习(一)—— tf.get_variable() vs tf.Variable(),tf.name_scope() vs tf.variable_scope()