2 回答

TA貢獻1853條經(jīng)驗 獲得超6個贊
用于torch.repeat_interleave
重復張量的元素。
t.repeat_interleave(repeats=3, dim=1).view(-1)
tensor([ 5., 5., 5., 5., 5., 5., 5., 5., 5., 5.,
5., 5., 10., 10., 10., 10., 10., 10., 10., 10.,
10., 10., 10., 10., 100., 100., 100., 100., 100., 100.,
100., 100., 100., 100., 100., 100., 1000., 1000., 1000., 1000.,
1000., 1000., 1000., 1000., 1000., 1000., 1000., 1000.])

TA貢獻1826條經(jīng)驗 獲得超6個贊
嘗試這個:
final_features = feature_combined.view(1, -1, feature_combined.size(-1))
.repeat(1, 1, 3).view(1, -1).squeeze(0)
我假設(shè)您輸入的形狀為 的張量(2, 2, 2, 2)在feature_combined. final_features結(jié)果的形狀([48])如您所愿。
print(feature_combined)
>>tensor([ 5., 5., 5., 5., 5., 5., 5., 5., 5., 5.,
5., 5., 10., 10., 10., 10., 10., 10., 10., 10.,
10., 10., 10., 10., 100., 100., 100., 100., 100., 100.,
100., 100., 100., 100., 100., 100., 1000., 1000., 1000., 1000.,
1000., 1000., 1000., 1000., 1000., 1000., 1000., 1000.])
添加回答
舉報