如何查看tensorshape
时间: 2023-09-09 16:11:00 浏览: 144
要查看Tensor的shape,可以使用`tf.shape()`函数或者`.get_shape()`方法。下面是两个示例:
1. 使用`tf.shape()`函数:
```python
import tensorflow as tf
# 定义一个Tensor
X = tf.placeholder(tf.int32, shape=[None, 64, 64, 3])
# 输出Tensor的shape
print(tf.shape(X))
```
上述代码将输出一个Tensor,其shape是一个一维的Tensor:`Tensor("Shape:0", shape=(4,), dtype=int32)`。
2. 使用`.get_shape()`方法:
```python
import tensorflow as tf
# 定义一个Tensor
X = tf.placeholder(tf.int32, shape=[None, 64, 64, 3])
# 输出Tensor的shape
print(X.get_shape())
```
上述代码将输出一个字符串,表示Tensor的shape:`(?, 64, 64, 3)`。
以上是使用TensorFlow查看Tensor的shape的两种方法。你可以根据自己的需要选择其中一种来使用。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [tensorflow在sess之前查看graph中tensor的shape](https://blog.csdn.net/Bismarckczy/article/details/85211239)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [tensorflow之获取tensor的shape作为max_pool的ksize实例](https://download.csdn.net/download/weixin_38631182/13762235)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [pytorch炼丹工具必备——自动查看每个Tensor的shape](https://blog.csdn.net/m0_51246196/article/details/126415180)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文