(feature, dst_len)
| 118 | ############################################################ |
| 119 | # (seqlen, featdim) -> (dst_len, featdim) |
| 120 | def 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 | |
| 139 | def func_mapping_feature_tensor(feature, dst_len, pad_place='right'): |
| 140 | if len(feature.shape)>=2: |
no outgoing calls
no test coverage detected