MCPcopy Create free account
hub / github.com/WarmCongee/SDUMC / func_mapping_feature

Function func_mapping_feature

toolkit/utils/read_data.py:120–137  ·  view source on GitHub ↗
(feature, dst_len)

Source from the content-addressed store, hash-verified

118############################################################
119# (seqlen, featdim) -> (dst_len, featdim)
120def func_mapping_feature(feature, dst_len):
121 featlen, featdim = feature.shape
122 if featlen == dst_len:
123 return feature
124 elif featlen < dst_len:
125 pad_feature = np.zeros((dst_len-featlen, featdim))
126 feature = np.concatenate((feature, pad_feature), axis=0)
127 else:
128 if featlen // dst_len == featlen / dst_len:
129 pad_len = 0
130 pool_size = featlen // dst_len
131 else:
132 pad_len = dst_len - featlen % dst_len
133 pool_size = featlen // dst_len + 1
134 pad_feature = np.zeros((pad_len, featdim))
135 feature = np.concatenate([pad_feature, feature]).reshape(dst_len, pool_size, featdim) # 相邻时刻特征取平均
136 feature = np.mean(feature, axis=1)
137 return feature
138
139def func_mapping_feature_tensor(feature, dst_len, pad_place='right'):
140 if len(feature.shape)>=2:

Callers 3

feature_scale_compressFunction · 0.85
align_to_textFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected