Spaces:
Running
Running
Upload 7 files
Browse files- .gitattributes +2 -0
- monotonic_align/__init__.py +19 -0
- monotonic_align/__pycache__/__init__.cpython-39.pyc +0 -0
- monotonic_align/build/temp.linux-x86_64-3.9/core.o +3 -0
- monotonic_align/core.c +0 -0
- monotonic_align/core.pyx +42 -0
- monotonic_align/monotonic_align/core.cpython-39-x86_64-linux-gnu.so +3 -0
- monotonic_align/setup.py +9 -0
.gitattributes
CHANGED
@@ -32,3 +32,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
32 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
32 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
35 |
+
monotonic_align/build/temp.linux-x86_64-3.9/core.o filter=lfs diff=lfs merge=lfs -text
|
36 |
+
monotonic_align/monotonic_align/core.cpython-39-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
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 (800 Bytes). View file
|
|
monotonic_align/build/temp.linux-x86_64-3.9/core.o
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9b817d9e8f2d4dfd1e2753ed4a7a0b765cd3c950ff8dbfd3829f5946f30df33f
|
3 |
+
size 2697832
|
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.cpython-39-x86_64-linux-gnu.so
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:eb859832cfae8e92c6fc7a216fee219f4d6da5fe000f19ec77cee49c46c38784
|
3 |
+
size 1105680
|
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 |
+
)
|