MCPcopy Create free account
hub / github.com/PaddlePaddle/Research / pad_feature_data

Function pad_feature_data

NLP/UNIMO/src/reader/batching.py:93–107  ·  view source on GitHub ↗

for image feature sequence padding

(data, pad_value=0.0, dtype="float32", return_mask=False, batch_image_size=None)

Source from the content-addressed store, hash-verified

91
92
93def pad_feature_data(data, pad_value=0.0, dtype="float32", return_mask=False, batch_image_size=None):
94 """for image feature sequence padding"""
95 # num box + 1 ,1 for global feature
96 max_lenth = max([len(item) for item in data])
97 data_width = len(data[0][0])
98 out_data = np.ones((len(data), max_lenth, data_width), dtype=dtype) * pad_value
99 out_mask = np.zeros((len(data), max_lenth, 1), dtype=dtype)
100 for i in range(len(data)):
101 out_data[i, 0:len(data[i]), :] = data[i]
102 if return_mask and batch_image_size[i] > 1:
103 out_mask[i, 0:len(data[i]), :] = 1.0
104 if return_mask:
105 return out_data, out_mask
106 else:
107 return out_data
108
109
110def gen_seq2seq_mask(insts, sent_b_starts=None):

Callers 4

_prepare_batch_dataMethod · 0.90
_pad_batch_recordsMethod · 0.90
_prepare_batch_dataMethod · 0.90
_prepare_batch_dataMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected