Skip to content

Commit d8b727a

Browse files
committed
Merge branch 'main' into remove_test_deps
2 parents cf0247c + ea7855b commit d8b727a

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

examples/tutorials/audio_feature_extractions_tutorial.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ def plot_spectrogram(specgram, title=None, ylabel="freq_bin", ax=None):
7575
if title is not None:
7676
ax.set_title(title)
7777
ax.set_ylabel(ylabel)
78-
ax.imshow(librosa.power_to_db(specgram), origin="lower", aspect="auto", interpolation="nearest")
78+
power_to_db = T.AmplitudeToDB("power", 80.0)
79+
ax.imshow(power_to_db(specgram), origin="lower", aspect="auto", interpolation="nearest")
7980

8081

8182
def plot_fbank(fbank, title=None):

src/libtorchaudio/forced_align/cpu/compute.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,14 @@ void forced_align_impl(
3232
alphas_a[i] = kNegInfinity;
3333
}
3434

35-
torch::Tensor backPtr = torch::empty({T, S}, torch::kInt8).fill_(-1);
35+
auto backPtr_a = new int8_t[T * S];
36+
for (int i = 0; i < T * S; i++) {
37+
backPtr_a[i] = -1;
38+
}
39+
3640
auto logProbs_a = logProbs.accessor<scalar_t, 3>();
3741
auto targets_a = targets.accessor<target_t, 2>();
3842
auto paths_a = paths.accessor<target_t, 2>();
39-
auto backPtr_a = backPtr.accessor<int8_t, 2>();
4043
auto R = 0;
4144
for (auto i = 1; i < L; i++) {
4245
if (targets_a[batchIndex][i] == targets_a[batchIndex][i - 1]) {
@@ -82,8 +85,8 @@ void forced_align_impl(
8285
}
8386
if (start == 0) {
8487
alphas_a[curIdxOffset * S] =
85-
alphas_a[prevIdxOffset * S] + logProbs_a[batchIndex][t][blank];
86-
backPtr_a[t][0] = 0;
88+
alphas_a[prevIdxOffset * S] + logProbs_a[batchIndex][t][blank]; // alphas_a[curIdxOffset][0]
89+
backPtr_a[S * t] = 0; // backPtr_a[t][0] = 0
8790
startloop += 1;
8891
}
8992

@@ -105,13 +108,13 @@ void forced_align_impl(
105108
scalar_t result = 0.0;
106109
if (x2 > x1 && x2 > x0) {
107110
result = x2;
108-
backPtr_a[t][i] = 2;
111+
backPtr_a[t * S + i] = 2; // backPtr_a[t][i] = 2
109112
} else if (x1 > x0 && x1 > x2) {
110113
result = x1;
111-
backPtr_a[t][i] = 1;
114+
backPtr_a[t * S + i] = 1; // backPtr_a[t][i] = 1
112115
} else {
113116
result = x0;
114-
backPtr_a[t][i] = 0;
117+
backPtr_a[t * S + i] = 0; // backPtr_a[t][i] = 0
115118
}
116119
alphas_a[curIdxOffset * S + i] = result + logProbs_a[batchIndex][t][labelIdx]; // alphas_a[curIdxOffset][i]
117120
}
@@ -124,8 +127,9 @@ void forced_align_impl(
124127
for (auto t = T - 1; t > -1; t--) {
125128
auto lbl_idx = ltrIdx % 2 == 0 ? blank : targets_a[batchIndex][ltrIdx / 2];
126129
paths_a[batchIndex][t] = lbl_idx;
127-
ltrIdx -= backPtr_a[t][ltrIdx];
130+
ltrIdx -= backPtr_a[t * S + ltrIdx]; // backPtr_a[t][ltrIdx]
128131
}
132+
delete[] backPtr_a;
129133
}
130134

131135
std::tuple<torch::Tensor, torch::Tensor> compute(

0 commit comments

Comments
 (0)