Spaces:
Build error
Build error
Upload monotonic_align with huggingface_hub
Browse files- monotonic_align/__init__.py +19 -0
- monotonic_align/__pycache__/__init__.cpython-39.pyc +0 -0
- monotonic_align/build/temp.win-amd64-3.9/Release/core.cp39-win_amd64.exp +0 -0
- monotonic_align/build/temp.win-amd64-3.9/Release/core.cp39-win_amd64.lib +0 -0
- monotonic_align/build/temp.win-amd64-3.9/Release/core.obj +0 -0
- monotonic_align/core.c +0 -0
- monotonic_align/core.pyx +42 -0
- monotonic_align/monotonic_align/core.cp39-win_amd64.pyd +0 -0
- monotonic_align/setup.py +9 -0
monotonic_align/__init__.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import torch
|
3 |
+
from .monotonic_align.core import maximum_path_c
|
4 |
+
|
5 |
+
|
6 |
+
def maximum_path(neg_cent, mask):
|
7 |
+
""" Cython optimized version.
|
8 |
+
neg_cent: [b, t_t, t_s]
|
9 |
+
mask: [b, t_t, t_s]
|
10 |
+
"""
|
11 |
+
device = neg_cent.device
|
12 |
+
dtype = neg_cent.dtype
|
13 |
+
neg_cent = neg_cent.data.cpu().numpy().astype(np.float32)
|
14 |
+
path = np.zeros(neg_cent.shape, dtype=np.int32)
|
15 |
+
|
16 |
+
t_t_max = mask.sum(1)[:, 0].data.cpu().numpy().astype(np.int32)
|
17 |
+
t_s_max = mask.sum(2)[:, 0].data.cpu().numpy().astype(np.int32)
|
18 |
+
maximum_path_c(path, neg_cent, t_t_max, t_s_max)
|
19 |
+
return torch.from_numpy(path).to(device=device, dtype=dtype)
|
monotonic_align/__pycache__/__init__.cpython-39.pyc
ADDED
Binary file (804 Bytes). View file
|
|
monotonic_align/build/temp.win-amd64-3.9/Release/core.cp39-win_amd64.exp
ADDED
Binary file (746 Bytes). View file
|
|
monotonic_align/build/temp.win-amd64-3.9/Release/core.cp39-win_amd64.lib
ADDED
Binary file (1.94 kB). View file
|
|
monotonic_align/build/temp.win-amd64-3.9/Release/core.obj
ADDED
Binary file (720 kB). View file
|
|
monotonic_align/core.c
ADDED
The diff for this file is too large to render.
See raw diff
|
|
monotonic_align/core.pyx
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
cimport cython
|
2 |
+
from cython.parallel import prange
|
3 |
+
|
4 |
+
|
5 |
+
@cython.boundscheck(False)
|
6 |
+
@cython.wraparound(False)
|
7 |
+
cdef void maximum_path_each(int[:,::1] path, float[:,::1] value, int t_y, int t_x, float max_neg_val=-1e9) nogil:
|
8 |
+
cdef int x
|
9 |
+
cdef int y
|
10 |
+
cdef float v_prev
|
11 |
+
cdef float v_cur
|
12 |
+
cdef float tmp
|
13 |
+
cdef int index = t_x - 1
|
14 |
+
|
15 |
+
for y in range(t_y):
|
16 |
+
for x in range(max(0, t_x + y - t_y), min(t_x, y + 1)):
|
17 |
+
if x == y:
|
18 |
+
v_cur = max_neg_val
|
19 |
+
else:
|
20 |
+
v_cur = value[y-1, x]
|
21 |
+
if x == 0:
|
22 |
+
if y == 0:
|
23 |
+
v_prev = 0.
|
24 |
+
else:
|
25 |
+
v_prev = max_neg_val
|
26 |
+
else:
|
27 |
+
v_prev = value[y-1, x-1]
|
28 |
+
value[y, x] += max(v_prev, v_cur)
|
29 |
+
|
30 |
+
for y in range(t_y - 1, -1, -1):
|
31 |
+
path[y, index] = 1
|
32 |
+
if index != 0 and (index == y or value[y-1, index] < value[y-1, index-1]):
|
33 |
+
index = index - 1
|
34 |
+
|
35 |
+
|
36 |
+
@cython.boundscheck(False)
|
37 |
+
@cython.wraparound(False)
|
38 |
+
cpdef void maximum_path_c(int[:,:,::1] paths, float[:,:,::1] values, int[::1] t_ys, int[::1] t_xs) nogil:
|
39 |
+
cdef int b = paths.shape[0]
|
40 |
+
cdef int i
|
41 |
+
for i in prange(b, nogil=True):
|
42 |
+
maximum_path_each(paths[i], values[i], t_ys[i], t_xs[i])
|
monotonic_align/monotonic_align/core.cp39-win_amd64.pyd
ADDED
Binary file (151 kB). View file
|
|
monotonic_align/setup.py
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from distutils.core import setup
|
2 |
+
from Cython.Build import cythonize
|
3 |
+
import numpy
|
4 |
+
|
5 |
+
setup(
|
6 |
+
name = 'monotonic_align',
|
7 |
+
ext_modules = cythonize("core.pyx"),
|
8 |
+
include_dirs=[numpy.get_include()]
|
9 |
+
)
|