MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / _expand_label

Function _expand_label

imperative/python/megengine/functional/loss.py:313–326  ·  view source on GitHub ↗
(label: Tensor, label_lengths: Tensor, blank: int)

Source from the content-addressed store, hash-verified

311
312
313def _expand_label(label: Tensor, label_lengths: Tensor, blank: int) -> Tensor:
314 N = label_lengths.shape[0]
315 if len(label.shape) == 1:
316 L = label_lengths.max()
317 unpack_label = zeros((N, L), dtype="int32") + blank
318 idx_0 = _gen_repeat_idx(label_lengths)
319 idx_1 = _gen_tile_idx(label_lengths)
320 unpack_label[idx_0, idx_1] = label
321 label = unpack_label
322
323 L = label.shape[1]
324 ex_label = zeros((N, L * 2 + 1), dtype="int32") + blank
325 ex_label[:, 1::2] = label
326 return ex_label
327
328
329def _safelog(x: Tensor) -> Tensor:

Callers 1

ctc_lossFunction · 0.85

Calls 4

_gen_repeat_idxFunction · 0.85
_gen_tile_idxFunction · 0.85
zerosFunction · 0.70
maxMethod · 0.45

Tested by

no test coverage detected