tf.shape(a)和a.get_shape()
来源:互联网 发布:平板电脑淘宝开店认证 编辑:程序博客网 时间:2024/06/03 17:47
1,tf.shape(a)和a.get_shape()比较
相同点:都可以得到tensor a的尺寸
不同点:tf.shape()中a 数据的类型可以是tensor, list, array
a.get_shape()中a的数据类型只能是tensor,且返回的是一个元组(tuple)
2,例子:
import tensorflow as tf import numpy as np x=tf.constant([[1,2,3],[4,5,6]] y=[[1,2,3],[4,5,6]] z=np.arange(24).reshape([2,3,4])) sess=tf.Session() # tf.shape() x_shape=tf.shape(x) # x_shape 是一个tensor y_shape=tf.shape(y) # <tf.Tensor 'Shape_2:0' shape=(2,) dtype=int32> z_shape=tf.shape(z) # <tf.Tensor 'Shape_5:0' shape=(3,) dtype=int32> print sess.run(x_shape) # 结果:[2 3] print sess.run(y_shape) # 结果:[2 3] print sess.run(z_shape) # 结果:[2 3 4] #a.get_shape() x_shape=x.get_shape() # 返回的是TensorShape([Dimension(2), Dimension(3)]),不能使用 sess.run() 因为返回的不是tensor 或string,而是元组 x_shape=x.get_shape().as_list() # 可以使用 as_list()得到具体的尺寸,x_shape=[2 3] y_shape=y.get_shape() # AttributeError: 'list' object has no attribute 'get_shape' z_shape=z.get_shape() # AttributeError: 'numpy.ndarray' object has no attribute 'get_shape' 或者a.shape.as_list()
阅读全文
0 0
- Tensorflow -tf.shape(a)和a.get_shape()
- tf.shape(a)和a.get_shape()
- Tensorflow API 学习(2)-tf.shape(a)和a.get_shape()
- tf.shape和get_shape()
- tf.shape()与tf.get_shape()
- tensorflow学习笔记(九):tf.shape()与tensor.get_shape()
- tensorflow学习之路(4):tf.shape(xxx) vs. xxx.get_shape()
- tensorflow学习之路(4):tf.shape(xxx) vs. xxx.get_shape()
- Creating a Shape from a Stroked Shape
- write a tf listener
- tf.greater(a,b)
- Tf.shape
- Writing a tf broadcaster (C++)
- Writing a tf listener (C++)
- A Feature Descriptor: Shape Context
- tf教程(二):Writing a tf broadcaster
- tf教程(三):Writing a tf listener
- tf教程(四):Adding a frame
- cdn学习
- HDU 2014 青年歌手大奖赛_评委会打分
- 第九章 JSP标签
- 667. Beautiful Arrangement II(Java)
- 基于lua服务器
- tf.shape(a)和a.get_shape()
- Js作用域与作用域链详解
- MyBatis框架中Mapper类中方法的返回类型问题解决方案
- 在ubuntu下python编码问题
- 【JZOJ5343】【NOIP模拟】健美猫(模拟)
- 分享下学习Kotlin的历程-数据类型(2)
- HDU 2015 偶数求和
- java 实现 计算tfidf 使用ik分词
- Java代理模式