3 回答
TA贡献2039条经验 获得超7个赞
import tensorflow as tf
a = tf.convert_to_tensor([
[ 138.7087, 670.4597, 194.0305, 788.7614],
[1744.7915, 597.5836, 1790.3419, 709.9775],
[ 384.6486, 526.4615, 428.3247, 622.8542],
...
[ 152.5436, 322.7310, 196.8471, 429.3589],
[ 164.2602, 322.5941, 195.3645, 386.3824]
])
b = tf.unstack(a, axis=0)
TA贡献1880条经验 获得超4个赞
假设t是你的张量对象。
ax1 = t.shape[1]
for i in range(ax1):
vals = t[:,i]
# do stuff
TA贡献1155条经验 获得超0个赞
用于tf.split()获取张量列表(每行一个):
boxes = tf.constant([[ 138.7087, 670.4597, 194.0305, 788.7614],
[1744.7915, 597.5836, 1790.3419, 709.9775],
[ 384.6486, 526.4615, 428.3247, 622.8542],
[1396.4264, 562.2295, 1444.1472, 653.7578],
[1135.2161, 504.2900, 1169.5103, 608.7569],
[1035.7961, 771.2336, 1100.9679, 919.1385]],)
tf.split(boxes, num_or_size_splits=boxes.shape[0], axis = 0)
[<tf.Tensor: shape=(1, 4), dtype=float32, numpy=array([[138.7087, 670.4597, 194.0305, 788.7614]], dtype=float32)>,
<tf.Tensor: shape=(1, 4), dtype=float32, numpy=array([[1744.7915, 597.5836, 1790.3419, 709.9775]], dtype=float32)>,
<tf.Tensor: shape=(1, 4), dtype=float32, numpy=array([[384.6486, 526.4615, 428.3247, 622.8542]], dtype=float32)>,
<tf.Tensor: shape=(1, 4), dtype=float32, numpy=array([[1396.4264, 562.2295, 1444.1472, 653.7578]], dtype=float32)>,
<tf.Tensor: shape=(1, 4), dtype=float32, numpy=array([[1135.2161, 504.29 , 1169.5103, 608.7569]], dtype=float32)>,
<tf.Tensor: shape=(1, 4), dtype=float32, numpy=array([[1035.7961, 771.2336, 1100.9679, 919.1385]], dtype=float32)>]
添加回答
举报