Pipe1213 commited on
Commit
9384a00
·
verified ·
1 Parent(s): 1524fa3

Upload 7 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ monotonic_align/build/temp.linux-x86_64-3.6/core.o 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-36.pyc ADDED
Binary file (786 Bytes). View file
 
monotonic_align/build/temp.linux-x86_64-3.6/core.o ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1cf087f75fefa878bf0c2823e9481756bf83d24988a4ba54f9e2bbb9ddfdf9f8
3
+ size 2165448
monotonic_align/core.c ADDED
The diff for this file is too large to render. See raw diff
 
monotonic_align/core.pyx CHANGED
@@ -1,42 +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])
 
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-36m-x86_64-linux-gnu.so ADDED
Binary file (868 kB). View file
 
monotonic_align/setup.py CHANGED
@@ -1,9 +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
- )
 
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
+ )